Bump version
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2023-04-28 19:50:00 +02:00
parent 1b62a887c8
commit 279adff4f3
3 changed files with 6 additions and 3 deletions

2
Cargo.lock generated
View File

@ -478,7 +478,7 @@ checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
[[package]] [[package]]
name = "light-openid" name = "light-openid"
version = "0.1.0-alpha" version = "0.2.0-alpha"
dependencies = [ dependencies = [
"aes-gcm", "aes-gcm",
"base64", "base64",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "light-openid" name = "light-openid"
version = "0.1.0-alpha" version = "0.2.0-alpha"
edition = "2021" edition = "2021"
repository = "https://gitea.communiquons.org/pierre/light-openid" repository = "https://gitea.communiquons.org/pierre/light-openid"
authors = ["Pierre HUBERT <pierre.git@communiquons.org>"] authors = ["Pierre HUBERT <pierre.git@communiquons.org>"]

View File

@ -8,8 +8,11 @@ use base64::Engine as _;
pub use bincode::{Decode, Encode}; pub use bincode::{Decode, Encode};
use rand::Rng; use rand::Rng;
/// The lenght of the nonce used to initialize encryption
const NONCE_LEN: usize = 12; const NONCE_LEN: usize = 12;
/// CryptoWrapper is a library that can be used to encrypt and decrypt some data marked
/// that derives [Encode] and [Decode] traits using AES encryption
pub struct CryptoWrapper { pub struct CryptoWrapper {
key: Key<Aes256Gcm>, key: Key<Aes256Gcm>,
} }
@ -22,7 +25,7 @@ impl CryptoWrapper {
} }
} }
/// Encrypt some data /// Encrypt some data, returning the result as a base64-encoded string
pub fn encrypt<T: Encode + Decode>(&self, data: &T) -> Result<String, Box<dyn Error>> { pub fn encrypt<T: Encode + Decode>(&self, data: &T) -> Result<String, Box<dyn Error>> {
let aes_key = Aes256Gcm::new(&self.key); let aes_key = Aes256Gcm::new(&self.key);
let nonce_bytes = rand::thread_rng().gen::<[u8; NONCE_LEN]>(); let nonce_bytes = rand::thread_rng().gen::<[u8; NONCE_LEN]>();