-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
6 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,38 +24,38 @@ | |
//! ```rust | ||
//! use hmac_serialiser::{Encoder, HmacSigner, KeyInfo, Payload, Algorithm}; | ||
//! use serde::{Serialize, Deserialize}; | ||
//! | ||
//! | ||
//! #[derive(Serialize, Deserialize, Debug)] | ||
//! struct UserData { | ||
//! // Add your data fields here | ||
//! username: String, | ||
//! email: String, | ||
//! } | ||
//! | ||
//! | ||
//! impl Payload for UserData { | ||
//! fn get_exp(&self) -> Option<chrono::DateTime<chrono::Utc>> { | ||
//! // Add logic to retrieve expiration time if needed | ||
//! None | ||
//! } | ||
//! } | ||
//! | ||
//! | ||
//! fn main() { | ||
//! // Define your secret key, salt, and optional info | ||
//! let key_info = KeyInfo { | ||
//! key: b"your_secret_key".to_vec(), | ||
//! salt: b"your_salt".to_vec(), | ||
//! info: vec![], // empty info | ||
//! }; | ||
//! | ||
//! | ||
//! // Initialize the HMAC signer | ||
//! let signer = HmacSigner::new(key_info, Algorithm::SHA256, Encoder::UrlSafeNoPadding); | ||
//! | ||
//! | ||
//! // Serialize your data | ||
//! let user_data = UserData { | ||
//! username: "user123".to_string(), | ||
//! email: "[email protected]".to_string(), | ||
//! }; | ||
//! | ||
//! | ||
//! // Sign the data (safe to use by clients) | ||
//! let token = signer.sign(&user_data); | ||
//! println!("Token: {}", token); | ||
|