From ab0ab9b48bf482545d6c1ebf42c5517a73cb9d2a Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sun, 28 Oct 2018 19:54:35 +0100 Subject: [PATCH] Update examples and readme for exp use --- README.md | 3 ++- examples/custom_header.rs | 6 ++++-- examples/validation.rs | 13 +++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 32e21ff..4ba0f6b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ use jwt::{encode, decode, Header, Algorithm, Validation}; #[derive(Debug, Serialize, Deserialize)] struct Claims { sub: String, - company: String + company: String, + exp: usize, } ``` diff --git a/examples/custom_header.rs b/examples/custom_header.rs index 5fdc078..38d2248 100644 --- a/examples/custom_header.rs +++ b/examples/custom_header.rs @@ -9,13 +9,15 @@ use jwt::errors::{ErrorKind}; #[derive(Debug, Serialize, Deserialize)] struct Claims { sub: String, - company: String + company: String, + exp: usize, } fn main() { let my_claims = Claims { sub: "b@b.com".to_owned(), - company: "ACME".to_owned() + company: "ACME".to_owned(), + exp: 10000000000, }; let key = "secret"; diff --git a/examples/validation.rs b/examples/validation.rs index fcdd841..987cdbe 100644 --- a/examples/validation.rs +++ b/examples/validation.rs @@ -9,13 +9,15 @@ use jwt::errors::{ErrorKind}; #[derive(Debug, Serialize, Deserialize)] struct Claims { sub: String, - company: String + company: String, + exp: usize, } fn main() { let my_claims = Claims { sub: "b@b.com".to_owned(), - company: "ACME".to_owned() + company: "ACME".to_owned(), + exp: 10000000000, }; let key = "secret"; let token = match encode(&Header::default(), &my_claims, key.as_ref()) { @@ -27,13 +29,12 @@ fn main() { sub: Some("b@b.com".to_string()), ..Validation::default() }; - let token_data = match decode::(&token, key.as_ref(), &validation) { Ok(c) => c, Err(err) => match *err.kind() { - ErrorKind::InvalidToken => panic!(), // Example on how to handle a specific error - ErrorKind::InvalidIssuer => panic!(), // Example on how to handle a specific error - _ => panic!() + ErrorKind::InvalidToken => panic!("Token is invalid"), // Example on how to handle a specific error + ErrorKind::InvalidIssuer => panic!("Issuer is invalid"), // Example on how to handle a specific error + _ => panic!("Some other errors") } }; println!("{:?}", token_data.claims);