Skip to content

Commit

Permalink
Derive Clone for MiniCocoon
Browse files Browse the repository at this point in the history
  • Loading branch information
Deaths-Door committed Sep 1, 2024
1 parent 9240ecc commit 85c2a7a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/mini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::{
pub const MINI_PREFIX_SIZE: usize = MiniFormatPrefix::SERIALIZE_SIZE;

/// This is a mini cocoon for a convenient and cool encryption.
#[derive(Clone)]
pub struct MiniCocoon {
key: Zeroizing<[u8; KEY_SIZE]>,
rng: StdRng,
Expand Down Expand Up @@ -449,6 +450,21 @@ mod test {
MiniCocoon::from_key(&[1; 32], &[0; 32]);
}

#[test]
fn mini_cocoon_clone() {
let mut cocoon = MiniCocoon::from_password(b"password", &[0; 32]);
let cloned_cocoon = cocoon.clone();
const DATA : &'static [u8]= b"my-sercet-data";

// To check whether MiniCocoon gets cloned properly
let wrapped = cocoon.wrap(DATA).unwrap();
drop(cocoon);

let unwrapped = cloned_cocoon.unwrap(&wrapped).unwrap();
assert_eq!(&unwrapped,DATA);
}


#[test]
fn mini_cocoon_encrypt() {
let mut cocoon = MiniCocoon::from_password(b"password", &[0; 32]);
Expand Down

0 comments on commit 85c2a7a

Please sign in to comment.