Added aes en/decryption slice->vec functions (sync+async)

Fix aes sync functions marked as async

Fortune for cryptohelpers's current commit: Future blessing − 末吉
tokio-1.0
Avril 3 years ago
parent 5ed7f1b652
commit 95447dce6f
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,6 +1,6 @@
[package]
name = "cryptohelpers"
version = "1.7.3"
version = "1.8.0"
license= "MIT"
description = "Collection of helpers and simplifying functions for cryptography things"
authors = ["Avril <flanchan@cumallover.me>"]

@ -187,7 +187,7 @@ where F: AsyncRead + Unpin + ?Sized,
}
/// Encrypt a stream into another using a key
pub async fn encrypt_stream_sync<F,T>(key: &AesKey, from: &mut F, to: &mut T) -> Result<usize, Error>
pub fn encrypt_stream_sync<F,T>(key: &AesKey, from: &mut F, to: &mut T) -> Result<usize, Error>
where F: io::Read + ?Sized,
T: io::Write + ?Sized
{
@ -234,7 +234,7 @@ where F: AsyncRead + Unpin + ?Sized,
}
/// Decrypt a stream into another using a key
pub async fn decrypt_stream_sync<F,T>(key: &AesKey, from: &mut F, to: &mut T) -> Result<usize, Error>
pub fn decrypt_stream_sync<F,T>(key: &AesKey, from: &mut F, to: &mut T) -> Result<usize, Error>
where F: io::Read + ?Sized,
T: io::Write + ?Sized
{
@ -256,6 +256,48 @@ where F: io::Read + ?Sized,
Ok(done + bytes_encrypted)
}
/// Decrypt a slice to a `Vec<u8>` async
#[cfg(feature="async")]
pub async fn decrypt_slice(key: &AesKey, from: impl AsRef<[u8]>) -> Result<Vec<u8>, Error>
{
let from = from.as_ref();
let mut to = Vec::with_capacity(from.len() + 128);
decrypt_stream(key, &mut &from[..], &mut to).await?;
Ok(to)
}
/// Decrypt a slice to a `Vec<u8>` sync
pub fn decrypt_slice_sync(key: &AesKey, from: impl AsRef<[u8]>) -> Result<Vec<u8>, Error>
{
let from = from.as_ref();
let mut to = Vec::with_capacity(from.len() + 128);
decrypt_stream_sync(key, &mut &from[..], &mut to)?;
Ok(to)
}
/// Encrypt a slice to a `Vec<u8>` async
#[cfg(feature="async")]
pub async fn encrypt_slice(key: &AesKey, from: impl AsRef<[u8]>) -> Result<Vec<u8>, Error>
{
let from = from.as_ref();
let mut to = Vec::with_capacity(from.len() + 128);
encrypt_stream(key, &mut &from[..], &mut to).await?;
Ok(to)
}
/// Encrypt a slice to a `Vec<u8>` sync
pub fn encrypt_slice_sync(key: &AesKey, from: impl AsRef<[u8]>) -> Result<Vec<u8>, Error>
{
let from = from.as_ref();
let mut to = Vec::with_capacity(from.len() + 128);
encrypt_stream_sync(key, &mut &from[..], &mut to)?;
Ok(to)
}
pub use crate::error::aes::Error;
#[cfg(test)]

Loading…
Cancel
Save