Enum biscuit::jws::Compact
[−]
[src]
pub enum Compact<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
Methods
impl<T: CompactPart, H: Serialize + DeserializeOwned> Compact<T, H>
[src]
fn new_decoded(header: Header<H>, payload: T) -> Self
New decoded JWT
fn new_encoded(token: &str) -> Self
New encoded JWT
fn into_encoded(self, secret: &Secret) -> Result<Self, Error>
Consumes self and convert into encoded form. If the token is already encoded, this is a no-op.
fn encode(&self, secret: &Secret) -> Result<Self, 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
fn into_decoded(
self,
secret: &Secret,
algorithm: SignatureAlgorithm
) -> Result<Self, Error>
self,
secret: &Secret,
algorithm: SignatureAlgorithm
) -> Result<Self, Error>
Consumes self and convert into decoded form, verifying the signature, if any. If the token is already decoded, this is a no-op
fn decode(
&self,
secret: &Secret,
algorithm: SignatureAlgorithm
) -> Result<Self, Error>
&self,
secret: &Secret,
algorithm: SignatureAlgorithm
) -> Result<Self, 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
fn encoded(&self) -> Result<&Compact, Error>
Convenience method to get a reference to the encoded string from an encoded compact JWS
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
fn payload(&self) -> Result<&T, Error>
Convenience method to get a reference to the claims set from a decoded compact JWS
fn payload_mut(&mut self) -> Result<&mut T, Error>
Convenience method to get a reference to the claims set from a decoded compact JWS
fn header(&self) -> Result<&Header<H>, Error>
Convenience method to get a reference to the header from a decoded compact JWS
fn header_mut(&mut self) -> Result<&mut Header<H>, Error>
Convenience method to get a reference to the header from a decoded compact JWS
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
fn unwrap_encoded(self) -> Compact
Consumes self, and move the encoded Compact out and return it
Panics
Panics if the JWS is not encoded
Trait Implementations
impl<T: Clone, H: Clone> Clone for Compact<T, H>
[src]
fn clone(&self) -> Compact<T, H>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Debug, H: Debug> Debug for Compact<T, H>
[src]
impl<T: Eq, H: Eq> Eq for Compact<T, H>
[src]
impl<T: PartialEq, H: PartialEq> PartialEq for Compact<T, H>
[src]
fn eq(&self, __arg_0: &Compact<T, H>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Compact<T, H>) -> bool
This method tests for !=
.
impl<T: CompactPart, H: Serialize + DeserializeOwned> CompactPart for Compact<T, H>
[src]
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<Self, Error>
Convert a sequence of bytes into Self
fn from_base64<B: AsRef<[u8]>>(encoded: &B) -> Result<Self, Error> where
Self: Sized,
Self: Sized,
Base64 decode into Self
fn to_base64(&self) -> Result<Base64Url, Error>
Serialize Self
to some form and then base64URL Encode