Enum biscuit::jwe::Compact [] [src]

pub enum Compact<T, H> {
    Decrypted {
        header: Header<H>,
        payload: T,
    },
    Encrypted(Compact),
}

Compact representation of a JWE, or an encrypted JWT

This representation contains a payload of type T with custom headers provided by type H.

Examples

Encrypting a JWS/JWT

See the example code in the biscuit::JWE type alias.

Encrypting a string payload with A256GCMKW and A256GCM

extern crate biscuit;

use std::str;
use biscuit::Empty;
use biscuit::jwk::{JWK};
use biscuit::jwe;
use biscuit::jwa::{KeyManagementAlgorithm, ContentEncryptionAlgorithm};


let payload = "The true sign of intelligence is not knowledge but imagination.";
// You would usually have your own AES key for this, but we will use a zeroed key as an example
let key: JWK<Empty> = JWK::new_octect_key(&vec![0; 256/8], Default::default());

// Construct the JWE
let jwe = jwe::Compact::new_decrypted(From::from(jwe::RegisteredHeader {
                                                cek_algorithm: KeyManagementAlgorithm::A256GCMKW,
                                                enc_algorithm: ContentEncryptionAlgorithm::A256GCM,
                                                ..Default::default()
                                            }),
                                      payload.as_bytes().to_vec());

// Encrypt
let encrypted_jwe = jwe.encrypt(&key).unwrap();

// Decrypt
let decrypted_jwe = encrypted_jwe.decrypt(&key,
                                          KeyManagementAlgorithm::A256GCMKW,
                                          ContentEncryptionAlgorithm::A256GCM)
                                  .unwrap();

let decrypted_payload: &Vec<u8> = decrypted_jwe.payload().unwrap();
let decrypted_str = str::from_utf8(&*decrypted_payload).unwrap();
assert_eq!(decrypted_str, payload);

Variants

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

Fields of Decrypted

Embedded header

Payload, usually a signed/unsigned JWT

Encrypted JWT. Use this form to send to your clients

Methods

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

Create a new encrypted JWE

Create a new encrypted JWE

Consumes self and encrypt it. If the token is already encrypted, this is a no-op.

Encrypt an Decrypted JWE

Consumes self and decrypt it. If the token is already decrypted, this is a no-op.

Decrypt an encrypted JWE. Provide the expected algorithms to mitigate an attacker modifying the fields

Convenience method to get a reference to the encrypted payload

Convenience method to get a mutable reference to the encrypted payload

Convenience method to get a reference to the payload from an Decrypted JWE

Convenience method to get a mutable reference to the payload from an Decrypted JWE

Convenience method to get a reference to the header from an Decrypted JWE

Convenience method to get a reference to the header from an Decrypted JWE

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

Panics

Panics if the JWE is not decrypted

Consumes self, and move the encrypted Compact serialization out and return it

Panics

Panics if the JWE is not encrypted

Trait Implementations

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Formats the value using the given formatter.

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

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.