#aws #signature

aws-sign-v4

Generate AWS Signature 4 headers easily

3 releases

0.1.1 Dec 30, 2019
0.1.0 Nov 26, 2019

#426 in Cryptography

Download history 230/week @ 2022-06-05 153/week @ 2022-06-12 95/week @ 2022-06-19 165/week @ 2022-06-26 254/week @ 2022-07-03 483/week @ 2022-07-10 219/week @ 2022-07-17 291/week @ 2022-07-24 435/week @ 2022-07-31 251/week @ 2022-08-07 425/week @ 2022-08-14 252/week @ 2022-08-21 172/week @ 2022-08-28 83/week @ 2022-09-04 151/week @ 2022-09-11 195/week @ 2022-09-18

613 downloads per month

MIT license

13KB
168 lines

aws-sign-v4

Crates.io

Use this crate to generate an AUTHORIZATION header for AWS Signature Version 4 services.

Example

Example usage with reqwest:

const S3_ACCESS: &str = "my-access-key";
const S3_SECRET: &str = "my-secret-key";

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let datetime = chrono::Utc::now();
    let url = "https://s3-bucket-url";
    let mut headers = reqwest::header::HeaderMap::new();

    headers.insert(
        "X-Amz-Date",
        datetime
            .format("%Y%m%dT%H%M%SZ")
            .to_string()
            .parse()
            .unwrap(),
    );
    headers.insert("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD".parse().unwrap());
    headers.insert("host", "my-host".parse().unwrap());

    let s = aws_sign_v4::AwsSign::new(
        "GET",
        url,
        &datetime,
        &headers,
        "us-east-1",
        &S3_ACCESS,
        &S3_SECRET,
    );
    let signature = s.sign();
    println!("{:#?}", signature);
    headers.insert(reqwest::header::AUTHORIZATION, signature.parse().unwrap());

    let client = reqwest::Client::new();
    let res = client
        .get(url)
        .headers(headers.to_owned())
        .body("")
        .send()
        .await?;

    println!("Status: {}", res.status());
    let body = res.text().await?;
    println!("Body:\n\n{}", body);
    Ok(())
}

Dependencies

~9.5MB
~264K SLoC