Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/digest/src/dev/fixed.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / digest / src / dev / fixed.rs` 65 lines ยท 2021 bytes Raw Blame History 1 use crate::{Digest, FixedOutput, FixedOutputReset, HashMarker, Update}; 2 use core::fmt::Debug; 3 4 /// Fixed-output resettable digest test via the `Digest` trait 5 pub fn fixed_reset_test(input: &[u8], output: &[u8]) -> Option<&'static str> 6 where 7 D: FixedOutputReset + Debug + Clone + Default + Update + HashMarker, 8 { 9 let mut hasher = D::new(); 10 // Test that it works when accepting the message all at once 11 hasher.update(input); 12 let mut hasher2 = hasher.clone(); 13 if hasher.finalize()[..] != output[..] { 14 return Some("whole message"); 15 } 16 17 // Test if reset works correctly 18 hasher2.reset(); 19 hasher2.update(input); 20 if hasher2.finalize_reset()[..] != output[..] { 21 return Some("whole message after reset"); 22 } 23 24 // Test that it works when accepting the message in chunks 25 for n in 1..core::cmp::min(17, input.len()) { 26 let mut hasher = D::new(); 27 for chunk in input.chunks(n) { 28 hasher.update(chunk); 29 hasher2.update(chunk); 30 } 31 if hasher.finalize()[..] != output[..] { 32 return Some("message in chunks"); 33 } 34 if hasher2.finalize_reset()[..] != output[..] { 35 return Some("message in chunks"); 36 } 37 } 38 39 None 40 } 41 42 /// Variable-output resettable digest test 43 pub fn fixed_test(input: &[u8], output: &[u8]) -> Option<&'static str> 44 where 45 D: FixedOutput + Default + Debug + Clone, 46 { 47 let mut hasher = D::default(); 48 // Test that it works when accepting the message all at once 49 hasher.update(input); 50 if hasher.finalize_fixed()[..] != output[..] { 51 return Some("whole message"); 52 } 53 54 // Test that it works when accepting the message in chunks 55 for n in 1..core::cmp::min(17, input.len()) { 56 let mut hasher = D::default(); 57 for chunk in input.chunks(n) { 58 hasher.update(chunk); 59 } 60 if hasher.finalize_fixed()[..] != output[..] { 61 return Some("message in chunks"); 62 } 63 } 64 None 65 }