[−][src]Enum oidc::token::Jws
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
Methods
impl<T, H> Compact<T, H> where
H: Serialize + DeserializeOwned,
T: CompactPart,
[src]
H: Serialize + DeserializeOwned,
T: CompactPart,
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 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>, 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<'de, T, H> Deserialize<'de> for Compact<T, H>
[src]
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
H: Eq,
T: Eq,
[src]
H: Eq,
T: Eq,
impl<T, H> CompactPart for Compact<T, H> where
H: DeserializeOwned + Serialize,
T: CompactPart,
[src]
H: DeserializeOwned + Serialize,
T: CompactPart,
Implementation for embedded inside a JWE.
fn to_bytes(&self) -> Result<Vec<u8>, Error>
[src]
fn from_bytes(bytes: &[u8]) -> Result<Compact<T, H>, Error>
[src]
fn from_base64<B>(encoded: &B) -> Result<Self, Error> where
B: AsRef<[u8]>,
[src]
B: AsRef<[u8]>,
fn to_base64(&self) -> Result<Base64Url, Error>
[src]
impl<T, H> Serialize for Compact<T, H>
[src]
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> Clone for Compact<T, H> where
H: Clone,
T: Clone,
[src]
H: Clone,
T: Clone,
impl<T, H> Debug for Compact<T, H> where
H: Debug,
T: Debug,
[src]
H: Debug,
T: Debug,
impl<T, H> PartialEq<Compact<T, H>> for Compact<T, H> where
H: PartialEq<H>,
T: PartialEq<T>,
[src]
H: PartialEq<H>,
T: PartialEq<T>,
Auto Trait Implementations
impl<T, H> Send for Compact<T, H> where
H: Send,
T: Send,
H: Send,
T: Send,
impl<T, H> Unpin for Compact<T, H> where
H: Unpin,
T: Unpin,
H: Unpin,
T: Unpin,
impl<T, H> Sync for Compact<T, H> where
H: Sync,
T: Sync,
H: Sync,
T: Sync,
impl<T, H> UnwindSafe for Compact<T, H> where
H: UnwindSafe,
T: UnwindSafe,
H: UnwindSafe,
T: UnwindSafe,
impl<T, H> RefUnwindSafe for Compact<T, H> where
H: RefUnwindSafe,
T: RefUnwindSafe,
H: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for 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.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: 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,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> CompactPart for T where
T: CompactJson,
[src]
T: CompactJson,
fn to_bytes(&self) -> Result<Vec<u8>, Error>
[src]
JSON serialize the part and return the JSON string bytes
fn from_bytes(bytes: &[u8]) -> Result<T, Error>
[src]
fn from_base64<B>(encoded: &B) -> Result<Self, Error> where
B: AsRef<[u8]>,
[src]
B: AsRef<[u8]>,
fn to_base64(&self) -> Result<Base64Url, Error>
[src]
impl<T> Erased for T
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,