fn aes_gcm_decrypt<T: Serialize + DeserializeOwned>(
    algorithm: &'static aead::Algorithm,
    encrypted: &EncryptionResult,
    key: &jwk::JWK<T>,
) -> Result<Vec<u8>, Error> {
    // JWA needs a 128 bit tag length. We need to assert that the algorithm has 128 bit tag length
    assert_eq!(algorithm.tag_len(), AES_GCM_TAG_SIZE);
    // Also the nonce (or initialization vector) needs to be 96 bits
    assert_eq!(algorithm.nonce_len(), AES_GCM_NONCE_LENGTH);

    let key = key.algorithm.octet_key()?;
    let key = aead::UnboundKey::new(algorithm, key)?;
    let opening_key = aead::LessSafeKey::new(key);

    let mut in_out = encrypted.encrypted.to_vec();
    in_out.append(&mut encrypted.tag.to_vec());

    let plaintext = opening_key.open_in_place(
        aead::Nonce::try_assume_unique_for_key(&encrypted.nonce)?,
        aead::Aad::from(&encrypted.additional_data),
        &mut in_out,
    )?;
    Ok(plaintext.to_vec())
}
/// Decrypts a payload with AES GCM
Decrypts a payload with AES GCM
Decrypts a payload with AES GCM
fn aes_gcm_decrypt<T: Serialize + DeserializeOwned>(
    algorithm: &'static aead::Algorithm,
    encrypted: &EncryptionResult,
    key: &jwk::JWK<T>,
) -> Result<Vec<u8>, Error> {
    // JWA needs a 128 bit tag length. We need to assert that the algorithm has 128 bit tag length
    assert_eq!(algorithm.tag_len(), AES_GCM_TAG_SIZE);
    // Also the nonce (or initialization vector) needs to be 96 bits
    assert_eq!(algorithm.nonce_len(), AES_GCM_NONCE_LENGTH);
    let key = key.algorithm.octet_key()?;
    let key = aead::UnboundKey::new(algorithm, key)?;
    let opening_key = aead::LessSafeKey::new(key);
    let mut in_out = encrypted.encrypted.to_vec();
    in_out.append(&mut encrypted.tag.to_vec());
    let plaintext = opening_key.open_in_place(
        aead::Nonce::try_assume_unique_for_key(&encrypted.nonce)?,
        aead::Aad::from(&encrypted.additional_data),
        &mut in_out,
    )?;
    Ok(plaintext.to_vec())
}
fn aes_gcm_decrypt < T : Serialize + DeserializeOwned > ( algorithm : & ' static aead :: Algorithm , encrypted : & EncryptionResult , key : & jwk :: JWK < T > , ) -> Result < Vec < u8 > , Error > { // JWA needs a 128 bit tag length. We need to assert that the algorithm has 128 bit tag length assert_eq ! ( algorithm tag_len ( ) AES_GCM_TAG_SIZE ) ; // Also the nonce (or initialization vector) needs to be 96 bits assert_eq ! ( algorithm nonce_len ( ) AES_GCM_NONCE_LENGTH ) ; let key = key . algorithm . octet_key ( ) ? ; let key = aead :: UnboundKey :: new ( algorithm , key ) ? ; let opening_key = aead :: LessSafeKey :: new ( key ) ; let mut in_out = encrypted . encrypted . to_vec ( ) ; in_out . append ( & mut encrypted . tag . to_vec ( ) ) ; let plaintext = opening_key . open_in_place ( aead :: Nonce :: try_assume_unique_for_key ( & encrypted . nonce ) ? , aead :: Aad :: from ( & encrypted . additional_data ) , & mut in_out , ) ? ; Ok ( plaintext . to_vec ( ) ) }
Decrypts a payload with AES GCM
Decrypts a payload with AES GCM
algorithm
&'static aead::Algorithm
encrypted
&EncryptionResult
key
&jwk::JWK<T>
algorithm
&'static aead::Algorithm
encrypted
&EncryptionResult
key
&jwk::JWK<T>