Skip to content

Commit

Permalink
Auto merge of #5 - badboy:pr-4, r=badboy
Browse files Browse the repository at this point in the history
Use |ring::hmac::verify_with_own_key|.

Closes #4
  • Loading branch information
homu committed Nov 3, 2015
2 parents a00c666 + 20bf565 commit 23617b4
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ pub enum Error {

pub struct Signer {
separator: char,
s_key: hmac::SigningKey,
v_key: hmac::VerificationKey,
key: hmac::SigningKey,
}

pub struct TimestampSigner {
Expand All @@ -89,8 +88,7 @@ impl Signer {

Signer {
separator: '.',
s_key: hmac::SigningKey::new(ALGORITHM, derived_key.as_ref()),
v_key: hmac::VerificationKey::new(ALGORITHM, derived_key.as_ref()),
key: hmac::SigningKey::new(ALGORITHM, derived_key.as_ref()),
}
}

Expand All @@ -111,15 +109,15 @@ impl Signer {
};

let sig = try!(sig.from_base64().map_err(|_| Error::BadSignature));
try!(hmac::verify(&self.v_key, value.as_bytes(), &sig)
try!(hmac::verify_with_own_key(&self.key, value.as_bytes(), &sig)
.map_err(|_| Error::BadSignature));

Ok(value.into())
}


fn signature(&self, value: &str) -> String {
let sig = hmac::sign(&self.s_key, value.as_bytes());
let sig = hmac::sign(&self.key, value.as_bytes());
sig.as_ref().to_base64(URL_SAFE)
}
}
Expand Down

0 comments on commit 23617b4

Please sign in to comment.