Add comments

This commit is contained in:
Rodolphe Bréard 2024-03-24 10:59:48 +01:00
parent ae19a16531
commit 56db45cbad

View file

@ -42,12 +42,17 @@ pub(crate) fn xchacha20poly1305_decrypt(
encrypted_data: &EncryptedData, encrypted_data: &EncryptedData,
aad: &str, aad: &str,
) -> Result<Vec<u8>> { ) -> Result<Vec<u8>> {
// Adapt the key and nonce
let key = Key::from_slice(key); let key = Key::from_slice(key);
let nonce = XNonce::from_slice(&encrypted_data.nonce); let nonce = XNonce::from_slice(&encrypted_data.nonce);
// Prepare the payload
let payload = Payload { let payload = Payload {
msg: &encrypted_data.ciphertext, msg: &encrypted_data.ciphertext,
aad: aad.as_bytes(), aad: aad.as_bytes(),
}; };
// Decrypt the payload and return
let cipher = XChaCha20Poly1305::new(key); let cipher = XChaCha20Poly1305::new(key);
Ok(cipher.decrypt(nonce, payload)?) Ok(cipher.decrypt(nonce, payload)?)
} }