diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e5b2de..72aaa87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### 0.6.5 + +__Date:__ December 14, 2022. + +__Changelog:__ +- `SymmetricKey`, `AsymmetricSecretKey` and `AsymmetricKeyPair` now implement `Clone`. + ### 0.6.4 __Date:__ November 17, 2022. diff --git a/Cargo.toml b/Cargo.toml index ac2632a..3bea7b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pasetors" -version = "0.6.4" # Update html_root_url in lib.rs along with this. +version = "0.6.5" # Update html_root_url in lib.rs along with this. authors = ["brycx "] edition = "2018" description = "PASETO: Platform-Agnostic Security Tokens (in Rust)" diff --git a/src/keys.rs b/src/keys.rs index 02699c2..3c5c9bb 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -10,6 +10,7 @@ pub trait Generate { fn generate() -> Result; } +#[derive(Clone)] /// A symmetric key used for `.local` tokens, given a version `V`. pub struct SymmetricKey { pub(crate) bytes: Vec, @@ -53,6 +54,7 @@ impl PartialEq> for SymmetricKey { } } +#[derive(Clone)] /// An asymmetric secret key used for `.public` tokens, given a version `V`. /// /// In case of Ed25519, which is used in V2 and V4, this is the seed concatenated with the public key. @@ -132,7 +134,7 @@ impl PartialEq> for AsymmetricPublicKey { } } -#[derive(Debug)] +#[derive(Debug, Clone)] /// A keypair of an [`AsymmetricSecretKey`] and its corresponding [`AsymmetricPublicKey`]. pub struct AsymmetricKeyPair { /// The [`AsymmetricSecretKey`]. diff --git a/src/lib.rs b/src/lib.rs index 58e69f0..a921e92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -183,7 +183,7 @@ unused_qualifications, overflowing_literals )] -#![doc(html_root_url = "https://docs.rs/pasetors/0.6.4")] +#![doc(html_root_url = "https://docs.rs/pasetors/0.6.5")] #![cfg_attr(docsrs, feature(doc_cfg))] #[macro_use] diff --git a/src/version2.rs b/src/version2.rs index 891e36d..f2a5c9a 100644 --- a/src/version2.rs +++ b/src/version2.rs @@ -815,4 +815,14 @@ mod test_keys { let random2 = AsymmetricKeyPair::::generate().unwrap(); assert_ne!(random1.secret, random2.secret); } + + #[test] + fn test_clone() { + let sk = SymmetricKey::::generate().unwrap(); + assert_eq!(sk, sk.clone()); + + let kp = AsymmetricKeyPair::::generate().unwrap(); + assert_eq!(kp.secret, kp.secret.clone()); + assert_eq!(kp.public, kp.public.clone()); + } } diff --git a/src/version3.rs b/src/version3.rs index acb28bb..5c84a68 100644 --- a/src/version3.rs +++ b/src/version3.rs @@ -807,4 +807,11 @@ mod test_keys { kpv3.public.bytes[0] = 0x04; assert!(UncompressedPublicKey::try_from(&kpv3.public).is_err()); } + + #[test] + fn test_clone() { + let kp = AsymmetricKeyPair::::generate().unwrap(); + assert_eq!(kp.secret, kp.secret.clone()); + assert_eq!(kp.public, kp.public.clone()); + } } diff --git a/src/version4.rs b/src/version4.rs index a36d926..858b4b9 100644 --- a/src/version4.rs +++ b/src/version4.rs @@ -970,4 +970,14 @@ mod test_keys { let random2 = AsymmetricKeyPair::::generate().unwrap(); assert_ne!(random1.secret, random2.secret); } + + #[test] + fn test_clone() { + let sk = SymmetricKey::::generate().unwrap(); + assert_eq!(sk, sk.clone()); + + let kp = AsymmetricKeyPair::::generate().unwrap(); + assert_eq!(kp.secret, kp.secret.clone()); + assert_eq!(kp.public, kp.public.clone()); + } }