Expose sign() and verify()

This commit is contained in:
Félix Saparelli 2016-04-24 19:18:26 +12:00
parent 86c0889ae3
commit 1b7ec1057a
1 changed files with 2 additions and 2 deletions

View File

@ -131,7 +131,7 @@ pub struct TokenData<T: Part> {
/// Take the payload of a JWT and sign it using the algorithm given.
/// Returns the base64 url safe encoded of the hmac result
fn sign(data: &str, secret: &[u8], algorithm: Algorithm) -> String {
pub fn sign(data: &str, secret: &[u8], algorithm: Algorithm) -> String {
fn crypt<D: Digest>(digest: D, data: &str, secret: &[u8]) -> String {
let mut hmac = Hmac::new(digest, secret);
hmac.input(data.as_bytes());
@ -146,7 +146,7 @@ fn sign(data: &str, secret: &[u8], algorithm: Algorithm) -> String {
}
/// Compares the signature given with a re-computed signature
fn verify(signature: &str, data: &str, secret: &[u8], algorithm: Algorithm) -> bool {
pub fn verify(signature: &str, data: &str, secret: &[u8], algorithm: Algorithm) -> bool {
fixed_time_eq(signature.as_ref(), sign(data, secret, algorithm).as_ref())
}