diff options
| author | Eduardo Leegwater Simões <[email protected]> | 2023-04-12 11:26:53 +0200 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2023-05-01 03:23:16 -0500 |
| commit | 8176a2202dfd3556949cbdab2b669a011231c63b (patch) | |
| tree | b4010c6addc81a361e505c2078b145885775e096 /src/test.rs | |
| parent | ce48d79f38a8862b749ec6cc12ba5d1da69ab131 (diff) | |
add `from_bytes` for conversions from `[u8; 32]`
The function is `const`, so it is fundamentally different from the
`From` trait implementation by allowing compile-time instantiation of a
`Hash`.
Diffstat (limited to 'src/test.rs')
| -rw-r--r-- | src/test.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test.rs b/src/test.rs index 4b6272c..f5b3462 100644 --- a/src/test.rs +++ b/src/test.rs @@ -603,3 +603,28 @@ fn test_issue_206_windows_sse2() { assert_eq!(crate::Hasher::new().update(input).finalize(), expected_hash); } } + +#[test] +fn test_hash_conversions() { + let bytes1 = [42; 32]; + let hash1: crate::Hash = bytes1.into(); + let bytes2: [u8; 32] = hash1.into(); + assert_eq!(bytes1, bytes2); + + let bytes3 = *hash1.as_bytes(); + assert_eq!(bytes1, bytes3); + + let hash2 = crate::Hash::from_bytes(bytes1); + assert_eq!(hash1, hash2); + + let hex = hash1.to_hex(); + let hash3 = crate::Hash::from_hex(hex.as_bytes()).unwrap(); + assert_eq!(hash1, hash3); +} + +#[test] +const fn test_hash_const_conversions() { + let bytes = [42; 32]; + let hash = crate::Hash::from_bytes(bytes); + _ = hash.as_bytes(); +} |
