usecrate::{Digest, FixedOutput, FixedOutputReset, HashMarker, Update}; use core::fmt::Debug;
/// Fixed-output resettable digest test via the `Digest` trait pubfn fixed_reset_test<D>(input: &[u8], output: &[u8]) -> Option<&'static str> where
D: FixedOutputReset + Debug + Clone + Default + Update + HashMarker,
{ letmut hasher = D::new(); // Test that it works when accepting the message all at once
hasher.update(input); letmut hasher2 = hasher.clone(); if hasher.finalize()[..] != output[..] { return Some("whole message");
}
// Test if reset works correctly
hasher2.reset();
hasher2.update(input); if hasher2.finalize_reset()[..] != output[..] { return Some("whole message after reset");
}
// Test that it works when accepting the message in chunks for n in1..core::cmp::min(17, input.len()) { letmut hasher = D::new(); for chunk in input.chunks(n) {
hasher.update(chunk);
hasher2.update(chunk);
} if hasher.finalize()[..] != output[..] { return Some("message in chunks");
} if hasher2.finalize_reset()[..] != output[..] { return Some("message in chunks");
}
}
None
}
/// Variable-output resettable digest test pubfn fixed_test<D>(input: &[u8], output: &[u8]) -> Option<&'static str> where
D: FixedOutput + Default + Debug + Clone,
{ letmut hasher = D::default(); // Test that it works when accepting the message all at once
hasher.update(input); if hasher.finalize_fixed()[..] != output[..] { return Some("whole message");
}
// Test that it works when accepting the message in chunks for n in1..core::cmp::min(17, input.len()) { letmut hasher = D::default(); for chunk in input.chunks(n) {
hasher.update(chunk);
} if hasher.finalize_fixed()[..] != output[..] { return Some("message in chunks");
}
}
None
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.