mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-20 19:42:17 +00:00
Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -408,23 +408,6 @@ impl HashReader {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn enable_auto_checksum(&mut self, checksum_type: ChecksumType) -> Result<(), std::io::Error> {
|
||||
if !checksum_type.is_set() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let Some(hasher) = checksum_type.hasher() else {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "Invalid checksum type"));
|
||||
};
|
||||
|
||||
self.content_hash = Some(Checksum {
|
||||
checksum_type,
|
||||
..Default::default()
|
||||
});
|
||||
self.content_hasher = Some(hasher);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn checksum(&self) -> Option<Checksum> {
|
||||
if self
|
||||
.content_hash
|
||||
@@ -564,9 +547,7 @@ impl AsyncRead for HashReader {
|
||||
}
|
||||
|
||||
// check content hasher
|
||||
if let (Some(hasher), Some(expected_content_hash)) =
|
||||
(this.content_hasher.as_mut(), this.content_hash.as_mut())
|
||||
{
|
||||
if let (Some(hasher), Some(expected_content_hash)) = (this.content_hasher, this.content_hash) {
|
||||
if expected_content_hash.checksum_type.trailing()
|
||||
&& let Some(trailer) = this.trailer_s3s.as_ref()
|
||||
&& let Some(Some(checksum_str)) = trailer.read(|headers| {
|
||||
@@ -588,11 +569,7 @@ impl AsyncRead for HashReader {
|
||||
|
||||
let content_hash = hasher.finalize();
|
||||
|
||||
if expected_content_hash.encoded.is_empty() {
|
||||
expected_content_hash.raw = content_hash.clone();
|
||||
expected_content_hash.encoded = general_purpose::STANDARD.encode(&content_hash);
|
||||
*this.content_hash = Some(expected_content_hash.clone());
|
||||
} else if content_hash != expected_content_hash.raw {
|
||||
if content_hash != expected_content_hash.raw {
|
||||
let expected_hex = hex_simd::encode_to_string(&expected_content_hash.raw, hex_simd::AsciiCase::Lower);
|
||||
let actual_hex = hex_simd::encode_to_string(content_hash, hex_simd::AsciiCase::Lower);
|
||||
error!(
|
||||
|
||||
Reference in New Issue
Block a user