Develop first version #1
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -478,7 +478,7 @@ checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "light-openid"
 | 
			
		||||
version = "0.1.0-alpha"
 | 
			
		||||
version = "0.2.0-alpha"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "aes-gcm",
 | 
			
		||||
 "base64",
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "light-openid"
 | 
			
		||||
version = "0.1.0-alpha"
 | 
			
		||||
version = "0.2.0-alpha"
 | 
			
		||||
edition = "2021"
 | 
			
		||||
repository = "https://gitea.communiquons.org/pierre/light-openid"
 | 
			
		||||
authors = ["Pierre HUBERT <pierre.git@communiquons.org>"]
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,11 @@ use base64::Engine as _;
 | 
			
		||||
pub use bincode::{Decode, Encode};
 | 
			
		||||
use rand::Rng;
 | 
			
		||||
 | 
			
		||||
/// The lenght of the nonce used to initialize encryption
 | 
			
		||||
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 {
 | 
			
		||||
    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>> {
 | 
			
		||||
        let aes_key = Aes256Gcm::new(&self.key);
 | 
			
		||||
        let nonce_bytes = rand::thread_rng().gen::<[u8; NONCE_LEN]>();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user