Added reset_hash

This commit is contained in:
Alienscience 2022-03-16 18:12:51 +01:00
parent aa6004c664
commit efe695a061

View file

@ -84,6 +84,12 @@ impl<T: HashValue> CyclicPoly<T> {
self.current
}
/// Reset the current hash value.
/// This does not reset the block size. To reset the block size create a new object.
pub fn reset_hash(&mut self) {
self.current = T::zero()
}
/// Calculate a single hash value from the given block.
/// This function does not support rolling hashes but saves the initial
/// setup that is done when calling new().
@ -161,10 +167,20 @@ impl<T: HashValue> CyclicPoly<T> {
#[cfg(test)]
mod tests {
use crate::{cyclic_poly::CyclicPoly, hash_value::HashValue};
use crate::{cyclic_poly::CyclicPoly, hash_value::HashValue, CyclicPoly32};
use quickcheck::TestResult;
use quickcheck_macros::quickcheck;
#[test]
fn reset_hash() {
let data = vec![0, 1, 2, 3, 4, 5, 6, 7];
let mut h = CyclicPoly32::from_block(&data);
let expected = h.value();
h.reset_hash();
let actual = h.update(&data);
assert_eq!(expected, actual);
}
#[quickcheck]
fn sensitivity64(data0: Vec<u8>, i: usize) -> TestResult {
sensitivity_check::<u64>(data0, i)