1 use crate::table::crc64_table_slice_16; 2 use crate::*; 3 4 use super::{finalize, init, update_slice16}; 5 6 impl Crc<u64, Table<16>> { new(algorithm: &'static Algorithm<u64>) -> Self7 pub const fn new(algorithm: &'static Algorithm<u64>) -> Self { 8 let data = crc64_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); 9 Self { algorithm, data } 10 } 11 checksum(&self, bytes: &[u8]) -> u6412 pub const fn checksum(&self, bytes: &[u8]) -> u64 { 13 let mut crc = init(self.algorithm, self.algorithm.init); 14 crc = self.update(crc, bytes); 15 finalize(self.algorithm, crc) 16 } 17 update(&self, crc: u64, bytes: &[u8]) -> u6418 const fn update(&self, crc: u64, bytes: &[u8]) -> u64 { 19 update_slice16(crc, self.algorithm.refin, &self.data, bytes) 20 } 21 digest(&self) -> Digest<u64, Table<16>>22 pub const fn digest(&self) -> Digest<u64, Table<16>> { 23 self.digest_with_initial(self.algorithm.init) 24 } 25 26 /// Construct a `Digest` with a given initial value. 27 /// 28 /// This overrides the initial value specified by the algorithm. 29 /// The effects of the algorithm's properties `refin` and `width` 30 /// are applied to the custom initial value. digest_with_initial(&self, initial: u64) -> Digest<u64, Table<16>>31 pub const fn digest_with_initial(&self, initial: u64) -> Digest<u64, Table<16>> { 32 let value = init(self.algorithm, initial); 33 Digest::new(self, value) 34 } 35 table(&self) -> &<Table<16> as Implementation>::Data<u64>36 pub const fn table(&self) -> &<Table<16> as Implementation>::Data<u64> { 37 &self.data 38 } 39 } 40 41 impl<'a> Digest<'a, u64, Table<16>> { new(crc: &'a Crc<u64, Table<16>>, value: u64) -> Self42 const fn new(crc: &'a Crc<u64, Table<16>>, value: u64) -> Self { 43 Digest { crc, value } 44 } 45 update(&mut self, bytes: &[u8])46 pub fn update(&mut self, bytes: &[u8]) { 47 self.value = self.crc.update(self.value, bytes); 48 } 49 finalize(self) -> u6450 pub const fn finalize(self) -> u64 { 51 finalize(self.crc.algorithm, self.value) 52 } 53 } 54