mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 03:46:37 +00:00
chore: upgrade dependencies and migrate to aws-lc-rs (#1333)
This commit is contained in:
+35
-35
@@ -387,7 +387,7 @@ impl Checksum {
|
||||
|
||||
// Ensure we don't divide by 0
|
||||
let raw_len = self.checksum_type.raw_byte_len();
|
||||
if raw_len == 0 || parts.len() % raw_len != 0 {
|
||||
if raw_len == 0 || !parts.len().is_multiple_of(raw_len) {
|
||||
checksums = 0;
|
||||
} else if !parts.is_empty() {
|
||||
checksums = (parts.len() / raw_len) as i32;
|
||||
@@ -506,16 +506,16 @@ pub fn get_content_checksum(headers: &HeaderMap) -> Result<Option<Checksum>, std
|
||||
for header in trailing_headers {
|
||||
let mut duplicates = false;
|
||||
for &checksum_type in crate::checksum::BASE_CHECKSUM_TYPES {
|
||||
if let Some(key) = checksum_type.key() {
|
||||
if header.eq_ignore_ascii_case(key) {
|
||||
duplicates = result.is_some();
|
||||
result = Some(Checksum {
|
||||
checksum_type: ChecksumType(checksum_type.0 | ChecksumType::TRAILING.0),
|
||||
encoded: String::new(),
|
||||
raw: Vec::new(),
|
||||
want_parts: 0,
|
||||
});
|
||||
}
|
||||
if let Some(key) = checksum_type.key()
|
||||
&& header.eq_ignore_ascii_case(key)
|
||||
{
|
||||
duplicates = result.is_some();
|
||||
result = Some(Checksum {
|
||||
checksum_type: ChecksumType(checksum_type.0 | ChecksumType::TRAILING.0),
|
||||
encoded: String::new(),
|
||||
raw: Vec::new(),
|
||||
want_parts: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
if duplicates {
|
||||
@@ -567,13 +567,13 @@ fn get_content_checksum_direct(headers: &HeaderMap) -> (ChecksumType, String) {
|
||||
checksum_type = ChecksumType(checksum_type.0 | ChecksumType::FULL_OBJECT.0);
|
||||
}
|
||||
|
||||
if checksum_type.is_set() {
|
||||
if let Some(key) = checksum_type.key() {
|
||||
if let Some(value) = headers.get(key).and_then(|v| v.to_str().ok()) {
|
||||
return (checksum_type, value.to_string());
|
||||
} else {
|
||||
return (ChecksumType::NONE, String::new());
|
||||
}
|
||||
if checksum_type.is_set()
|
||||
&& let Some(key) = checksum_type.key()
|
||||
{
|
||||
if let Some(value) = headers.get(key).and_then(|v| v.to_str().ok()) {
|
||||
return (checksum_type, value.to_string());
|
||||
} else {
|
||||
return (ChecksumType::NONE, String::new());
|
||||
}
|
||||
}
|
||||
return (checksum_type, String::new());
|
||||
@@ -581,22 +581,22 @@ fn get_content_checksum_direct(headers: &HeaderMap) -> (ChecksumType, String) {
|
||||
|
||||
// Check individual checksum headers
|
||||
for &ct in crate::checksum::BASE_CHECKSUM_TYPES {
|
||||
if let Some(key) = ct.key() {
|
||||
if let Some(value) = headers.get(key).and_then(|v| v.to_str().ok()) {
|
||||
// If already set, invalid
|
||||
if checksum_type != ChecksumType::NONE {
|
||||
if let Some(key) = ct.key()
|
||||
&& let Some(value) = headers.get(key).and_then(|v| v.to_str().ok())
|
||||
{
|
||||
// If already set, invalid
|
||||
if checksum_type != ChecksumType::NONE {
|
||||
return (ChecksumType::INVALID, String::new());
|
||||
}
|
||||
checksum_type = ct;
|
||||
|
||||
if headers.get("x-amz-checksum-type").and_then(|v| v.to_str().ok()) == Some("FULL_OBJECT") {
|
||||
if !checksum_type.can_merge() {
|
||||
return (ChecksumType::INVALID, String::new());
|
||||
}
|
||||
checksum_type = ct;
|
||||
|
||||
if headers.get("x-amz-checksum-type").and_then(|v| v.to_str().ok()) == Some("FULL_OBJECT") {
|
||||
if !checksum_type.can_merge() {
|
||||
return (ChecksumType::INVALID, String::new());
|
||||
}
|
||||
checksum_type = ChecksumType(checksum_type.0 | ChecksumType::FULL_OBJECT.0);
|
||||
}
|
||||
return (checksum_type, value.to_string());
|
||||
checksum_type = ChecksumType(checksum_type.0 | ChecksumType::FULL_OBJECT.0);
|
||||
}
|
||||
return (checksum_type, value.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -965,10 +965,10 @@ fn gf2_matrix_times(mat: &[u64], mut vec: u64) -> u64 {
|
||||
let mut mat_iter = mat.iter();
|
||||
|
||||
while vec != 0 {
|
||||
if vec & 1 != 0 {
|
||||
if let Some(&m) = mat_iter.next() {
|
||||
sum ^= m;
|
||||
}
|
||||
if vec & 1 != 0
|
||||
&& let Some(&m) = mat_iter.next()
|
||||
{
|
||||
sum ^= m;
|
||||
}
|
||||
vec >>= 1;
|
||||
mat_iter.next();
|
||||
|
||||
@@ -178,12 +178,11 @@ impl HashReader {
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(checksum) = existing_hash_reader.checksum() {
|
||||
if let Some(ref md5) = md5hex {
|
||||
if checksum != md5 {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "HashReader checksum mismatch"));
|
||||
}
|
||||
}
|
||||
if let Some(checksum) = existing_hash_reader.checksum()
|
||||
&& let Some(ref md5) = md5hex
|
||||
&& checksum != md5
|
||||
{
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "HashReader checksum mismatch"));
|
||||
}
|
||||
|
||||
if existing_hash_reader.size() > 0 && size > 0 && existing_hash_reader.size() != size {
|
||||
@@ -359,15 +358,15 @@ impl HashReader {
|
||||
}
|
||||
|
||||
if checksum.checksum_type.trailing() {
|
||||
if let Some(trailer) = self.trailer_s3s.as_ref() {
|
||||
if let Some(Some(checksum_str)) = trailer.read(|headers| {
|
||||
if let Some(trailer) = self.trailer_s3s.as_ref()
|
||||
&& let Some(Some(checksum_str)) = trailer.read(|headers| {
|
||||
checksum
|
||||
.checksum_type
|
||||
.key()
|
||||
.and_then(|key| headers.get(key).and_then(|value| value.to_str().ok().map(|s| s.to_string())))
|
||||
}) {
|
||||
map.insert(checksum.checksum_type.to_string(), checksum_str);
|
||||
}
|
||||
})
|
||||
{
|
||||
map.insert(checksum.checksum_type.to_string(), checksum_str);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -450,18 +449,18 @@ impl AsyncRead for HashReader {
|
||||
|
||||
if filled > 0 {
|
||||
// Update SHA256 hasher
|
||||
if let Some(hasher) = this.content_sha256_hasher {
|
||||
if let Err(e) = hasher.write_all(data) {
|
||||
error!("SHA256 hasher write error, error={:?}", e);
|
||||
return Poll::Ready(Err(std::io::Error::other(e)));
|
||||
}
|
||||
if let Some(hasher) = this.content_sha256_hasher
|
||||
&& let Err(e) = hasher.write_all(data)
|
||||
{
|
||||
error!("SHA256 hasher write error, error={:?}", e);
|
||||
return Poll::Ready(Err(std::io::Error::other(e)));
|
||||
}
|
||||
|
||||
// Update content hasher
|
||||
if let Some(hasher) = this.content_hasher {
|
||||
if let Err(e) = hasher.write_all(data) {
|
||||
return Poll::Ready(Err(std::io::Error::other(e)));
|
||||
}
|
||||
if let Some(hasher) = this.content_hasher
|
||||
&& let Err(e) = hasher.write_all(data)
|
||||
{
|
||||
return Poll::Ready(Err(std::io::Error::other(e)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,22 +476,22 @@ impl AsyncRead for HashReader {
|
||||
|
||||
// check content hasher
|
||||
if let (Some(hasher), Some(expected_content_hash)) = (this.content_hasher, this.content_hash) {
|
||||
if expected_content_hash.checksum_type.trailing() {
|
||||
if let Some(trailer) = this.trailer_s3s.as_ref() {
|
||||
if let Some(Some(checksum_str)) = trailer.read(|headers| {
|
||||
expected_content_hash.checksum_type.key().and_then(|key| {
|
||||
headers.get(key).and_then(|value| value.to_str().ok().map(|s| s.to_string()))
|
||||
})
|
||||
}) {
|
||||
expected_content_hash.encoded = checksum_str;
|
||||
expected_content_hash.raw = general_purpose::STANDARD
|
||||
.decode(&expected_content_hash.encoded)
|
||||
.map_err(|_| std::io::Error::other("Invalid base64 checksum"))?;
|
||||
if expected_content_hash.checksum_type.trailing()
|
||||
&& let Some(trailer) = this.trailer_s3s.as_ref()
|
||||
&& let Some(Some(checksum_str)) = trailer.read(|headers| {
|
||||
expected_content_hash
|
||||
.checksum_type
|
||||
.key()
|
||||
.and_then(|key| headers.get(key).and_then(|value| value.to_str().ok().map(|s| s.to_string())))
|
||||
})
|
||||
{
|
||||
expected_content_hash.encoded = checksum_str;
|
||||
expected_content_hash.raw = general_purpose::STANDARD
|
||||
.decode(&expected_content_hash.encoded)
|
||||
.map_err(|_| std::io::Error::other("Invalid base64 checksum"))?;
|
||||
|
||||
if expected_content_hash.raw.is_empty() {
|
||||
return Poll::Ready(Err(std::io::Error::other("Content hash mismatch")));
|
||||
}
|
||||
}
|
||||
if expected_content_hash.raw.is_empty() {
|
||||
return Poll::Ready(Err(std::io::Error::other("Content hash mismatch")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user