From fdc0032109a175c6c9e106853c160e8e7138a0de Mon Sep 17 00:00:00 2001 From: Aarav Shah <110741219+Deaths-Door@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:56:48 +0200 Subject: [PATCH] Derive `Clone` for `MiniCocoon` (#32) Solves the issue #29 --- src/mini.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/mini.rs b/src/mini.rs index 23cdd4c..d049a18 100644 --- a/src/mini.rs +++ b/src/mini.rs @@ -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, @@ -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]);