Struct mini_functions::claims::Claims
source · pub struct Claims {
pub claims: HashMap<String, String>,
}
Expand description
Re-exported Claims
struct from cclm for accessing JWT claims.
The Claims struct holds the claims of a JSON Web Token (JWT).
A JWT is a compact, URL-safe means of representing claims to be transferred between two parties. It consists of a header, a payload, and a signature. The payload is where the claims are stored.
The claims in a JWT are encoded as a JSON object and can be used to convey information such as the identity of an end user, the expiration time of the token, and more.
The Claims struct provides a convenient way to manipulate the claims of a JWT in Rust. It stores the claims as a HashMap<String, String>, allowing for fast and efficient access to each claim.
Fields§
§claims: HashMap<String, String>
The claims of the JWT as a HashMap.
Implementations§
source§impl Claims
impl Claims
sourcepub fn new() -> Claims
pub fn new() -> Claims
Creates a new instance of the Claims
struct with an empty
HashMap of claims.
Example
use self::cclm::Claims;
let claims = Claims::new();
assert!(claims.claims.is_empty());
sourcepub fn set_claim(&mut self, key: &str, value: &str)
pub fn set_claim(&mut self, key: &str, value: &str)
Adds or updates a claim in the Claims
struct with the given key and value.
Example
use self::cclm::Claims;
let mut claims = Claims::new();
claims.set_claim("sub", "1234567890");
assert_eq!(claims.get_claim("sub"), Some(&String::from("1234567890")));
sourcepub fn get_claim(&self, key: &str) -> Option<&String>
pub fn get_claim(&self, key: &str) -> Option<&String>
Gets a claim from the Claims
struct with the given key.
Returns None
if the key does not exist in the Claims
.
Example
use self::cclm::Claims;
let mut claims = Claims::new();
claims.set_claim("sub", "1234567890");
assert_eq!(claims.get_claim("sub"), Some(&String::from("1234567890")));
sourcepub fn remove_claim(&mut self, key: &str) -> Option<String>
pub fn remove_claim(&mut self, key: &str) -> Option<String>
Returns the value of the claim that was removed, if any.
Example
use self::cclm::Claims;
let mut claims = Claims::new();
claims.set_claim("sub", "1234567890");
assert_eq!(claims.remove_claim("sub"), Some("1234567890".to_owned()));
sourcepub fn clear_claims(&mut self)
pub fn clear_claims(&mut self)
Clears all claims from the Claims
struct.
Example
use self::cclm::Claims;
let mut claims = Claims::new();
claims.set_claim("sub", "1234567890");
claims.clear_claims();
assert!(claims.claims.is_empty());
sourcepub fn has_claim(&self, key: &str) -> bool
pub fn has_claim(&self, key: &str) -> bool
Checks if a claim with the given key exists in the Claims
struct.
Example
use self::cclm::Claims;
let mut claims = Claims::new();
claims.set_claim("sub", "1234567890");
assert!(claims.has_claim("sub"));
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the number of claims in the Claims
struct.
Example
use self::cclm::Claims;
let mut claims = Claims::new();
claims.set_claim("sub", "1234567890");
assert_eq!(claims.len(), 1);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the Claims
struct is empty.
Example
use self::cclm::Claims;
let mut claims = Claims::new();
assert!(claims.is_empty());
claims.set_claim("sub", "1234567890");
assert!(!claims.is_empty());
sourcepub fn get_claims(&self) -> &HashMap<String, String>
pub fn get_claims(&self) -> &HashMap<String, String>
Get a reference to the HashMap of claims in the Claims
struct.
This is useful if you need to iterate over the claims.
Example
use self::cclm::Claims;
let mut claims = Claims::new();
claims.set_claim("sub", "1234567890");
claims.set_claim("name", "John Doe");
for (key, value) in claims.get_claims() {
println!("{}: {}", key, value);
}
Trait Implementations§
source§impl<'de> Deserialize<'de> for Claims
impl<'de> Deserialize<'de> for Claims
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Claims, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Claims, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl Serialize for Claims
impl Serialize for Claims
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl RefUnwindSafe for Claims
impl Send for Claims
impl Sync for Claims
impl Unpin for Claims
impl UnwindSafe for Claims
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FromBase64 for Twhere
T: for<'de> Deserialize<'de>,
impl<T> FromBase64 for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.