You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/01/07 09:27:49 UTC

[avro] 01/01: AVRO-3284 Update Rabin fingerprint implementation to digest to 0.10+

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch avro-3284-update-to-digest-0.10+
in repository https://gitbox.apache.org/repos/asf/avro.git

commit d29ebeb67ee87534e2c5eee8d66053b295cab24f
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Fri Jan 7 11:26:12 2022 +0200

    AVRO-3284 Update Rabin fingerprint implementation to digest to 0.10+
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
 lang/rust/Cargo.toml   |  6 +++---
 lang/rust/src/rabin.rs | 33 ++++++++++++++++++++-------------
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/lang/rust/Cargo.toml b/lang/rust/Cargo.toml
index 7709156..2158f41 100644
--- a/lang/rust/Cargo.toml
+++ b/lang/rust/Cargo.toml
@@ -54,7 +54,7 @@ harness = false
 byteorder = "1.4.3"
 bzip2 = { version = "0.4.3", optional = true }
 crc32fast = { version = "1.2.1", optional = true }
-digest = "0.9"
+digest = "0.10.1"
 libflate = "1.1.1"
 num-bigint = "0.4.2"
 rand = "0.8.4"
@@ -73,8 +73,8 @@ log = "0.4.14"
 zstd = { version = "0.9.0+zstd.1.5.0" , optional = true }
 
 [dev-dependencies]
-md-5 = "0.9.1"
-sha2 = "0.9.8"
+md-5 = "0.10.0"
+sha2 = "0.10.0"
 criterion = "0.3.5"
 anyhow = "1.0.44"
 hex-literal = "0.3.3"
diff --git a/lang/rust/src/rabin.rs b/lang/rust/src/rabin.rs
index aebaacc..d7cb773 100644
--- a/lang/rust/src/rabin.rs
+++ b/lang/rust/src/rabin.rs
@@ -17,7 +17,10 @@
 
 //! Implementation of the Rabin fingerprint algorithm
 use byteorder::{ByteOrder, LittleEndian};
-use digest::{consts::U8, generic_array::GenericArray, FixedOutput, Reset, Update};
+use digest::{
+    consts::U8, core_api::OutputSizeUser, generic_array::GenericArray, FixedOutput,
+    FixedOutputReset, HashMarker, Output, Reset, Update,
+};
 use lazy_static::lazy_static;
 
 const EMPTY: i64 = -4513414715797952619;
@@ -90,8 +93,8 @@ impl Default for Rabin {
 }
 
 impl Update for Rabin {
-    fn update(&mut self, input: impl AsRef<[u8]>) {
-        for b in input.as_ref() {
+    fn update(&mut self, data: &[u8]) {
+        for b in data {
             self.result = (self.result as u64 >> 8) as i64
                 ^ FPTABLE[((self.result ^ *b as i64) & 0xff) as usize];
         }
@@ -99,18 +102,9 @@ impl Update for Rabin {
 }
 
 impl FixedOutput for Rabin {
-    // 8-byte little-endian form of the i64
-    // See: https://avro.apache.org/docs/current/spec.html#single_object_encoding
-    type OutputSize = U8;
-
     fn finalize_into(self, out: &mut GenericArray<u8, Self::OutputSize>) {
         LittleEndian::write_i64(out, self.result);
     }
-
-    fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>) {
-        LittleEndian::write_i64(out, self.result);
-        self.result = EMPTY;
-    }
 }
 
 impl Reset for Rabin {
@@ -119,7 +113,20 @@ impl Reset for Rabin {
     }
 }
 
-digest::impl_write!(Rabin);
+impl OutputSizeUser for Rabin {
+    // 8-byte little-endian form of the i64
+    // See: https://avro.apache.org/docs/current/spec.html#single_object_encoding
+    type OutputSize = U8;
+}
+
+impl HashMarker for Rabin {}
+
+impl FixedOutputReset for Rabin {
+    fn finalize_into_reset(&mut self, out: &mut Output<Self>) {
+        LittleEndian::write_i64(out, self.result);
+        self.reset();
+    }
+}
 
 #[cfg(test)]
 mod tests {