Enum openid::Jws[][src]

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

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 of Decoded

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
[src]

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

New decoded JWT

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

New encoded JWT

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

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>[src]

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>
[src]

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>
[src]

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>
[src]

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 encoded(&self) -> Result<&Compact, Error>[src]

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>[src]

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

pub fn payload(&self) -> Result<&T, Error>[src]

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>[src]

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

pub fn header(&self) -> Result<&Header<H>, Error>[src]

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>[src]

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

pub fn unwrap_decoded(self) -> (Header<H>, T)[src]

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[src]

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>[src]

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>[src]

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, Global>, Error>[src]

Get a copy of the signature

impl<P, H> Compact<ClaimsSet<P>, H> where
    H: Serialize + DeserializeOwned,
    ClaimsSet<P>: CompactPart
[src]

Convenience implementation for a Compact that contains a ClaimsSet

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

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
[src]

impl<T, H> CompactPart for Compact<T, H> where
    T: CompactPart,
    H: Serialize + DeserializeOwned
[src]

Implementation for embedded inside a JWE.

impl<T, H> Debug for Compact<T, H> where
    T: Debug,
    H: Debug
[src]

impl<'de, T, H> Deserialize<'de> for Compact<T, H>[src]

impl<T, H> Eq for Compact<T, H> where
    T: Eq,
    H: Eq
[src]

impl<T, H> PartialEq<Compact<T, H>> for Compact<T, H> where
    T: PartialEq<T>,
    H: PartialEq<H>, 
[src]

impl<T, H> Serialize for Compact<T, H>[src]

impl<T, H> StructuralEq for Compact<T, H>[src]

impl<T, H> StructuralPartialEq for Compact<T, H>[src]

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.