Struct mini_functions::jwt::JWT
source · pub struct JWT {
pub header: Header,
pub claims: Claims,
pub signature: Vec<u8>,
pub token: String,
}
Expand description
JWT is a struct that holds the JWT token and its associated claims. Provides a set of utility functions for working with JSON Web Tokens (JWTs) and JSON Web Signatures (JWSs).
Fields§
§header: Header
The header of the JWT.
claims: Claims
The claims associated with the JWT.
signature: Vec<u8>
The signature of the JWT.
token: String
The JWT token.
Implementations§
source§impl JWT
impl JWT
sourcepub fn decode(&mut self, secret: &[u8]) -> Result<String, JwtError>
pub fn decode(&mut self, secret: &[u8]) -> Result<String, JwtError>
Decodes a JWT token. takes a mutable reference to a JWT struct and a reference to a slice of bytes representing a secret, and it returns a Result containing a string or an Error variant. The function splits the JWT stored in the token field of the JWT struct into its header, claims, and signature, decodes the header and claims from base64, deserializes the header and claims from JSON, and then verifies the JWT’s signature using the provided secret.
Arguments
secret
- A byte array containing the secret used to sign the JWT.
Returns
Ok(String)
- The decoded JWT as a string.Err(Error)
- An error if the JWT is invalid or if there was a problem decoding it.
sourcepub fn encode(
header: Header,
claims: Claims,
secret: &[u8]
) -> Result<String, JwtError>
pub fn encode( header: Header, claims: Claims, secret: &[u8] ) -> Result<String, JwtError>
Encodes a JWT token using the provided header, claims, and secret. It returns a Result containing a string or an Error variant. The function serializes the header and claims to JSON, base64-encodes the header and claims, concatenates the encoded header, claims, and separators, and then signs the JWT with the provided secret.
sourcepub fn get_token_header(jwt: JWT) -> Header
pub fn get_token_header(jwt: JWT) -> Header
Returns the header field of the JWT struct.
sourcepub fn get_token_length(jwt: JWT) -> usize
pub fn get_token_length(jwt: JWT) -> usize
Get the token length.
Trait Implementations§
source§impl<'de> Deserialize<'de> for JWT
impl<'de> Deserialize<'de> for JWT
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<JWT, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<JWT, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl Serialize for JWT
impl Serialize for JWT
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 JWT
impl Send for JWT
impl Sync for JWT
impl Unpin for JWT
impl UnwindSafe for JWT
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()
.