use super::{finalize, init, update_nolookup};
use crate::*;
impl Crc<u64, NoTable> {
pub const fn new(algorithm: &'static Algorithm<u64>) -> Self {
Self {
algorithm,
data: [],
}
}
pub const fn checksum(&self, bytes: &[u8]) -> u64 {
let mut crc = init(self.algorithm, self.algorithm.init);
crc = self.update(crc, bytes);
finalize(self.algorithm, crc)
}
const fn update(&self, crc: u64, bytes: &[u8]) -> u64 {
update_nolookup(crc, self.algorithm, bytes)
}
pub const fn digest(&self) -> Digest<u64, NoTable> {
self.digest_with_initial(self.algorithm.init)
}
pub const fn digest_with_initial(&self, initial: u64) -> Digest<u64, NoTable> {
let value = init(self.algorithm, initial);
Digest::new(self, value)
}
}
impl<'a> Digest<'a, u64, NoTable> {
const fn new(crc: &'a Crc<u64, NoTable>, value: u64) -> Self {
Digest { crc, value }
}
pub fn update(&mut self, bytes: &[u8]) {
self.value = self.crc.update(self.value, bytes);
}
pub const fn finalize(self) -> u64 {
finalize(self.crc.algorithm, self.value)
}
}