chore: clean relative to references and borrows

- lint message: the borrowed expression implements the required traits
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#needless_borrows_for_generic_args
- lint message: this expression creates a reference which is immediately dereferenced by the compiler
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#needless_borrow
- lint message: you don't need to add `&` to all patterns
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#match_ref_pat
- remove useless taken reference
lint message: needlessly taken reference of left operand
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#op_ref
- use &Path instead of &PathBuf as fn parameters
lint message: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#ptr_arg
This commit is contained in:
Gwen Lg
2025-12-13 17:43:05 +01:00
parent 209263eb93
commit 141b3f24f1
35 changed files with 129 additions and 134 deletions
+4 -4
View File
@@ -57,23 +57,23 @@ pub fn handle_get_bucket_acl(ctx: ReqCtx) -> Result<Response<ResBody>, Error> {
if kp.allow_owner {
grants.push(s3_xml::Grant {
grantee: create_grantee(&key_p, &api_key),
grantee: create_grantee(key_p, &api_key),
permission: s3_xml::Value("FULL_CONTROL".to_string()),
});
} else {
if kp.allow_read {
grants.push(s3_xml::Grant {
grantee: create_grantee(&key_p, &api_key),
grantee: create_grantee(key_p, &api_key),
permission: s3_xml::Value("READ".to_string()),
});
grants.push(s3_xml::Grant {
grantee: create_grantee(&key_p, &api_key),
grantee: create_grantee(key_p, &api_key),
permission: s3_xml::Value("READ_ACP".to_string()),
});
}
if kp.allow_write {
grants.push(s3_xml::Grant {
grantee: create_grantee(&key_p, &api_key),
grantee: create_grantee(key_p, &api_key),
permission: s3_xml::Value("WRITE".to_string()),
});
}
+8 -8
View File
@@ -124,7 +124,7 @@ impl EncryptionParams {
pub fn add_response_headers(&self, resp: &mut http::response::Builder) {
if let Self::SseC { client_key_md5, .. } = self {
let md5 = BASE64_STANDARD.encode(&client_key_md5);
let md5 = BASE64_STANDARD.encode(client_key_md5);
resp.headers_mut().unwrap().insert(
X_AMZ_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM,
@@ -196,7 +196,7 @@ impl EncryptionParams {
None
},
};
let plaintext = enc.decrypt_blob(&inner)?;
let plaintext = enc.decrypt_blob(inner)?;
let inner = ObjectVersionMetaInner::decode(&plaintext)
.ok_or_internal_error("Could not decode encrypted metadata")?;
Ok((enc, Cow::Owned(inner)))
@@ -248,7 +248,7 @@ impl EncryptionParams {
// So we just put some random bytes.
let mut random = [0u8; 16];
OsRng.fill_bytes(&mut random);
hex::encode(&random)
hex::encode(random)
}
}
}
@@ -263,12 +263,12 @@ impl EncryptionParams {
Self::SseC {
object_key: Some(oek),
..
} => Some(Aes256Gcm::new(&oek)),
} => Some(Aes256Gcm::new(oek)),
Self::SseC {
client_key,
object_key: None,
..
} => Some(Aes256Gcm::new(&client_key)),
} => Some(Aes256Gcm::new(client_key)),
Self::Plaintext => None,
}
}
@@ -433,7 +433,7 @@ fn parse_request_headers(
let key_b64 =
key.ok_or_bad_request("Missing server-side-encryption-customer-key header")?;
let key_bytes: [u8; 32] = BASE64_STANDARD
.decode(&key_b64)
.decode(key_b64)
.ok_or_bad_request(
"Invalid server-side-encryption-customer-key header: invalid base64",
)?
@@ -445,7 +445,7 @@ fn parse_request_headers(
let md5_b64 =
md5.ok_or_bad_request("Missing server-side-encryption-customer-key-md5 header")?;
let md5_bytes = BASE64_STANDARD.decode(&md5_b64).ok_or_bad_request(
let md5_bytes = BASE64_STANDARD.decode(md5_b64).ok_or_bad_request(
"Invalid server-side-encryption-customer-key-md5 header: invalid bass64",
)?;
@@ -547,7 +547,7 @@ impl Stream for DecryptStream {
let nonce_size = StreamNonceSize::to_usize();
if let Some(nonce) = this.buf.take_exact(nonce_size) {
let nonce = Nonce::from_slice(nonce.as_ref());
*this.state = DecryptStreamState::Running(DecryptorLE31::new(&this.key, nonce));
*this.state = DecryptStreamState::Running(DecryptorLE31::new(this.key, nonce));
break;
}
+6 -6
View File
@@ -124,7 +124,7 @@ fn handle_http_precondition(
) -> Result<Option<Response<ResBody>>, Error> {
let precondition_headers = PreconditionHeaders::parse(req)?;
if let Some(status_code) = precondition_headers.check(&version, &version_meta.etag)? {
if let Some(status_code) = precondition_headers.check(version, &version_meta.etag)? {
Ok(Some(
Response::builder()
.status(status_code)
@@ -189,7 +189,7 @@ pub async fn handle_head_without_ctx(
OekDerivationInfo::for_object(&object, object_version),
)?;
let checksum_mode = checksum_mode(&req);
let checksum_mode = checksum_mode(req);
if let Some(part_number) = part_number {
match version_data {
@@ -316,7 +316,7 @@ pub async fn handle_get_without_ctx(
OekDerivationInfo::for_object(&object, last_v),
)?;
let checksum_mode = checksum_mode(&req);
let checksum_mode = checksum_mode(req);
match (part_number, parse_range_header(req, last_v_meta.size)?) {
(Some(_), Some(_)) => Err(Error::bad_request(
@@ -403,7 +403,7 @@ async fn handle_get_full(
let mut resp_builder = object_headers(
version,
version_meta,
&meta_inner,
meta_inner,
encryption,
checksum_mode,
)
@@ -515,7 +515,7 @@ async fn handle_get_range(
match &version_data {
ObjectVersionData::DeleteMarker => unreachable!(),
ObjectVersionData::Inline(_meta, bytes) => {
let bytes = encryption.decrypt_blob(&bytes)?;
let bytes = encryption.decrypt_blob(bytes)?;
if end as usize <= bytes.len() {
let body = bytes_body(bytes[begin as usize..end as usize].to_vec().into());
Ok(resp_builder.body(body)?)
@@ -564,7 +564,7 @@ async fn handle_get_part(
if part_number != 1 {
return Err(Error::InvalidPart);
}
let bytes = encryption.decrypt_blob(&bytes)?;
let bytes = encryption.decrypt_blob(bytes)?;
assert_eq!(bytes.len() as u64, version_meta.size);
Ok(resp_builder
.header(CONTENT_LENGTH, format!("{}", bytes.len()))
+5 -5
View File
@@ -324,31 +324,31 @@ pub async fn handle_list_parts(
size: s3_xml::IntValue(part.size as i64),
checksum_crc32: match &checksum {
Some(ChecksumValue::Crc32(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
checksum_crc32c: match &checksum {
Some(ChecksumValue::Crc32c(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
checksum_crc64nvme: match &checksum {
Some(ChecksumValue::Crc64Nvme(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
checksum_sha1: match &checksum {
Some(ChecksumValue::Sha1(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
checksum_sha256: match &checksum {
Some(ChecksumValue::Sha256(x)) => {
Some(s3_xml::Value(BASE64_STANDARD.encode(&x)))
Some(s3_xml::Value(BASE64_STANDARD.encode(x)))
}
_ => None,
},
+14 -18
View File
@@ -43,7 +43,7 @@ pub async fn handle_create_multipart_upload(
bucket_name,
..
} = &ctx;
let existing_object = garage.object_table.get(&bucket_id, &key).await?;
let existing_object = garage.object_table.get(bucket_id, key).await?;
let upload_id = gen_uuid();
let timestamp = next_timestamp(existing_object.as_ref());
@@ -57,12 +57,12 @@ pub async fn handle_create_multipart_upload(
// Determine whether object should be encrypted, and if so the key
let encryption = EncryptionParams::new_from_headers(
&garage,
garage,
req.headers(),
OekDerivationInfo {
bucket_id: *bucket_id,
version_id: upload_id,
object_key: &key,
object_key: key,
},
)?;
let object_encryption = encryption.encrypt_meta(meta)?;
@@ -157,12 +157,8 @@ pub async fn handle_put_part(
} => (encryption, checksum_algorithm),
_ => unreachable!(),
};
let (encryption, _) = EncryptionParams::check_decrypt(
&garage,
&req_head.headers,
&object_encryption,
oek_params,
)?;
let (encryption, _) =
EncryptionParams::check_decrypt(garage, &req_head.headers, &object_encryption, oek_params)?;
// Check object is valid and part can be accepted
let first_block = first_block.ok_or_bad_request("Empty body")?;
@@ -459,7 +455,7 @@ pub async fn handle_complete_multipart_upload(
None => object_encryption,
Some(_) => {
let (encryption, meta) = EncryptionParams::check_decrypt(
&garage,
garage,
&req_head.headers,
&object_encryption,
oek_params,
@@ -503,23 +499,23 @@ pub async fn handle_complete_multipart_upload(
key: s3_xml::Value(key),
etag: s3_xml::Value(format!("\"{}\"", etag)),
checksum_crc32: match &checksum_extra {
Some(ChecksumValue::Crc32(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Crc32(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_crc32c: match &checksum_extra {
Some(ChecksumValue::Crc32c(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Crc32c(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_crc64nvme: match &checksum_extra {
Some(ChecksumValue::Crc64Nvme(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Crc64Nvme(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_sha1: match &checksum_extra {
Some(ChecksumValue::Sha1(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Sha1(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_sha256: match &checksum_extra {
Some(ChecksumValue::Sha256(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(&x))),
Some(ChecksumValue::Sha256(x)) => Some(s3_xml::Value(BASE64_STANDARD.encode(x))),
_ => None,
},
checksum_type: match checksum_algorithm {
@@ -735,7 +731,7 @@ impl MultipartChecksummer {
part_len: u64,
) -> Result<(), Error> {
self.md5
.update(&hex::decode(&etag).ok_or_message("invalid etag hex")?);
.update(&hex::decode(etag).ok_or_message("invalid etag hex")?);
if let Some(extra) = &mut self.extra {
extra.update(checksum, part_len)?;
}
@@ -815,10 +811,10 @@ impl MultipartExtraChecksummer {
}
},
(Self::CompositeSha1(sha1), Some(ChecksumValue::Sha1(x))) => {
sha1.update(&x);
sha1.update(x);
}
(Self::CompositeSha256(sha256), Some(ChecksumValue::Sha256(x))) => {
sha256.update(&x);
sha256.update(x);
}
_ => {
return Err(Error::internal_error(format!(
+1 -1
View File
@@ -91,7 +91,7 @@ pub async fn handle_put(
OekDerivationInfo {
bucket_id: ctx.bucket_id,
version_id: version_uuid,
object_key: &key,
object_key: key,
},
)?;