apparently the gen_or_get_key logic is for string only keys

changed that and also added an implementation for the trait
This commit is contained in:
2026-07-13 19:19:29 -05:00
parent 6a8abec015
commit 29033259df
5 changed files with 39 additions and 25 deletions
+9 -1
View File
@@ -9,7 +9,7 @@ pub type Key = chacha20poly1305::Key;
pub type Nonce = chacha20poly1305::Nonce;
pub mod helper {
use super::{Generate, Key, Nonce};
use super::{Generate, Key, Nonce, Result};
pub fn gen_nonce() -> Nonce {
Nonce::generate()
}
@@ -17,6 +17,14 @@ pub mod helper {
pub fn gen_key() -> Key {
Key::generate()
}
pub fn key_from(bytes: Vec<u8>) -> Result<Key> {
let array: [u8; 32] = bytes
.try_into()
.map_err(|_| "key must be exactly 32 bytes".to_string())?;
Ok(Key::from(array))
}
}
pub fn encrypt(key: &Key, plaintext: Vec<u8>) -> Result<(Nonce, Vec<u8>)> {