From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- vendor/twox-hash/src/digest_support.rs | 179 +++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 vendor/twox-hash/src/digest_support.rs (limited to 'vendor/twox-hash/src/digest_support.rs') diff --git a/vendor/twox-hash/src/digest_support.rs b/vendor/twox-hash/src/digest_support.rs new file mode 100644 index 000000000..7b00b9d80 --- /dev/null +++ b/vendor/twox-hash/src/digest_support.rs @@ -0,0 +1,179 @@ +use core::hash::Hasher; + +use digest::{ + generic_array::{ + typenum::consts::{U16, U4, U8}, + GenericArray, + }, + Digest, +}; + +use crate::{xxh3, XxHash32, XxHash64}; + +impl Digest for XxHash32 { + type OutputSize = U4; + + fn new() -> Self { + Self::default() + } + + fn input>(&mut self, data: B) { + self.write(data.as_ref()); + } + + fn chain>(mut self, data: B) -> Self + where + Self: Sized, + { + self.input(data); + self + } + + fn result(self) -> GenericArray { + self.finish().to_be_bytes().into() + } + + fn result_reset(&mut self) -> GenericArray { + let result = self.result(); + self.reset(); + result + } + + fn reset(&mut self) { + *self = Self::default(); + } + + fn output_size() -> usize { + 4 + } + + fn digest(data: &[u8]) -> GenericArray { + Self::new().chain(data).result() + } +} + +impl Digest for XxHash64 { + type OutputSize = U8; + + fn new() -> Self { + Self::default() + } + + fn input>(&mut self, data: B) { + self.write(data.as_ref()); + } + + fn chain>(mut self, data: B) -> Self + where + Self: Sized, + { + self.input(data); + self + } + + fn result(self) -> GenericArray { + self.finish().to_be_bytes().into() + } + + fn result_reset(&mut self) -> GenericArray { + let result = self.result(); + self.reset(); + result + } + + fn reset(&mut self) { + *self = Self::default(); + } + + fn output_size() -> usize { + 8 + } + + fn digest(data: &[u8]) -> GenericArray { + Self::new().chain(data).result() + } +} + +impl Digest for xxh3::Hash64 { + type OutputSize = U8; + + fn new() -> Self { + Self::default() + } + + fn input>(&mut self, data: B) { + self.write(data.as_ref()); + } + + fn chain>(mut self, data: B) -> Self + where + Self: Sized, + { + self.input(data); + self + } + + fn result(self) -> GenericArray { + self.finish().to_be_bytes().into() + } + + fn result_reset(&mut self) -> GenericArray { + let result = self.clone().result(); + self.reset(); + result + } + + fn reset(&mut self) { + *self = Self::default(); + } + + fn output_size() -> usize { + 8 + } + + fn digest(data: &[u8]) -> GenericArray { + Self::new().chain(data).result() + } +} + +impl Digest for xxh3::Hash128 { + type OutputSize = U16; + + fn new() -> Self { + Self::default() + } + + fn input>(&mut self, data: B) { + self.write(data.as_ref()); + } + + fn chain>(mut self, data: B) -> Self + where + Self: Sized, + { + self.input(data); + self + } + + fn result(self) -> GenericArray { + xxh3::HasherExt::finish_ext(&self).to_be_bytes().into() + } + + fn result_reset(&mut self) -> GenericArray { + let result = self.clone().result(); + self.reset(); + result + } + + fn reset(&mut self) { + *self = Self::default(); + } + + fn output_size() -> usize { + 8 + } + + fn digest(data: &[u8]) -> GenericArray { + Self::new().chain(data).result() + } +} -- cgit v1.2.3