Enum openid::Jws [−][src]
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 form of the JWS. This variant cannot be serialized or deserialized and will return an error.
Fields of Decoded
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]
T: CompactPart,
H: Serialize + DeserializeOwned,
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]
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>
[src]
&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>
[src]
&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 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]
H: Serialize + DeserializeOwned,
ClaimsSet<P>: CompactPart,
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]
T: Clone,
H: Clone,
impl<T, H> CompactPart for Compact<T, H> where
T: CompactPart,
H: Serialize + DeserializeOwned,
[src]
T: CompactPart,
H: Serialize + DeserializeOwned,
Implementation for embedded inside a JWE.
pub fn to_bytes(&self) -> Result<Vec<u8, Global>, Error>
[src]
pub fn from_bytes(bytes: &[u8]) -> Result<Compact<T, H>, Error>
[src]
pub fn from_base64<B>(encoded: &B) -> Result<Self, Error> where
B: AsRef<[u8]>,
[src]
B: AsRef<[u8]>,
pub fn to_base64(&self) -> Result<Base64Url, Error>
[src]
impl<T, H> Debug for Compact<T, H> where
T: Debug,
H: Debug,
[src]
T: Debug,
H: Debug,
impl<'de, T, H> Deserialize<'de> for Compact<T, H>
[src]
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Compact<T, H>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]
__deserializer: __D
) -> Result<Compact<T, H>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
impl<T, H> Eq for Compact<T, H> where
T: Eq,
H: Eq,
[src]
T: Eq,
H: Eq,
impl<T, H> PartialEq<Compact<T, H>> for Compact<T, H> where
T: PartialEq<T>,
H: PartialEq<H>,
[src]
T: PartialEq<T>,
H: PartialEq<H>,
pub fn eq(&self, other: &Compact<T, H>) -> bool
[src]
pub fn ne(&self, other: &Compact<T, H>) -> bool
[src]
impl<T, H> Serialize for Compact<T, H>
[src]
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
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,
H: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, H> Send for Compact<T, H> where
H: Send,
T: Send,
H: Send,
T: Send,
impl<T, H> Sync for Compact<T, H> where
H: Sync,
T: Sync,
H: Sync,
T: Sync,
impl<T, H> Unpin for Compact<T, H> where
H: Unpin,
T: Unpin,
H: Unpin,
T: Unpin,
impl<T, H> UnwindSafe for Compact<T, H> where
H: UnwindSafe,
T: UnwindSafe,
H: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,