Skip to content

Commit

Permalink
Derive Clone for SymmetricKey, AsymmetricSecretKey and `Asymmet…
Browse files Browse the repository at this point in the history
…ricKeyPair` (#81)

* v0.6.5

* nit

* nit
  • Loading branch information
brycx authored Dec 14, 2022
1 parent 1e6e231 commit 9a6b330
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
edition = "2018"
description = "PASETO: Platform-Agnostic Security Tokens (in Rust)"
Expand Down
4 changes: 3 additions & 1 deletion src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub trait Generate<T, V: Version> {
fn generate() -> Result<T, Error>;
}

#[derive(Clone)]
/// A symmetric key used for `.local` tokens, given a version `V`.
pub struct SymmetricKey<V> {
pub(crate) bytes: Vec<u8>,
Expand Down Expand Up @@ -53,6 +54,7 @@ impl<V: Version> PartialEq<SymmetricKey<V>> for SymmetricKey<V> {
}
}

#[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.
Expand Down Expand Up @@ -132,7 +134,7 @@ impl<V: Version> PartialEq<AsymmetricPublicKey<V>> for AsymmetricPublicKey<V> {
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
/// A keypair of an [`AsymmetricSecretKey`] and its corresponding [`AsymmetricPublicKey`].
pub struct AsymmetricKeyPair<V> {
/// The [`AsymmetricSecretKey`].
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 10 additions & 0 deletions src/version2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,4 +815,14 @@ mod test_keys {
let random2 = AsymmetricKeyPair::<V2>::generate().unwrap();
assert_ne!(random1.secret, random2.secret);
}

#[test]
fn test_clone() {
let sk = SymmetricKey::<V2>::generate().unwrap();
assert_eq!(sk, sk.clone());

let kp = AsymmetricKeyPair::<V2>::generate().unwrap();
assert_eq!(kp.secret, kp.secret.clone());
assert_eq!(kp.public, kp.public.clone());
}
}
7 changes: 7 additions & 0 deletions src/version3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<V3>::generate().unwrap();
assert_eq!(kp.secret, kp.secret.clone());
assert_eq!(kp.public, kp.public.clone());
}
}
10 changes: 10 additions & 0 deletions src/version4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,4 +970,14 @@ mod test_keys {
let random2 = AsymmetricKeyPair::<V4>::generate().unwrap();
assert_ne!(random1.secret, random2.secret);
}

#[test]
fn test_clone() {
let sk = SymmetricKey::<V4>::generate().unwrap();
assert_eq!(sk, sk.clone());

let kp = AsymmetricKeyPair::<V4>::generate().unwrap();
assert_eq!(kp.secret, kp.secret.clone());
assert_eq!(kp.public, kp.public.clone());
}
}

0 comments on commit 9a6b330

Please sign in to comment.