diff --git a/Cargo.toml b/Cargo.toml index 06fd0a37..4ce20c9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,9 @@ keywords = ["jwt", "web", "api", "token", "json"] [dependencies] error-chain = { version = "0.10", default-features = false } -serde_json = "0.9" -serde_derive = "0.9" -serde = "0.9" +serde_json = "1.0" +serde_derive = "1.0" +serde = "1.0" ring = { version = "0.7", features = ["rsa_signing", "dev_urandom_fallback"] } base64 = "0.4" untrusted = "0.3" diff --git a/README.md b/README.md index 6fbdb7fd..d67bf779 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Add the following to Cargo.toml: ```toml jsonwebtoken = "2" -serde_derive = "0.9" +serde_derive = "1.0" ``` ## How to use diff --git a/src/lib.rs b/src/lib.rs index 1f517cc8..e323eab9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,7 @@ pub use crypto::{ pub use validation::Validation; -use serde::de::Deserialize; +use serde::de::DeserializeOwned; use serde::ser::Serialize; use errors::{Result, ErrorKind}; @@ -101,7 +101,7 @@ macro_rules! expect_two { /// // Claims is a struct that implements Deserialize /// let token_data = decode::(&token, "secret", Algorithm::HS256, &Validation::default()); /// ``` -pub fn decode(token: &str, key: &[u8], algorithm: Algorithm, validation: &Validation) -> Result> { +pub fn decode(token: &str, key: &[u8], algorithm: Algorithm, validation: &Validation) -> Result> { let (signature, signing_input) = expect_two!(token.rsplitn(2, '.')); if validation.validate_signature && !verify(signature, signing_input, key, algorithm)? { diff --git a/src/serialization.rs b/src/serialization.rs index fe7529e2..12d5e5de 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -1,5 +1,5 @@ use base64; -use serde::de::Deserialize; +use serde::de::DeserializeOwned; use serde::ser::Serialize; use serde_json::{from_str, to_string, Value}; use serde_json::map::Map; @@ -10,7 +10,7 @@ use header::Header; /// The return type of a successful call to decode #[derive(Debug)] -pub struct TokenData { +pub struct TokenData { pub header: Header, pub claims: T } @@ -22,7 +22,7 @@ pub fn to_jwt_part(input: &T) -> Result { } /// Decodes from base64 and deserializes from JSON to a struct -pub fn from_jwt_part, T: Deserialize>(encoded: B) -> Result { +pub fn from_jwt_part, T: DeserializeOwned>(encoded: B) -> Result { let decoded = base64::decode_config(encoded.as_ref(), base64::URL_SAFE_NO_PAD)?; let s = String::from_utf8(decoded)?; @@ -30,7 +30,7 @@ pub fn from_jwt_part, T: Deserialize>(encoded: B) -> Result { } /// Decodes from base64 and deserializes from JSON to a struct AND a hashmap -pub fn from_jwt_part_claims, T: Deserialize>(encoded: B) -> Result<(T, Map)> { +pub fn from_jwt_part_claims, T: DeserializeOwned>(encoded: B) -> Result<(T, Map)> { let decoded = base64::decode_config(encoded.as_ref(), base64::URL_SAFE_NO_PAD)?; let s = String::from_utf8(decoded)?;