Skip to content

Commit

Permalink
Add serde support for Hash behind optional feature
Browse files Browse the repository at this point in the history
Added a new cargo feature `serde` that when enabled will derive
`serde::Serialize` and `serde::Deserialize` for the `blake3::Hash`
struct.
  • Loading branch information
rminderhoud committed Sep 20, 2023
1 parent 4e25f2e commit 5e3eb94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ features = ["mmap", "rayon", "zeroize"]
arrayref = "0.3.5"
arrayvec = { version = "0.7.4", default-features = false }
constant_time_eq = "0.3.0"
rayon = { version = "1.2.1", optional = true }
cfg-if = "1.0.0"
digest = { version = "0.10.1", features = [ "mac" ], optional = true }
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"], optional = true }
memmap2 = { version = "0.7.1", optional = true }
rayon = { version = "1.2.1", optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"], optional = true }

[dev-dependencies]
hmac = "0.12.0"
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
//! expect breaking changes between patch versions. (The "-preview" feature name
//! follows the conventions of the RustCrypto [`signature`] crate.)
//!
//! The `serde` feature (disabled by default) enables serde compatibility for
//! the `Hash` struct.
//!
//! [`Hasher::update_rayon`]: struct.Hasher.html#method.update_rayon
//! [BLAKE3]: https://blake3.io
//! [Rayon]: https://github.com/rayon-rs/rayon
Expand Down Expand Up @@ -212,6 +215,7 @@ fn counter_high(counter: u64) -> u32 {
/// [`Display`]: https://doc.rust-lang.org/std/fmt/trait.Display.html
/// [`FromStr`]: https://doc.rust-lang.org/std/str/trait.FromStr.html
#[cfg_attr(feature = "zeroize", derive(zeroize::Zeroize))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[derive(Clone, Copy, Hash)]
pub struct Hash([u8; OUT_LEN]);

Expand Down

0 comments on commit 5e3eb94

Please sign in to comment.