mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-05 12:57:42 +00:00
fix clippy
This commit is contained in:
@@ -74,12 +74,12 @@ pub fn streaming_sign_v4(
|
||||
for (k, _) in &trailer {
|
||||
headers.append("X-Amz-Trailer", k.as_str().to_lowercase().parse().unwrap());
|
||||
}
|
||||
let chunked_value = HeaderValue::from_str(&vec!["aws-chunked"].join(",")).expect("err");
|
||||
let chunked_value = HeaderValue::from_str(&["aws-chunked"].join(",")).expect("err");
|
||||
headers.insert(http::header::TRANSFER_ENCODING, chunked_value);
|
||||
}
|
||||
|
||||
if !session_token.is_empty() {
|
||||
headers.insert("X-Amz-Security-Token", HeaderValue::from_str(&session_token).expect("err"));
|
||||
headers.insert("X-Amz-Security-Token", HeaderValue::from_str(session_token).expect("err"));
|
||||
}
|
||||
|
||||
let format = format_description!("[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond]Z");
|
||||
|
||||
@@ -9,10 +9,10 @@ pub fn streaming_unsigned_v4(
|
||||
) -> request::Builder {
|
||||
let headers = req.headers_mut().expect("err");
|
||||
|
||||
let chunked_value = HeaderValue::from_str(&vec!["aws-chunked"].join(",")).expect("err");
|
||||
let chunked_value = HeaderValue::from_str(&["aws-chunked"].join(",")).expect("err");
|
||||
headers.insert(http::header::TRANSFER_ENCODING, chunked_value);
|
||||
if !session_token.is_empty() {
|
||||
headers.insert("X-Amz-Security-Token", HeaderValue::from_str(&session_token).expect("err"));
|
||||
headers.insert("X-Amz-Security-Token", HeaderValue::from_str(session_token).expect("err"));
|
||||
}
|
||||
|
||||
let format = format_description!("[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond]Z");
|
||||
|
||||
@@ -12,10 +12,10 @@ const _SIGN_V4_ALGORITHM: &str = "AWS4-HMAC-SHA256";
|
||||
const SIGN_V2_ALGORITHM: &str = "AWS";
|
||||
|
||||
fn encode_url2path(req: &request::Builder, _virtual_host: bool) -> String {
|
||||
let path;
|
||||
|
||||
|
||||
//path = serde_urlencoded::to_string(req.uri_ref().unwrap().path().unwrap()).unwrap();
|
||||
path = req.uri_ref().unwrap().path().to_string();
|
||||
let path = req.uri_ref().unwrap().path().to_string();
|
||||
path
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn pre_sign_v2(
|
||||
expires: i64,
|
||||
virtual_host: bool,
|
||||
) -> request::Builder {
|
||||
if access_key_id == "" || secret_access_key == "" {
|
||||
if access_key_id.is_empty() || secret_access_key.is_empty() {
|
||||
return req;
|
||||
}
|
||||
|
||||
@@ -60,14 +60,14 @@ pub fn pre_sign_v2(
|
||||
.parse()
|
||||
.unwrap(),
|
||||
);
|
||||
let req = req.uri(Uri::from_parts(parts).unwrap());
|
||||
|
||||
|
||||
req
|
||||
req.uri(Uri::from_parts(parts).unwrap())
|
||||
}
|
||||
|
||||
fn _post_pre_sign_signature_v2(policy_base64: &str, secret_access_key: &str) -> String {
|
||||
let signature = hex(hmac_sha1(secret_access_key, policy_base64));
|
||||
signature
|
||||
|
||||
hex(hmac_sha1(secret_access_key, policy_base64))
|
||||
}
|
||||
|
||||
pub fn sign_v2(
|
||||
@@ -77,7 +77,7 @@ pub fn sign_v2(
|
||||
secret_access_key: &str,
|
||||
virtual_host: bool,
|
||||
) -> request::Builder {
|
||||
if access_key_id == "" || secret_access_key == "" {
|
||||
if access_key_id.is_empty() || secret_access_key.is_empty() {
|
||||
return req;
|
||||
}
|
||||
|
||||
@@ -109,9 +109,9 @@ pub fn sign_v2(
|
||||
|
||||
fn pre_string_to_sign_v2(req: &request::Builder, virtual_host: bool) -> String {
|
||||
let mut buf = BytesMut::new();
|
||||
write_pre_sign_v2_headers(&mut buf, &req);
|
||||
write_canonicalized_headers(&mut buf, &req);
|
||||
write_canonicalized_resource(&mut buf, &req, virtual_host);
|
||||
write_pre_sign_v2_headers(&mut buf, req);
|
||||
write_canonicalized_headers(&mut buf, req);
|
||||
write_canonicalized_resource(&mut buf, req, virtual_host);
|
||||
String::from_utf8(buf.to_vec()).unwrap()
|
||||
}
|
||||
|
||||
@@ -128,9 +128,9 @@ fn write_pre_sign_v2_headers(buf: &mut BytesMut, req: &request::Builder) {
|
||||
|
||||
fn string_to_sign_v2(req: &request::Builder, virtual_host: bool) -> String {
|
||||
let mut buf = BytesMut::new();
|
||||
write_sign_v2_headers(&mut buf, &req);
|
||||
write_canonicalized_headers(&mut buf, &req);
|
||||
write_canonicalized_resource(&mut buf, &req, virtual_host);
|
||||
write_sign_v2_headers(&mut buf, req);
|
||||
write_canonicalized_headers(&mut buf, req);
|
||||
write_canonicalized_resource(&mut buf, req, virtual_host);
|
||||
String::from_utf8(buf.to_vec()).unwrap()
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ fn write_canonicalized_resource(buf: &mut BytesMut, req: &request::Builder, virt
|
||||
let vals = result.unwrap_or_default();
|
||||
for resource in INCLUDED_QUERY {
|
||||
let vv = &vals[*resource];
|
||||
if vv.len() > 0 {
|
||||
if !vv.is_empty() {
|
||||
n += 1;
|
||||
match n {
|
||||
1 => {
|
||||
@@ -218,7 +218,7 @@ fn write_canonicalized_resource(buf: &mut BytesMut, req: &request::Builder, virt
|
||||
_ => {
|
||||
let _ = buf.write_char('&');
|
||||
let _ = buf.write_str(resource);
|
||||
if vv[0].len() > 0 {
|
||||
if !vv[0].is_empty() {
|
||||
let _ = buf.write_char('=');
|
||||
let _ = buf.write_str(&vv[0]);
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ pub fn get_signing_key(secret: &str, loc: &str, t: OffsetDateTime, service_type:
|
||||
let date = hmac_sha256(s.into_bytes(), t.format(&format).unwrap().into_bytes());
|
||||
let location = hmac_sha256(date, loc);
|
||||
let service = hmac_sha256(location, service_type);
|
||||
let signing_key = hmac_sha256(service, "aws4_request");
|
||||
signing_key
|
||||
|
||||
hmac_sha256(service, "aws4_request")
|
||||
}
|
||||
|
||||
pub fn get_signature(signing_key: [u8; 32], string_to_sign: &str) -> String {
|
||||
@@ -57,7 +57,7 @@ pub fn get_scope(location: &str, t: OffsetDateTime, service_type: &str) -> Strin
|
||||
fn get_credential(access_key_id: &str, location: &str, t: OffsetDateTime, service_type: &str) -> String {
|
||||
let scope = get_scope(location, t, service_type);
|
||||
let mut s = access_key_id.to_string();
|
||||
s.push_str("/");
|
||||
s.push('/');
|
||||
s.push_str(&scope);
|
||||
s
|
||||
}
|
||||
@@ -68,7 +68,7 @@ fn get_hashed_payload(req: &request::Builder) -> String {
|
||||
if let Some(payload) = headers.get("X-Amz-Content-Sha256") {
|
||||
hashed_payload = payload.to_str().unwrap();
|
||||
}
|
||||
if hashed_payload == "" {
|
||||
if hashed_payload.is_empty() {
|
||||
hashed_payload = UNSIGNED_PAYLOAD;
|
||||
}
|
||||
hashed_payload.to_string()
|
||||
@@ -106,7 +106,7 @@ fn get_canonical_headers(req: &request::Builder, ignored_headers: &HashMap<Strin
|
||||
let k: &str = &k;
|
||||
match k {
|
||||
"host" => {
|
||||
let _ = buf.write_str(&get_host_addr(&req));
|
||||
let _ = buf.write_str(&get_host_addr(req));
|
||||
let _ = buf.write_char('\n');
|
||||
}
|
||||
_ => {
|
||||
@@ -179,8 +179,8 @@ fn get_canonical_request(req: &request::Builder, ignored_headers: &HashMap<Strin
|
||||
canonical_request.push(req.method_ref().unwrap().to_string());
|
||||
canonical_request.push(req.uri_ref().unwrap().path().to_string());
|
||||
canonical_request.push(canonical_query_string);
|
||||
canonical_request.push(get_canonical_headers(&req, ignored_headers));
|
||||
canonical_request.push(get_signed_headers(&req, ignored_headers));
|
||||
canonical_request.push(get_canonical_headers(req, ignored_headers));
|
||||
canonical_request.push(get_signed_headers(req, ignored_headers));
|
||||
canonical_request.push(hashed_payload.to_string());
|
||||
canonical_request.join("\n")
|
||||
}
|
||||
@@ -206,7 +206,7 @@ pub fn pre_sign_v4(
|
||||
expires: i64,
|
||||
t: OffsetDateTime,
|
||||
) -> request::Builder {
|
||||
if access_key_id == "" || secret_access_key == "" {
|
||||
if access_key_id.is_empty() || secret_access_key.is_empty() {
|
||||
return req;
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ pub fn pre_sign_v4(
|
||||
query.push(("X-Amz-Expires".to_string(), format!("{:010}", expires)));
|
||||
query.push(("X-Amz-SignedHeaders".to_string(), signed_headers));
|
||||
query.push(("X-Amz-Credential".to_string(), credential));
|
||||
if session_token != "" {
|
||||
if !session_token.is_empty() {
|
||||
query.push(("X-Amz-Security-Token".to_string(), session_token.to_string()));
|
||||
}
|
||||
|
||||
@@ -256,15 +256,15 @@ pub fn pre_sign_v4(
|
||||
.parse()
|
||||
.unwrap(),
|
||||
);
|
||||
let req = req.uri(Uri::from_parts(parts).unwrap());
|
||||
|
||||
|
||||
req
|
||||
req.uri(Uri::from_parts(parts).unwrap())
|
||||
}
|
||||
|
||||
fn _post_pre_sign_signature_v4(policy_base64: &str, t: OffsetDateTime, secret_access_key: &str, location: &str) -> String {
|
||||
let signing_key = get_signing_key(secret_access_key, location, t, SERVICE_TYPE_S3);
|
||||
let signature = get_signature(signing_key, policy_base64);
|
||||
signature
|
||||
|
||||
get_signature(signing_key, policy_base64)
|
||||
}
|
||||
|
||||
fn _sign_v4_sts(req: request::Builder, access_key_id: &str, secret_access_key: &str, location: &str) -> request::Builder {
|
||||
@@ -281,7 +281,7 @@ fn sign_v4_inner(
|
||||
service_type: &str,
|
||||
trailer: HeaderMap,
|
||||
) -> request::Builder {
|
||||
if access_key_id == "" || secret_access_key == "" {
|
||||
if access_key_id.is_empty() || secret_access_key.is_empty() {
|
||||
return req;
|
||||
}
|
||||
|
||||
@@ -292,11 +292,11 @@ fn sign_v4_inner(
|
||||
let format = format_description!("[year][month][day]T[hour][minute][second]Z");
|
||||
headers.insert("X-Amz-Date", t.format(&format).unwrap().to_string().parse().unwrap());
|
||||
|
||||
if session_token != "" {
|
||||
if !session_token.is_empty() {
|
||||
headers.insert("X-Amz-Security-Token", session_token.parse().unwrap());
|
||||
}
|
||||
|
||||
if trailer.len() > 0 {
|
||||
if !trailer.is_empty() {
|
||||
for (k, _) in &trailer {
|
||||
headers.append("X-Amz-Trailer", k.as_str().to_lowercase().parse().unwrap());
|
||||
}
|
||||
@@ -326,18 +326,18 @@ fn sign_v4_inner(
|
||||
);
|
||||
headers.insert("Authorization", auth.parse().unwrap());
|
||||
|
||||
if trailer.len() > 0 {
|
||||
if !trailer.is_empty() {
|
||||
//req.Trailer = trailer;
|
||||
for (_, v) in &trailer {
|
||||
headers.append(http::header::TRAILER, v.clone());
|
||||
}
|
||||
return streaming_unsigned_v4(req, &session_token, content_len, t);
|
||||
return streaming_unsigned_v4(req, session_token, content_len, t);
|
||||
}
|
||||
req
|
||||
}
|
||||
|
||||
fn _unsigned_trailer(mut req: request::Builder, content_len: i64, trailer: HeaderMap) {
|
||||
if trailer.len() > 0 {
|
||||
if !trailer.is_empty() {
|
||||
return;
|
||||
}
|
||||
let t = OffsetDateTime::now_utc();
|
||||
@@ -354,7 +354,7 @@ fn _unsigned_trailer(mut req: request::Builder, content_len: i64, trailer: Heade
|
||||
headers.insert("Content-Encoding", "aws-chunked".parse().unwrap());
|
||||
headers.insert("x-amz-decoded-content-length", format!("{:010}", content_len).parse().unwrap());
|
||||
|
||||
if trailer.len() > 0 {
|
||||
if !trailer.is_empty() {
|
||||
for (_, v) in &trailer {
|
||||
headers.append(http::header::TRAILER, v.clone());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user