7 releases

0.2.2 Sep 26, 2024
0.2.1 Aug 26, 2024
0.2.0 Jun 19, 2024
0.1.0 Nov 24, 2023

#408 in Cryptography

Download history 172/week @ 2024-07-29 98/week @ 2024-08-05 62/week @ 2024-08-12 89/week @ 2024-08-19 414/week @ 2024-08-26 85/week @ 2024-09-02 56/week @ 2024-09-09 155/week @ 2024-09-16 391/week @ 2024-09-23 800/week @ 2024-09-30 2101/week @ 2024-10-07 1700/week @ 2024-10-14 472/week @ 2024-10-21 312/week @ 2024-10-28 360/week @ 2024-11-04 320/week @ 2024-11-11

1,475 downloads per month
Used in 8 crates (7 directly)

MIT/Apache

63KB
961 lines

License Docs Crates io Discord

Unambiguously digest structured data

udigest provides utilities for unambiguous hashing the structured data. Structured data can be anything that implements Digestable trait:

  • str, String, CStr, CString
  • Integers: i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, char, isize, usize
  • Containers: Box, Arc, Rc, Cow, Option, Result
  • Collections: arrays, slices, Vec, LinkedList, VecDeque, BTreeSet, BTreeMap

The trait is intentionally not implemented for certain types:

  • HashMap, HashSet as they can not be traversed in deterministic order

The Digestable trait can be implemented for the struct using a macro:

#[derive(udigest::Digestable)]
struct Person {
    name: String,
    job_title: String,
}
let alice = Person {
    name: "Alice".into(),
    job_title: "cryptographer".into(),
};

let hash = udigest::hash::<sha2::Sha256>(&alice);

The crate intentionally does not try to follow any existing standards for unambiguous encoding. The format for encoding was designed specifically for udigest to provide a better usage experience in Rust. The details of encoding format can be found in encoding module.

Features

  • digest enables support of hash functions that implement digest traits
    If feature is not enabled, the crate is still usable via Digestable trait that generically implements unambiguous encoding
  • inline-struct is required to use inline_struct! macro
  • std implements Digestable trait for types in standard library
  • alloc implements Digestable trait for type in alloc crate
  • derive enables Digestable proc macro

Join us in Discord!

Feel free to reach out to us in Discord!

Dependencies

~270–435KB
~11K SLoC