## Jws

# Enum Jws

    pub enum Jws<T, H> {
        Decoded {
            header: Header<H>,
            payload: T,
        },
        Encoded(Compact),
    }

Expand description

Compact representation of a JWS

This representation contains a payload (type `T`) (e.g. a claims set) and is (optionally) signed. This is the most common form of tokens used. The JWS can contain additional header fields provided by type `H`.

Serialization/deserialization is handled by serde. Before you transport the token, make sure you turn it into the encoded form first.

## §Examples

### §Signing and verifying a JWT with HS256

See an example in the `biscuit::JWT` type alias.

## Variants§

§

### Decoded

Decoded form of the JWS. This variant cannot be serialized or deserialized and will return an error.

#### Fields

§`header: Header<H>`

Embedded header

§`payload: T`

Payload, usually a claims set

§

### Encoded(Compact)

Encoded and (optionally) signed JWT. Use this form to send to your clients

## Implementations§

§

### impl<T, H> Compact<T, H>
where T: CompactPart, H: Serialize + DeserializeOwned,

#### pub fn new_decoded(header: Header<H>, payload: T) -> Compact<T, H>

New decoded JWT

#### pub fn new_encoded(token: &str) -> Compact<T, H>

New encoded JWT

#### pub fn into_encoded(self, secret: &Secret) -> Result<Compact<T, H>, Error>

Consumes self and convert into encoded form. If the token is already encoded, this is a no-op.

#### pub fn encode(&self, secret: &Secret) -> Result<Compact<T, H>, Error>

Encode the JWT passed and sign the payload using the algorithm from the header and the secret The secret is dependent on the signing algorithm

#### pub fn into_decoded( self, secret: &Secret, algorithm: SignatureAlgorithm, ) -> Result<Compact<T, H>, Error>

Consumes self and convert into decoded form, verifying the signature, if any. If the token is already decoded, this is a no-op

#### pub fn decode( &self, secret: &Secret, algorithm: SignatureAlgorithm, ) -> Result<Compact<T, H>, Error>

Decode a token into the JWT struct and verify its signature using the concrete Secret If the token or its signature is invalid, it will return an error

#### pub fn decode_with_jwks<J>( &self, jwks: &JWKSet<J>, expected_algorithm: Option<SignatureAlgorithm>, ) -> Result<Compact<T, H>, Error>

Decode a token into the JWT struct and verify its signature using a JWKS

If the JWK does not contain an optional algorithm parameter, you will have to specify the expected algorithm or an error will be returned.

If the JWK specifies an algorithm and you provide an expected algorithm, both will be checked for equality. If they do not match, an error will be returned.

If the token or its signature is invalid, it will return an error

#### pub fn decode_with_jwks_ignore_kid<J>( &self, jwks: &JWKSet<J>, ) -> Result<Compact<T, H>, Error>

Decode a token into the JWT struct and verify its signature using a JWKS, ignoring kid.

If the JWK does not contain an optional algorithm parameter, you will have to specify the expected algorithm or an error will be returned.

If the JWK specifies an algorithm and you provide an expected algorithm, both will be checked for equality. If they do not match, an error will be returned.

If the token or its signature is invalid, it will return an error

#### pub fn encoded(&self) -> Result<&Compact, Error>

Convenience method to get a reference to the encoded string from an encoded compact JWS

#### pub fn encoded_mut(&mut self) -> Result<&mut Compact, Error>

Convenience method to get a mutable reference to the encoded string from an encoded compact JWS

#### pub fn payload(&self) -> Result<&T, Error>

Convenience method to get a reference to the claims set from a decoded compact JWS

#### pub fn payload_mut(&mut self) -> Result<&mut T, Error>

Convenience method to get a reference to the claims set from a decoded compact JWS

#### pub fn header(&self) -> Result<&Header<H>, Error>

Convenience method to get a reference to the header from a decoded compact JWS

#### pub fn header_mut(&mut self) -> Result<&mut Header<H>, Error>

Convenience method to get a reference to the header from a decoded compact JWS

#### pub fn unwrap_decoded(self) -> (Header<H>, T)

Consumes self, and move the payload and header out and return them as a tuple

##### §Panics

Panics if the JWS is not decoded

#### pub fn unwrap_encoded(self) -> Compact

Consumes self, and move the encoded Compact out and return it

##### §Panics

Panics if the JWS is not encoded

#### pub fn unverified_header(&self) -> Result<Header<H>, Error>

Without decoding and verifying the JWS, retrieve a copy of the header.

###### §Warning

Use this at your own risk. It is not advisable to trust unverified content.

