Compare commits
36 Commits
ee9fd437c7
...
master
Author | SHA1 | Date | |
---|---|---|---|
c394d29fee | |||
9711754ff3 | |||
240dfcc091 | |||
3e8099a2b9 | |||
dfb2b622b8 | |||
8fcbd84aa9 | |||
762767b13f | |||
e5c75e6b3c | |||
c5a2c2977d | |||
69728f2911 | |||
c36fe85900 | |||
0adf15991e | |||
1733737bfe | |||
6c1ba8cadf | |||
09ac30d9d3 | |||
666e4df395 | |||
b4cd0dbd22 | |||
8275ad1c6d | |||
862f9748f7 | |||
2271a899c1 | |||
f252eb7ecc | |||
332b3f3968 | |||
2b5f10783d | |||
359a90294b | |||
f164450a21 | |||
fab3b76b9a | |||
188a272678 | |||
ca287dcfe4 | |||
47c9c1e90c | |||
b22a8ffbb8 | |||
9e99a5df9e | |||
2684b685ab | |||
18f73bef28 | |||
80a6772117 | |||
490e1c0aac | |||
d02ddf8c82 |
1014
Cargo.lock
generated
1014
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "light-openid"
|
name = "light-openid"
|
||||||
version = "1.0.2"
|
version = "1.0.4"
|
||||||
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>"]
|
||||||
@ -12,7 +12,7 @@ license = "GPL-2.0-or-later"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.21"
|
log = "0.4.21"
|
||||||
reqwest = { version = "0.12.3", features = ["json"] }
|
reqwest = { version = "0.12.14", features = ["json"] }
|
||||||
base64 = "0.22.0"
|
base64 = "0.22.0"
|
||||||
serde = { version = "1.0.198", features = ["derive"] }
|
serde = { version = "1.0.198", features = ["derive"] }
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.115"
|
||||||
@ -21,7 +21,7 @@ urlencoding = "2.1.3"
|
|||||||
# Dependencies for crypto wrapper
|
# Dependencies for crypto wrapper
|
||||||
bincode = { version = "2.0.0-rc.3", optional = true }
|
bincode = { version = "2.0.0-rc.3", optional = true }
|
||||||
aes-gcm = { version = "0.10.3", optional = true }
|
aes-gcm = { version = "0.10.3", optional = true }
|
||||||
rand = { version = "0.8.5", optional = true }
|
rand = { version = "0.9.0", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
crypto-wrapper = ["bincode", "aes-gcm", "rand"]
|
crypto-wrapper = ["bincode", "aes-gcm", "rand"]
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
"packageRules": [
|
"extends": [
|
||||||
{
|
":automergeAll",
|
||||||
"matchUpdateTypes": ["major", "minor", "patch"],
|
":enableVulnerabilityAlerts",
|
||||||
"automerge": true
|
":ignoreUnstable"
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -1,12 +1,10 @@
|
|||||||
use std::error::Error;
|
|
||||||
use std::io::ErrorKind;
|
|
||||||
|
|
||||||
use aes_gcm::aead::{Aead, OsRng};
|
use aes_gcm::aead::{Aead, OsRng};
|
||||||
use aes_gcm::{Aes256Gcm, Key, KeyInit, Nonce};
|
use aes_gcm::{Aes256Gcm, Key, KeyInit, Nonce};
|
||||||
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
|
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
|
||||||
use base64::Engine as _;
|
use base64::Engine as _;
|
||||||
use bincode::{Decode, Encode};
|
use bincode::{Decode, Encode};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
/// The lenght of the nonce used to initialize encryption
|
/// The lenght of the nonce used to initialize encryption
|
||||||
const NONCE_LEN: usize = 12;
|
const NONCE_LEN: usize = 12;
|
||||||
@ -26,9 +24,9 @@ impl CryptoWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Encrypt some data, returning the result as a base64-encoded string
|
/// 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::rng().random::<[u8; NONCE_LEN]>();
|
||||||
|
|
||||||
let serialized_data = bincode::encode_to_vec(data, bincode::config::standard())?;
|
let serialized_data = bincode::encode_to_vec(data, bincode::config::standard())?;
|
||||||
|
|
||||||
@ -41,12 +39,11 @@ impl CryptoWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Decrypt some data previously encrypted using the [`CryptoWrapper::encrypt`] method
|
/// Decrypt some data previously encrypted using the [`CryptoWrapper::encrypt`] method
|
||||||
pub fn decrypt<T: Decode>(&self, input: &str) -> Result<T, Box<dyn Error>> {
|
pub fn decrypt<T: Decode<()>>(&self, input: &str) -> Result<T, Box<dyn Error>> {
|
||||||
let bytes = BASE64_STANDARD.decode(input)?;
|
let bytes = BASE64_STANDARD.decode(input)?;
|
||||||
|
|
||||||
if bytes.len() < NONCE_LEN {
|
if bytes.len() < NONCE_LEN {
|
||||||
return Err(Box::new(std::io::Error::new(
|
return Err(Box::new(std::io::Error::other(
|
||||||
ErrorKind::Other,
|
|
||||||
"Input string is smaller than nonce!",
|
"Input string is smaller than nonce!",
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -60,8 +57,7 @@ impl CryptoWrapper {
|
|||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Failed to decrypt wrapped data! {:#?}", e);
|
log::error!("Failed to decrypt wrapped data! {:#?}", e);
|
||||||
return Err(Box::new(std::io::Error::new(
|
return Err(Box::new(std::io::Error::other(
|
||||||
ErrorKind::Other,
|
|
||||||
"Failed to decrypt wrapped data!",
|
"Failed to decrypt wrapped data!",
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user