mirror of
https://github.com/rustfs/rustfs.git
synced 2026-10-04 20:43:04 +00:00
b6312ef37f
`crates/utils/src/hash.rs` is the one place RustFS is meant to touch a concrete MD5 implementation, but it only offered the one-shot shape (`HashAlgorithm::hash_encode`), so the streaming consumers in rio kept their own `md-5` dependency and `use md5::Digest` imports. Add `hash_stream.rs` with `Md5Stream`: new / update / consuming `finalize` / `finalize_reset` / one-shot `digest`, plus `io::Write` and an opaque `Debug`. The backend lives in a private module with exactly one implementation compiled in (RustCrypto `md-5` today); adding another means adding one `Md5Inner` behind a cargo feature there and nothing else in the tree changes. `Md5Stream` deliberately has no `Clone` and a consuming `finalize`: that is the intersection of what any backend can offer, so a backend switch can never surface as a compile error elsewhere. `HashAlgorithm::Md5` now delegates to `Md5Stream`; `hash.rs` no longer names `md5::Md5`. Behaviour is unchanged: the same `md-5` crate computes the same digests. Tests: RFC 1321 A.5 vectors (one-shot, byte-at-a-time, and through `HashAlgorithm::Md5`), splits on every 64-byte block and padding edge, `finalize_reset` sequences, `Write` delegation, and a proptest differential oracle against `md-5` called directly, which becomes the independent reference once a second backend exists. `hash_stream.rs` is at 100% line coverage. The bench gains a 256 KiB-chunked streaming entry that models how `EtagReader` is actually fed.
90 lines
1.7 KiB
Rust
90 lines
1.7 KiB
Rust
// Copyright 2024 RustFS Team
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#[cfg(feature = "egress")]
|
|
pub mod egress;
|
|
#[cfg(feature = "ip")]
|
|
pub mod ip;
|
|
#[cfg(feature = "net")]
|
|
pub mod net;
|
|
|
|
#[cfg(feature = "http")]
|
|
pub mod http;
|
|
|
|
#[cfg(feature = "egress")]
|
|
pub use egress::*;
|
|
#[cfg(feature = "net")]
|
|
pub use net::*;
|
|
|
|
#[cfg(all(feature = "net", feature = "io"))]
|
|
pub mod retry;
|
|
|
|
#[cfg(feature = "io")]
|
|
pub mod io;
|
|
|
|
#[cfg(feature = "hash")]
|
|
pub mod hash;
|
|
|
|
#[cfg(feature = "hash")]
|
|
pub mod hash_stream;
|
|
|
|
#[cfg(feature = "os")]
|
|
pub mod os;
|
|
|
|
#[cfg(feature = "path")]
|
|
pub mod path;
|
|
|
|
#[cfg(feature = "string")]
|
|
pub mod string;
|
|
|
|
#[cfg(feature = "crypto")]
|
|
pub mod crypto;
|
|
|
|
#[cfg(feature = "compress")]
|
|
pub mod compress;
|
|
|
|
pub mod logging;
|
|
|
|
#[cfg(feature = "path")]
|
|
pub mod dirs;
|
|
|
|
#[cfg(feature = "hash")]
|
|
pub use hash::*;
|
|
|
|
#[cfg(feature = "hash")]
|
|
pub use hash_stream::Md5Stream;
|
|
|
|
#[cfg(feature = "io")]
|
|
pub use io::*;
|
|
|
|
#[cfg(feature = "ip")]
|
|
pub use ip::*;
|
|
|
|
#[cfg(feature = "crypto")]
|
|
pub use crypto::*;
|
|
|
|
#[cfg(feature = "compress")]
|
|
pub use compress::*;
|
|
|
|
#[cfg(feature = "obj")]
|
|
pub mod obj;
|
|
|
|
#[cfg(feature = "path")]
|
|
mod dunce;
|
|
#[cfg(feature = "path")]
|
|
pub use dunce::*;
|
|
mod envs;
|
|
pub use envs::*;
|
|
pub use logging::*;
|