#### pub fn unverified_payload(&self) -> Result<T, Error>

Without decoding and verifying the JWS, retrieve a copy of the payload.

###### §Warning

Use this at your own risk. It is not advisable to trust unverified content.

#### pub fn signature(&self) -> Result<Vec<u8>, Error>

Get a copy of the signature

§

### impl<P, H> Compact<ClaimsSet<P>, H>
where ClaimsSet<P>: CompactPart, H: Serialize + DeserializeOwned,

Convenience implementation for a Compact that contains a `ClaimsSet`

#### pub fn validate(&self, options: ValidationOptions) -> Result<(), Error>

Validate the temporal claims in the decoded token

If `None` is provided for options, the defaults will apply.

By default, no temporal claims (namely `iat`, `exp`, `nbf`) are required, and they will pass validation if they are missing.

## Trait Implementations§

§

### impl<T, H> Clone for Compact<T, H>
where T: Clone, H: Clone,

§

#### fn clone(&self) -> Compact<T, H>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from `source`. Read more
§

### impl<T, H> CompactPart for Compact<T, H>
where T: CompactPart, H: Serialize + DeserializeOwned,

Implementation for embedded inside a JWE.

§

#### fn to_bytes(&self) -> Result<Vec<u8>, Error>

Convert this part into bytes
§

#### fn from_bytes(bytes: &[u8]) -> Result<Compact<T, H>, Error>

Convert a sequence of bytes into Self
§

#### fn from_base64<B>(encoded: &B) -> Result<Self, Error>
where B: AsRef<[u8]>, Self: Sized,

Base64 decode into Self
§

#### fn to_base64(&self) -> Result<Base64Url, Error>

Serialize `Self` to some form and then base64URL Encode
§

### impl<T, H> Debug for Compact<T, H>
where T: Debug, H: Debug,

§

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

Formats the value using the given formatter. Read more
§

### impl<'de, T, H> Deserialize<'de> for Compact<T, H>

§

#### fn deserialize<__D>( __deserializer: __D, ) -> Result<Compact<T, H>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

### impl<T, H> PartialEq for Compact<T, H>
where T: PartialEq, H: PartialEq,

§

#### fn eq(&self, other: &Compact<T, H>) -> bool

Tests for `self` and `other` values to be equal, and is used by `==`.
1.0.0 · Source§

#### fn ne(&self, other: &Rhs) -> bool

Tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

### impl<T, H> Serialize for Compact<T, H>

§

#### 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
§

### impl<T, H> Eq for Compact<T, H>
where T: Eq, H: Eq,

§

### impl<T, H> StructuralPartialEq for Compact<T, H>

## Auto Trait Implementations§

§

### impl<T, H> Freeze for Compact<T, H>
where T: Freeze, H: Freeze,

§

### impl<T, H> RefUnwindSafe for Compact<T, H>
where T: RefUnwindSafe, H: RefUnwindSafe,

§

### impl<T, H> Send for Compact<T, H>
where T: Send, H: Send,

§

### impl<T, H> Sync for Compact<T, H>
where T: Sync, H: Sync,

§

### impl<T, H> Unpin for Compact<T, H>
where T: Unpin, H: Unpin,

§

### impl<T, H> UnwindSafe for Compact<T, H>
where T: UnwindSafe, H: UnwindSafe,

## 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> CloneToUninit for T
where T: Clone,

Source§

#### unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (`clone_to_uninit`)
Performs copy-assignment from `self` to `dest`. Read more
§

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

#### fn equivalent(&self, key: &K) -> bool

Compare self to `key` and return `true` if they are equal.
Source§

### impl<T> From<T> for T

Source§

#### fn from(t: T) -> T

Returns the argument unchanged.

§

### impl<T> Instrument for T

§

#### fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [`Span`], returning an `Instrumented` wrapper. Read more
§

#### fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current `Span`, returning an `Instrumented` wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

§

#### fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new `Policy` that returns [`Action::Follow`] only if `self` and `other` return `Action::Follow`. Read more
§

#### fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new `Policy` that returns [`Action::Follow`] if either `self` or `other` returns `Action::Follow`. Read more
§

### impl<T> ServiceExt for T

§

#### fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

#### fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

#### fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

#### fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the `Standard` policy. Read more
Source§

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

Source§

#### 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

#### 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>,

Source§

#### 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<T> WithSubscriber for T

§

#### fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided `Subscriber` to this type, returning a [`WithDispatch`] wrapper. Read more
§

#### fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default `Subscriber` to this type, returning a [`WithDispatch`] wrapper. Read more
Source§

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