use Cipher struct in `decrypt` method

This commit is contained in:
Vadim Anufriev 2024-06-13 16:17:08 +04:00
parent 3c67b978a2
commit bf5d1cdb48
1 changed files with 3 additions and 9 deletions

View File

@ -268,11 +268,11 @@ impl SecretKey {
Ok(Cipher(encrypted_data))
}
/// Decrypts the given encrypted data.
/// Decrypts the given encrypted data, encapsulated in a Cipher wrapper.
/// Extracts the nonce from the data and uses it for decryption.
/// Returns the decrypted Vec<u8>.
pub fn decrypt<T: AsRef<[u8]>>(&self, encrypted: T) -> Result<Vec<u8>, Error> {
let encrypted = encrypted.as_ref();
pub fn decrypt(&self, encrypted: &Cipher) -> Result<Vec<u8>, Error> {
let encrypted = encrypted.as_bytes();
// Check if the length of decoded data is at least the length of the nonce
let nonce_len = <XChaCha20Poly1305 as AeadCore>::NonceSize::USIZE;
@ -433,9 +433,3 @@ impl fmt::Display for Cipher {
write!(f, "{}", self.to_base64())
}
}
impl AsRef<[u8]> for Cipher {
fn as_ref(&self) -> &[u8] {
self.as_bytes()
}
}