summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yml8
-rw-r--r--Cargo.toml5
-rw-r--r--src/lib.rs8
-rw-r--r--src/test.rs14
4 files changed, 26 insertions, 9 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 16a5468..2de4fdd 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -52,17 +52,17 @@ jobs:
- name: print instruction set support
run: cargo run --quiet
working-directory: ./tools/instruction_set_support
- # Default tests plus Rayon and RustCrypto trait implementations.
- - run: cargo test --features=rayon,traits-preview,zeroize
+ # Default tests plus Rayon and trait implementations.
+ - run: cargo test --features=rayon,traits-preview,serde,zeroize
# Same but with only one thread in the Rayon pool. This can find deadlocks.
- name: "again with RAYON_NUM_THREADS=1"
- run: cargo test --features=rayon,traits-preview,zeroize
+ run: cargo test --features=rayon,traits-preview,serde,zeroize
env:
RAYON_NUM_THREADS: 1
# The mmap feature by itself (update_mmap_rayon is omitted).
- run: cargo test --features=mmap
# All public features put together.
- - run: cargo test --features=mmap,rayon,traits-preview,zeroize
+ - run: cargo test --features=mmap,rayon,traits-preview,serde,zeroize
# no_std tests.
- run: cargo test --no-default-features
diff --git a/Cargo.toml b/Cargo.toml
index c3596eb..2cc42b7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -88,8 +88,8 @@ no_avx512 = []
no_neon = []
[package.metadata.docs.rs]
-# Document the rayon/mmap methods and the Zeroize impls on docs.rs.
-features = ["mmap", "rayon", "zeroize"]
+# Document the rayon/mmap methods and the Serialize/Deserialize/Zeroize impls on docs.rs.
+features = ["mmap", "rayon", "serde", "zeroize"]
[dependencies]
arrayref = "0.3.5"
@@ -110,6 +110,7 @@ rand = "0.8.0"
rand_chacha = "0.3.0"
reference_impl = { path = "./reference_impl" }
tempfile = "3.8.0"
+serde_json = "1.0.107"
[build-dependencies]
cc = "1.0.4"
diff --git a/src/lib.rs b/src/lib.rs
index ebfde7a..1fe47bf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -56,6 +56,11 @@
//! [`Zeroize`](https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html) for
//! this crate's types.
//!
+//! The `serde` feature (disabled by default, but enabled for [docs.rs]) implements
+//! [`serde::Serialize`](https://docs.rs/serde/latest/serde/trait.Serialize.html) and
+//! [`serde::Deserialize`](https://docs.rs/serde/latest/serde/trait.Deserialize.html)
+//! for [`Hash`](struct@Hash).
+//!
//! The NEON implementation is enabled by default for AArch64 but requires the
//! `neon` feature for other ARM targets. Not all ARMv7 CPUs support NEON, and
//! enabling this feature will produce a binary that's not portable to CPUs
@@ -69,9 +74,6 @@
//! 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
diff --git a/src/test.rs b/src/test.rs
index c98192f..fb1e849 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -806,3 +806,17 @@ fn test_mmap_rayon() -> Result<(), std::io::Error> {
);
Ok(())
}
+
+#[test]
+#[cfg(feature = "std")]
+#[cfg(feature = "serde")]
+fn test_serde() {
+ let hash: crate::Hash = [7; 32].into();
+ let json = serde_json::to_string(&hash).unwrap();
+ assert_eq!(
+ json,
+ "[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]",
+ );
+ let hash2: crate::Hash = serde_json::from_str(&json).unwrap();
+ assert_eq!(hash, hash2);
+}