Use a better name for the connection encryption cipher #32

Merged
tipragot merged 1 commit from fix-name into main 2024-02-09 23:00:43 +00:00

View file

@ -74,8 +74,8 @@ pub struct Connection {
/// The buffer used to receive a byte block. /// The buffer used to receive a byte block.
receive_buffer: Vec<u8>, receive_buffer: Vec<u8>,
/// The secret key used for encryption. /// The cipher used for encryption and decryption.
secret_key: Aes128Gcm, cipher: Aes128Gcm,
} }
impl Connection { impl Connection {
@ -89,7 +89,7 @@ impl Connection {
receive_message_nonce: None, receive_message_nonce: None,
receive_filled_len: 0, receive_filled_len: 0,
receive_buffer: Vec::new(), receive_buffer: Vec::new(),
secret_key: Aes128Gcm::new(secret_key), cipher: Aes128Gcm::new(secret_key),
}) })
} }
@ -130,7 +130,7 @@ impl Connection {
pub fn send(&mut self, message: &[u8]) -> io::Result<bool> { pub fn send(&mut self, message: &[u8]) -> io::Result<bool> {
// Encrypt the message. // Encrypt the message.
let nonce = Aes128Gcm::generate_nonce(OsRng); let nonce = Aes128Gcm::generate_nonce(OsRng);
let message = self.secret_key.encrypt(&nonce, message).map_err(|e| { let message = self.cipher.encrypt(&nonce, message).map_err(|e| {
io::Error::new( io::Error::new(
io::ErrorKind::InvalidData, io::ErrorKind::InvalidData,
format!("failed to encrypt message: {}", e), format!("failed to encrypt message: {}", e),
@ -286,7 +286,7 @@ impl Connection {
// Decrypting the message. // Decrypting the message.
let message = self let message = self
.secret_key .cipher
.decrypt(Nonce::from_slice(nonce), message) .decrypt(Nonce::from_slice(nonce), message)
.map_err(|e| { .map_err(|e| {
io::Error::new( io::Error::new(