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 Freeze for Claims
impl RefUnwindSafe for Claims
impl Send for Claims
impl Sync for Claims
impl Unpin for Claims
impl UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FromBase64 for Twhere
T: for<'de> Deserialize<'de>,
impl<T> FromBase64 for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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().