pub struct AwsSign<'a, T>{
method: &'a str,
url: Url,
datetime: &'a DateTime<Utc>,
region: &'a str,
access_key: &'a str,
secret_key: &'a str,
headers: T,
payload_override: Option<String>,
service: &'a str,
body: &'a [u8],
}Expand description
Low-level AWS Signature Version 4 signing primitive.
Holds all inputs needed to produce the canonical request, string-to-sign,
and final Authorization header value. Construct via AwsSign::new and
then call AwsSign::sign to obtain the header value.
Fields§
§method: &'a str§url: Url§datetime: &'a DateTime<Utc>§region: &'a str§access_key: &'a str§secret_key: &'a str§headers: T§payload_override: Option<String>§service: &'a str§body: &'a [u8]body, such as in an http POST
Implementations§
Source§impl<'a> AwsSign<'a, HashMap<String, String>>
Create a new AwsSign instance
impl<'a> AwsSign<'a, HashMap<String, String>>
Create a new AwsSign instance
§Arguments
method- HTTP method (GET, POST, etc.)url- URL to signdatetime- Date and time of the requestheaders- HTTP headersregion- AWS regionaccess_key- AWS access keysecret_key- AWS secret keyservice- AWS service codebody- Request bodysigned_headers- Optional list of signed headers, used to check inbound request signature
§Returns
A new instance of AwsSign
Source§impl<'a, T> AwsSign<'a, T>
impl<'a, T> AwsSign<'a, T>
Sourcepub fn set_payload_override(&mut self, h: String)
pub fn set_payload_override(&mut self, h: String)
for streaming uploads, we need to override the payload hash
with the actual payload hash
this is used for the UNSIGNED-PAYLOAD case
and for the payload_override case
Override the payload hash used in the canonical request.
Use "UNSIGNED-PAYLOAD" for presigned URLs or streaming uploads where
the body hash is not computed up front.
Sourcepub fn canonical_header_string(&'a self) -> String
pub fn canonical_header_string(&'a self) -> String
Return the canonicalized header string for inclusion in the canonical request.
Headers are sorted lexicographically by name and each entry is formatted as
lowercase-name:trimmed-value\n.
IMPORTANT: Sort must be by key name only, not by the full key:value string.
Otherwise x-amz-copy-source-if-match would sort before x-amz-copy-source
because - (ASCII 45) < : (ASCII 58).
Sourcepub fn signed_header_string(&'a self) -> String
pub fn signed_header_string(&'a self) -> String
Return the semicolon-separated list of signed header names (lowercase, sorted).
Sourcepub fn canonical_request(&'a self) -> String
pub fn canonical_request(&'a self) -> String
Build the canonical request string as defined in the AWS SigV4 spec.
Format: METHOD\nURI\nQUERY\nHEADERS\nSIGNED_HEADERS\nPAYLOAD_HASH
Sourcepub fn sign(&'a self) -> String
pub fn sign(&'a self) -> String
Compute and return the complete Authorization header value.
The returned string can be set directly on the outgoing request with
request.insert_header("authorization", sign_result).
Optimised to sort the header map once and compute the credential
scope once, avoiding the redundant work that would occur if
canonical_request() and signed_header_string() were called
separately.