From 3e5442cb8ee2add61c11d47949f9de7a11f771ed Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Sun, 25 Jul 2021 15:45:06 +0200 Subject: [PATCH] Update to PSEC v0.4 --- Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3aeab13..8d544f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-psec" -version = "0.3.2" +version = "0.4.0" authors = ["Hardcore Sushi "] edition = "2018" description = "Asynchronous PSEC implementation" diff --git a/README.md b/README.md index a1e45b2..cc120ca 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ async fn main() -> Result<(), PsecError> { To add this crate to your project, add the following to your project's Cargo.toml: ```toml [dependencies] -async-psec = "0.3" +async-psec = "0.4" ``` # Documentation diff --git a/src/lib.rs b/src/lib.rs index 096e464..7b853cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ Add this in your `Cargo.toml`: ```toml [dependencies] -async-psec = "0.3" +async-psec = "0.4" ``` And then: ```no_run @@ -36,7 +36,7 @@ async fn main() -> Result<(), PsecError> { If you want to split the [`Session`] struct in two parts, you must enable the `split` feature: ```toml [dependencies] -async-psec = { version = "0.3", feature = ["split"] } +async-psec = { version = "0.4", feature = ["split"] } ``` This can be useful if you want to send data from one thread/task and receive from another in parallel. */ @@ -169,7 +169,7 @@ fn unpad(input: Vec) -> Result, PsecError> { fn encrypt(local_cipher: &Aes128Gcm, local_iv: &[u8], local_counter: &mut usize, plain_text: &[u8], use_padding: bool) -> Vec { let padded_msg = pad(plain_text, use_padding); - let cipher_len = (padded_msg.len() as MessageLenType).to_be_bytes(); + let cipher_len = ((padded_msg.len() + AES_TAG_LEN) as MessageLenType).to_be_bytes(); let payload = Payload { msg: &padded_msg, aad: &cipher_len @@ -187,7 +187,7 @@ async fn encrypt_and_send(writer: &mut T, local_cipher async fn receive_and_decrypt(reader: &mut T, peer_cipher: &Aes128Gcm, peer_iv: &[u8], peer_counter: &mut usize, max_recv_size: Option) -> Result, PsecError> { let mut message_len = [0; MESSAGE_LEN_LEN]; receive(reader, &mut message_len).await?; - let recv_len = MessageLenType::from_be_bytes(message_len) as usize + AES_TAG_LEN; + let recv_len = MessageLenType::from_be_bytes(message_len) as usize; if let Some(max_recv_size) = max_recv_size { if recv_len > max_recv_size { return Err(PsecError::BufferTooLarge);