use crate::v2::crypto::XChaCha20Poly1305;
pub struct Cipher {
cipher: XChaCha20Poly1305,
}
impl Cipher {
pub fn new(key: &[u8]) -> Cipher {
debug_assert_eq!(key.len(), XChaCha20Poly1305::key_size());
Cipher {
cipher: XChaCha20Poly1305::new(key),
}
}
pub fn nonce_size() -> usize {
XChaCha20Poly1305::nonce_size()
}
pub fn encrypt_packet(&self, salt: &[u8], plaintext_in_ciphertext_out: &mut [u8]) {
self.cipher.encrypt(salt, plaintext_in_ciphertext_out);
}
pub fn decrypt_packet(&self, salt: &[u8], ciphertext_in_plaintext_out: &mut [u8]) -> bool {
self.cipher.decrypt(salt, ciphertext_in_plaintext_out)
}
}