From 56db45cbad0336feac695f351f0707947575649e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sun, 24 Mar 2024 10:59:48 +0100 Subject: [PATCH] Add comments --- src/scheme/xchacha20poly1305.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/scheme/xchacha20poly1305.rs b/src/scheme/xchacha20poly1305.rs index 45329cc..aa4f56d 100644 --- a/src/scheme/xchacha20poly1305.rs +++ b/src/scheme/xchacha20poly1305.rs @@ -42,12 +42,17 @@ pub(crate) fn xchacha20poly1305_decrypt( encrypted_data: &EncryptedData, aad: &str, ) -> Result> { + // Adapt the key and nonce let key = Key::from_slice(key); let nonce = XNonce::from_slice(&encrypted_data.nonce); + + // Prepare the payload let payload = Payload { msg: &encrypted_data.ciphertext, aad: aad.as_bytes(), }; + + // Decrypt the payload and return let cipher = XChaCha20Poly1305::new(key); Ok(cipher.decrypt(nonce, payload)?) }