diff options
| author | Elichai Turkel <[email protected]> | 2023-07-09 19:34:37 +0300 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2023-07-16 13:29:47 -0400 |
| commit | f18e19092b2de416f67734f59e72eaf9b36ba15b (patch) | |
| tree | f8fccdff9a23be15b1eb5a3728ebbd9d08d5dc5a /src/test.rs | |
| parent | 8e92fc6929a984508fc542b99bac302439cba0fb (diff) | |
Add tests for Zeroize
Diffstat (limited to 'src/test.rs')
| -rw-r--r-- | src/test.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test.rs b/src/test.rs index 60bbe8c..0d94f44 100644 --- a/src/test.rs +++ b/src/test.rs @@ -628,3 +628,61 @@ const fn test_hash_const_conversions() { let hash = crate::Hash::from_bytes(bytes); _ = hash.as_bytes(); } + +#[cfg(feature = "zeroize")] +#[test] +fn test_zeroize() { + use zeroize::Zeroize; + + let mut hash = crate::Hash([42; 32]); + hash.zeroize(); + assert_eq!(hash.0, [0u8; 32]); + + let mut hasher = crate::Hasher { + chunk_state: crate::ChunkState { + cv: [42; 8], + chunk_counter: 42, + buf: [42; 64], + buf_len: 42, + blocks_compressed: 42, + flags: 42, + platform: crate::Platform::Portable, + }, + key: [42; 8], + cv_stack: [[42; 32]; { crate::MAX_DEPTH + 1 }].into(), + }; + hasher.zeroize(); + assert_eq!(hasher.chunk_state.cv, [0; 8]); + assert_eq!(hasher.chunk_state.chunk_counter, 0); + assert_eq!(hasher.chunk_state.buf, [0; 64]); + assert_eq!(hasher.chunk_state.buf_len, 0); + assert_eq!(hasher.chunk_state.blocks_compressed, 0); + assert_eq!(hasher.chunk_state.flags, 0); + assert!(matches!(hasher.chunk_state.platform, crate::Platform::Portable)); + assert_eq!(hasher.key, [0; 8]); + assert_eq!(&*hasher.cv_stack, &[[0u8; 32]; 0]); + + + let mut output_reader = crate::OutputReader { + inner: crate::Output { + input_chaining_value: [42; 8], + block: [42; 64], + counter: 42, + block_len: 42, + flags: 42, + platform: crate::Platform::Portable, + }, + position_within_block: 42, + }; + + + output_reader.zeroize(); + assert_eq!(output_reader.inner.input_chaining_value, [0; 8]); + assert_eq!(output_reader.inner.block, [0; 64]); + assert_eq!(output_reader.inner.counter, 0); + assert_eq!(output_reader.inner.block_len, 0); + assert_eq!(output_reader.inner.flags, 0); + assert!(matches!(output_reader.inner.platform, crate::Platform::Portable)); + assert_eq!(output_reader.position_within_block, 0); + +}
\ No newline at end of file |
