use crate::digest::Digest;
use crate::hashing::sha1;
#[derive(Clone)]
pub struct Sha1 {
ctx: sha1::Context,
computed: bool,
}
impl Sha1 {
pub const fn new() -> Sha1 {
Sha1 {
ctx: sha1::Sha1::new(),
computed: false,
}
}
}
impl Digest for Sha1 {
fn reset(&mut self) {
self.ctx.reset();
self.computed = false;
}
fn input(&mut self, msg: &[u8]) {
assert!(!self.computed, "context is already finalized, needs reset");
self.ctx.update_mut(msg);
}
fn result(&mut self, slice: &mut [u8]) {
assert!(!self.computed, "context is already finalized, needs reset");
self.computed = true;
slice.copy_from_slice(&self.ctx.finalize_reset());
}
fn output_bits(&self) -> usize {
sha1::Sha1::OUTPUT_BITS
}
fn block_size(&self) -> usize {
sha1::Sha1::BLOCK_BYTES
}
}