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

source

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());
source

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")));
source

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")));
source

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()));
source

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());
source

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"));
source

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);
source

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());
source

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 Clone for Claims

source§

fn clone(&self) -> Claims

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Claims

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Claims

Implement the Default trait for Claims.

source§

fn default() -> Claims

Create a new instance of Claims.

source§

impl<'de> Deserialize<'de> for Claims

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<Claims, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Claims

Implement the Display trait for Claims.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Serialize for Claims

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromBase64 for T
where T: for<'de> Deserialize<'de>,

§

fn from_base64<Input>(raw: &Input) -> Result<T, Error>
where Input: AsRef<[u8]> + ?Sized,

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<C> SignWithKey<String> for C
where C: ToBase64,

§

fn sign_with_key(self, key: &impl SigningAlgorithm) -> Result<String, Error>

§

impl<T> ToBase64 for T
where T: Serialize,

§

fn to_base64(&self) -> Result<Cow<'_, str>, Error>

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,