Skip to content

Commit

Permalink
Derive Clone for MiniCocoon (#32)
Browse files Browse the repository at this point in the history
Solves the issue #29
  • Loading branch information
Deaths-Door authored Sep 2, 2024
1 parent 9240ecc commit fdc0032
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 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,20 @@ 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 fdc0032

Please sign in to comment.