Get more tests working
This commit is contained in:
parent
81a965caef
commit
ecae8ea43c
3 changed files with 7 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
use base64::{decode, encode_config, URL_SAFE};
|
use base64::{decode_config, encode_config, URL_SAFE};
|
||||||
use Component;
|
use Component;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -33,7 +33,7 @@ impl<T: Serialize + Deserialize> Claims<T>{
|
||||||
|
|
||||||
impl<T: Serialize + Deserialize> Component for Claims<T> {
|
impl<T: Serialize + Deserialize> Component for Claims<T> {
|
||||||
fn from_base64(raw: &str) -> Result<Claims<T>, Error> {
|
fn from_base64(raw: &str) -> Result<Claims<T>, Error> {
|
||||||
let data = try!(decode(raw));
|
let data = try!(decode_config(raw, URL_SAFE));
|
||||||
let reg_claims: Registered = try!(serde_json::from_slice(&data));
|
let reg_claims: Registered = try!(serde_json::from_slice(&data));
|
||||||
|
|
||||||
let pri_claims: T = try!(serde_json::from_slice(&data));
|
let pri_claims: T = try!(serde_json::from_slice(&data));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use base64::{decode, encode_config, URL_SAFE};
|
use base64::{decode_config, encode_config, URL_SAFE};
|
||||||
use openssl::hash::MessageDigest;
|
use openssl::hash::MessageDigest;
|
||||||
use openssl::memcmp;
|
use openssl::memcmp;
|
||||||
use openssl::pkey::PKey;
|
use openssl::pkey::PKey;
|
||||||
|
@ -26,7 +26,7 @@ pub fn sign_rsa(data: &str, key: &[u8], digest: MessageDigest) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify(target: &str, data: &str, key: &[u8], digest: MessageDigest) -> bool {
|
pub fn verify(target: &str, data: &str, key: &[u8], digest: MessageDigest) -> bool {
|
||||||
let target_bytes: Vec<u8> = decode(target).unwrap();
|
let target_bytes: Vec<u8> = decode_config(target, URL_SAFE).unwrap();
|
||||||
let secret_key = PKey::hmac(key).unwrap();
|
let secret_key = PKey::hmac(key).unwrap();
|
||||||
|
|
||||||
let mut signer = Signer::new(digest, &secret_key).unwrap();
|
let mut signer = Signer::new(digest, &secret_key).unwrap();
|
||||||
|
@ -38,7 +38,7 @@ pub fn verify(target: &str, data: &str, key: &[u8], digest: MessageDigest) -> bo
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify_rsa(signature: &str, data: &str, key: &[u8], digest: MessageDigest) -> bool {
|
pub fn verify_rsa(signature: &str, data: &str, key: &[u8], digest: MessageDigest) -> bool {
|
||||||
let signature_bytes: Vec<u8> = decode(signature).unwrap();
|
let signature_bytes: Vec<u8> = decode_config(signature, URL_SAFE).unwrap();
|
||||||
let public_key = Rsa::public_key_from_pem(key).unwrap();
|
let public_key = Rsa::public_key_from_pem(key).unwrap();
|
||||||
let pkey = PKey::from_rsa(public_key).unwrap();
|
let pkey = PKey::from_rsa(public_key).unwrap();
|
||||||
let mut verifier = Verifier::new(digest, &pkey).unwrap();
|
let mut verifier = Verifier::new(digest, &pkey).unwrap();
|
||||||
|
|
|
@ -5,7 +5,7 @@ extern crate serde;
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use base64::{decode, encode_config, URL_SAFE};
|
use base64::{decode_config, encode_config, URL_SAFE};
|
||||||
use openssl::hash::MessageDigest;
|
use openssl::hash::MessageDigest;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
|
@ -41,7 +41,7 @@ impl<T> Component for T
|
||||||
|
|
||||||
/// Parse from a string.
|
/// Parse from a string.
|
||||||
fn from_base64(raw: &str) -> Result<T, Error> {
|
fn from_base64(raw: &str) -> Result<T, Error> {
|
||||||
let data = try!(decode(raw));
|
let data = try!(decode_config(raw, URL_SAFE));
|
||||||
let s = try!(String::from_utf8(data));
|
let s = try!(String::from_utf8(data));
|
||||||
Ok(try!(serde_json::from_str(&*s)))
|
Ok(try!(serde_json::from_str(&*s)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue