softprops / sigv4 Goto Github PK
View Code? Open in Web Editor NEW๐โ๏ธ aws sigv4 signed requests on the command line
License: MIT License
๐โ๏ธ aws sigv4 signed requests on the command line
License: MIT License
Hey Doug! I've got a quick draft of a SigV4 signer I drew up a while back using ring. I haven't really tested it end-to-end, but it might be useful to you!
use bytes::Bytes;
use ring::{
digest,
hmac::{self, Signature, SigningKey},
rand::{self, SecureRandom},
};
use std::error::Error;
fn sign_inner(mut data: Vec<u8>, key: Bytes) -> Result<Signature, Box<Error>> {
rand::SystemRandom::new().fill(&mut data)?;
let signature = SigningKey::new(&digest::SHA256, &data);
let signature = hmac::sign(&signature, &key.as_ref());
Ok(signature)
}
pub fn sign(
key: String,
date: Vec<u8>,
region: Vec<u8>,
service: Vec<u8>,
) -> Result<Signature, Box<Error>> {
let sig = format!("AWS4{}", key);
let sig = sign_inner(date, Bytes::from(sig.as_bytes()))?;
let sig = sign_inner(region, Bytes::from(sig.as_ref()))?;
let sig = sign_inner(service, Bytes::from(sig.as_ref()))?;
let sig = sign_inner(
String::from("aws4_request").as_bytes().to_vec(),
Bytes::from(sig.as_ref()),
)?;
Ok(sig)
}
#[test]
fn test_sign() {
let key = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY";
let date = "20120215";
let region_name = "us-east-1";
let service = "iam";
let result = sign(
key.to_string(),
date.as_bytes().to_vec(),
region_name.as_bytes().to_vec(),
service.as_bytes().to_vec(),
)
.unwrap();
dbg!(result);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.