diff --git a/Cargo.toml b/Cargo.toml index 4cc1643..5c69a6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chacha20-poly1305-stream" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["Cesar Eduardo Barros ", "Hatter Jiang "] description = "A pure Rust implementation of the ChaCha20-Poly1305 AEAD from RFC 7539." diff --git a/src/stream_decryptor.rs b/src/stream_decryptor.rs index 985defc..dffe245 100644 --- a/src/stream_decryptor.rs +++ b/src/stream_decryptor.rs @@ -63,7 +63,7 @@ impl ChaCha20Poly1305StreamDecryptor { } /// Finalize decrypt - pub fn finalize(mut self) -> Result, String> { + pub fn finalize(&mut self) -> Result, String> { if self.message_buffer.len() < 16 { return Err("Bad tag length".to_string()); } @@ -84,7 +84,7 @@ impl ChaCha20Poly1305StreamDecryptor { let message_tag = &self.message_buffer[last_payload_len..]; self.poly1305.block([self.adata_len.to_le(), self.message_len.to_le()].as_bytes()); - let poly1305_tag = self.poly1305.tag(); + let poly1305_tag = self.poly1305.clone().tag(); let tag = poly1305_tag.as_bytes(); if message_tag != tag { Err(format!("Tag mismatch, expected: {}, actual: {}", diff --git a/src/stream_encryptor.rs b/src/stream_encryptor.rs index 991ecbe..b5b5892 100644 --- a/src/stream_encryptor.rs +++ b/src/stream_encryptor.rs @@ -62,7 +62,7 @@ impl ChaCha20Poly1305StreamEncryptor { } /// Finalize encrypt - pub fn finalize(mut self) -> (Vec, Vec) { + pub fn finalize(&mut self) -> (Vec, Vec) { let mut last_block = vec![]; if !self.message_buffer.is_empty() { let mut buf = [u32x4::default(); 4]; @@ -76,7 +76,7 @@ impl ChaCha20Poly1305StreamEncryptor { } self.poly1305.block([self.adata_len.to_le(), self.message_len.to_le()].as_bytes()); - let tag = self.poly1305.tag().as_bytes().to_vec(); + let tag = self.poly1305.clone().tag().as_bytes().to_vec(); (last_block, tag) }