Skip to content

Commit

Permalink
refactor: Move canonical_request into string_to_sign
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Sep 28, 2023
1 parent a79e8e6 commit 0aaa2fd
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions object_store/src/aws/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,18 @@ impl<'a> AwsAuthorizer<'a> {
let (signed_headers, canonical_headers) = canonicalize_headers(request.headers());
let canonical_query = canonicalize_query(request.url());

// https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
let canonical_request = format!(
"{}\n{}\n{}\n{}\n{}\n{}",
request.method().as_str(),
canonical_uri,
canonical_query,
canonical_headers,
signed_headers,
digest
);

let scope = self.scope(date);

let string_to_sign = self.string_to_sign(date, &scope, &canonical_request);
let string_to_sign = self.string_to_sign(
date,
&scope,
request.method(),
&canonical_uri,
&canonical_query,
&canonical_headers,
&signed_headers,
&digest,
);

// sign the string
let signature =
Expand All @@ -200,8 +198,24 @@ impl<'a> AwsAuthorizer<'a> {
&self,
date: DateTime<Utc>,
scope: &str,
canonical_request: &str,
request_method: &Method,
canonical_uri: &str,
canonical_query: &str,
canonical_headers: &str,
signed_headers: &str,
digest: &str,
) -> String {
// https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
let canonical_request = format!(
"{}\n{}\n{}\n{}\n{}\n{}",
request_method.as_str(),
canonical_uri,
canonical_query,
canonical_headers,
signed_headers,
digest
);

let hashed_canonical_request = hex_digest(canonical_request.as_bytes());

format!(
Expand Down

0 comments on commit 0aaa2fd

Please sign in to comment.