From 1c47ec2d281b904762ece947ede19f3d19572819 Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Wed, 7 Feb 2024 09:14:57 +1100 Subject: [PATCH] Replace `crc32c` dependency with `crc-any` Fixes #3 --- CHANGELOG.md | 3 +++ Cargo.toml | 4 ++-- src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs | 10 ++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a670a6e8..c7f702c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + - Replace `crc32c` dependency with `crc-any` + ## [0.11.6] - 2024-02-06 ### Added diff --git a/Cargo.toml b/Cargo.toml index 539fee1c..6de7fa42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ default = ["transpose", "blosc", "gzip", "sharding", "crc32c", "zstd", "ndarray" bitround = [] # Enable the experimental bitround codec blosc = ["dep:blosc-sys"] # Enable the blosc codec bz2 = ["dep:bzip2"] # Enable the experimental bz2 codec -crc32c = ["dep:crc32c"] # Enable the crc32c checksum codec +crc32c = ["dep:crc-any"] # Enable the crc32c checksum codec gzip = ["dep:flate2"] # Enable the gzip codec pcodec = ["dep:pco"] # Enable the experimental pcodec codec sharding = [] # Enable the sharding codec @@ -46,7 +46,7 @@ blosc-sys = { version = "0.3.0", package = "blosc-src", features = ["lz4", "zlib bytemuck = { version = "1.14.0", features = ["extern_crate_alloc"] } bytes = "1.5.0" bzip2 = { version = "0.4.4", optional = true, features = ["static"] } -crc32c = { version = "0.6.4", optional = true } +crc-any = { version = "2.4.4", optional = true } derive_more = "0.99" dyn-clone = "1" flate2 = { version = "1", optional = true } diff --git a/src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs b/src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs index fc5f1643..d295f830 100644 --- a/src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs +++ b/src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs @@ -47,6 +47,12 @@ impl CodecTraits for Crc32cCodec { } } +fn get_checksum_le_bytes(decoded_value: &[u8]) -> [u8; 4] { + let mut crc32c = crc_any::CRCu32::crc32c(); + crc32c.digest(&decoded_value); + crc32c.get_crc().to_le_bytes() +} + #[cfg_attr(feature = "async", async_trait::async_trait)] impl BytesToBytesCodecTraits for Crc32cCodec { fn encode_opt( @@ -54,7 +60,7 @@ impl BytesToBytesCodecTraits for Crc32cCodec { mut decoded_value: Vec, _parallel: bool, ) -> Result, CodecError> { - let checksum = crc32c::crc32c(&decoded_value).to_le_bytes(); + let checksum = get_checksum_le_bytes(&decoded_value); decoded_value.reserve_exact(checksum.len()); decoded_value.extend(&checksum); Ok(decoded_value) @@ -69,7 +75,7 @@ impl BytesToBytesCodecTraits for Crc32cCodec { if encoded_value.len() >= CHECKSUM_SIZE { if crate::config::global_config().validate_checksums() { let decoded_value = &encoded_value[..encoded_value.len() - CHECKSUM_SIZE]; - let checksum = crc32c::crc32c(decoded_value).to_le_bytes(); + let checksum = get_checksum_le_bytes(decoded_value); if checksum != encoded_value[encoded_value.len() - CHECKSUM_SIZE..] { return Err(CodecError::InvalidChecksum); }