Update to PSEC v0.4
This commit is contained in:
parent
eacd948236
commit
3e5442cb8e
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "async-psec"
|
name = "async-psec"
|
||||||
version = "0.3.2"
|
version = "0.4.0"
|
||||||
authors = ["Hardcore Sushi <hardcore.sushi@disroot.org>"]
|
authors = ["Hardcore Sushi <hardcore.sushi@disroot.org>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Asynchronous PSEC implementation"
|
description = "Asynchronous PSEC implementation"
|
||||||
|
@ -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:
|
To add this crate to your project, add the following to your project's Cargo.toml:
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-psec = "0.3"
|
async-psec = "0.4"
|
||||||
```
|
```
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
Add this in your `Cargo.toml`:
|
Add this in your `Cargo.toml`:
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-psec = "0.3"
|
async-psec = "0.4"
|
||||||
```
|
```
|
||||||
And then:
|
And then:
|
||||||
```no_run
|
```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:
|
If you want to split the [`Session`] struct in two parts, you must enable the `split` feature:
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[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.
|
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<u8>) -> Result<Vec<u8>, PsecError> {
|
|||||||
|
|
||||||
fn encrypt(local_cipher: &Aes128Gcm, local_iv: &[u8], local_counter: &mut usize, plain_text: &[u8], use_padding: bool) -> Vec<u8> {
|
fn encrypt(local_cipher: &Aes128Gcm, local_iv: &[u8], local_counter: &mut usize, plain_text: &[u8], use_padding: bool) -> Vec<u8> {
|
||||||
let padded_msg = pad(plain_text, use_padding);
|
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 {
|
let payload = Payload {
|
||||||
msg: &padded_msg,
|
msg: &padded_msg,
|
||||||
aad: &cipher_len
|
aad: &cipher_len
|
||||||
@ -187,7 +187,7 @@ async fn encrypt_and_send<T: AsyncWriteExt + Unpin>(writer: &mut T, local_cipher
|
|||||||
async fn receive_and_decrypt<T: AsyncReadExt + Unpin>(reader: &mut T, peer_cipher: &Aes128Gcm, peer_iv: &[u8], peer_counter: &mut usize, max_recv_size: Option<usize>) -> Result<Vec<u8>, PsecError> {
|
async fn receive_and_decrypt<T: AsyncReadExt + Unpin>(reader: &mut T, peer_cipher: &Aes128Gcm, peer_iv: &[u8], peer_counter: &mut usize, max_recv_size: Option<usize>) -> Result<Vec<u8>, PsecError> {
|
||||||
let mut message_len = [0; MESSAGE_LEN_LEN];
|
let mut message_len = [0; MESSAGE_LEN_LEN];
|
||||||
receive(reader, &mut message_len).await?;
|
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 let Some(max_recv_size) = max_recv_size {
|
||||||
if recv_len > max_recv_size {
|
if recv_len > max_recv_size {
|
||||||
return Err(PsecError::BufferTooLarge);
|
return Err(PsecError::BufferTooLarge);
|
||||||
|
Loading…
Reference in New Issue
Block a user