#[cfg(all(feature = "v2", feature = "easy_tokens"))] use {chrono::prelude::*, ed25519_dalek::Keypair, serde_json::json}; fn main() { #[cfg(all(feature = "v2", feature = "easy_tokens"))] { let current_date_time = Utc::now(); let dt = Utc.ymd(current_date_time.year() + 1, 7, 8).and_hms(9, 10, 11); let mut sys_rand = rand::rngs::OsRng {}; let as_key = Keypair::generate(&mut sys_rand); let key_bytes = as_key.to_bytes(); let cloned_key = Keypair::from_bytes(&key_bytes).unwrap(); let token = paseto::tokens::PasetoBuilder::new() .set_ed25519_key(as_key) .set_issued_at(None) .set_expiration(dt) .set_issuer(String::from("instructure")) .set_audience(String::from("wizards")) .set_jti(String::from("gandalf0")) .set_not_before(Utc::now()) .set_subject(String::from("gandalf")) .set_claim(String::from("go-to"), json!(String::from("mordor"))) .set_footer(String::from("key-id:gandalf0")) .build() .expect("Failed to construct paseto token w/ builder!"); println!("{:?}", token); let verified_token = paseto::tokens::validate_public_token( &token, Some("key-id:gandalf0"), &paseto::tokens::PasetoPublicKey::ED25519KeyPair(cloned_key), ) .expect("Failed to validate token!"); println!("{:?}", verified_token); } }