1mod constants;
2mod digest;
3mod encode;
4mod error;
5mod hash;
6mod inner;
7
8pub mod encoding;
9
10#[cfg(test)]
11#[allow(clippy::expect_used)]
12mod golden;
13
14pub use constants::{
15 DIGEST_SIZE, HASH_SIZE_BASE64, HASH_SIZE_BIN, HASH_SIZE_COMPACT, HASH_SIZE_CROCKFORD,
16 MIN_RECOVERABLE_BASE64, MIN_RECOVERABLE_BIN, MIN_RECOVERABLE_CROCKFORD, PARITY, PARITY_OFFSET,
17 PARITY_SIZE, SIZE_SIZE,
18};
19pub use digest::{blake3, sha256};
20pub use encode::hash_encoded;
21pub use error::{HashError, HashValidationError};
22pub use hash::{hash, Hash, RS};
23pub use inner::{hash_inner, inner_from_parts};
24pub use ps_pint16::PackedInt;
25
26#[allow(clippy::expect_used)]
27#[cfg(test)]
28mod tests {
29 use super::{
30 blake3, encoding, hash, hash_encoded, hash_inner, sha256, Hash, HashValidationError,
31 DIGEST_SIZE, HASH_SIZE_BASE64, HASH_SIZE_BIN, HASH_SIZE_COMPACT, HASH_SIZE_CROCKFORD,
32 PARITY_SIZE,
33 };
34
35 #[test]
36 fn public_api_exports_work() {
37 let data = b"core api";
38
39 assert_eq!(sha256(data).len(), DIGEST_SIZE);
40 assert_eq!(blake3(data).as_bytes().len(), DIGEST_SIZE);
41 assert_eq!(
42 hash_inner(data).expect("hash_inner should work").len(),
43 HASH_SIZE_BIN
44 );
45 assert_eq!(
46 hash_encoded(data).expect("hash_encoded should work").len(),
47 HASH_SIZE_CROCKFORD
48 );
49 }
50
51 #[test]
52 fn hash_method_exports_work() {
53 let hash = hash(b"core hash").expect("hash should work");
54
55 assert_eq!(hash.to_string().len(), HASH_SIZE_CROCKFORD);
56 assert_eq!(hash.to_crockford().len(), HASH_SIZE_CROCKFORD);
57 assert_eq!(hash.to_base64().len(), HASH_SIZE_BASE64);
58 assert_eq!(hash.compact().len(), HASH_SIZE_COMPACT);
59 assert_eq!(hash.digest().len(), DIGEST_SIZE);
60 assert_eq!(hash.parity().len(), PARITY_SIZE);
61 }
62
63 #[test]
64 fn encoding_module_is_public() {
65 let inner = hash_inner(b"public encoding").expect("hash_inner should work");
66
67 let crockford = encoding::crockford::encode(&inner);
68 let base64 = encoding::base64::encode(&inner);
69
70 assert_eq!(encoding::crockford::decode(&crockford), inner);
71 assert_eq!(encoding::base64::decode(&base64), inner);
72 }
73
74 #[test]
75 fn validate_reports_invalid_length() {
76 assert_eq!(
77 Hash::validate("short"),
78 Err(HashValidationError::InvalidLength(5))
79 );
80 }
81}