Skip to content

Instantly share code, notes, and snippets.

@wunki
Created July 2, 2014 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wunki/ca286c5b478d881a5b1f to your computer and use it in GitHub Desktop.
Save wunki/ca286c5b478d881a5b1f to your computer and use it in GitHub Desktop.
fn sign(req: RequestWriter, path: &Path) -> String {
let mut hmac = hmac::Hmac::new(sha1::Sha1::new(), "foo".as_bytes());
string_to_sign(hmac, req, path);
hmac.result().code().to_base64(URL_SAFE)
}
// See: http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html
// The string to sign consists of the following data:
// StringToSign = HTTP-Verb + "\n" +
// Content-MD5 + "\n" +
// Content-Type + "\n" +
// Date + "\n" +
// CanonicalizedAmzHeaders +
// CanonicalizedResource;
#[allow(dead_code)]
fn string_to_sign(mut hmac: hmac::Hmac<sha1::Sha1>, req: RequestWriter, path: &Path) {
hmac.input(req.method.to_str().as_bytes());
hmac.input("\n".as_bytes());
hmac.input(md5sum(path).as_bytes());
hmac.input("\n".as_bytes());
hmac.input(contenttype(path).as_bytes());
hmac.input("\n".as_bytes());
hmac.input(req.headers.date.unwrap().http_value().as_bytes());
hmac.input("\n".as_bytes());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment