diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2024-04-17 17:59:52 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-05-07 09:10:32 +0200 |
commit | a647f7a8e6e43071b1c62e5fe9fa10e3d439120b (patch) | |
tree | f7420f331cc7e7e2c502278a27949558b79c6d87 | |
parent | 9f6086273f6882d19a010efd228bb12387c686f4 (diff) |
openpgp: Add Key::steal_secret for public and unknown keys.
- This is a variant of Key::take_secret that doesn't change the type
and only requires a mutable reference.
-rw-r--r-- | openpgp/NEWS | 4 | ||||
-rw-r--r-- | openpgp/src/packet/key.rs | 6 | ||||
-rw-r--r-- | openpgp/src/packet/mod.rs | 8 |
3 files changed, 18 insertions, 0 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS index da2b53b3..f40537a3 100644 --- a/openpgp/NEWS +++ b/openpgp/NEWS @@ -6,6 +6,10 @@ * Changes in 1.21.0 ** New functionality + - Key::<PublicParts, _>::steal_secret + - Key::<UnknownParts, _>::steal_secret + - Key4::<PublicParts, _>::steal_secret + - Key4::<UnknownParts, _>::steal_secret - The RustCrypto backend now supports ECDH and ECDSA over the NIST curve P-384. - The RustCrypto backend now supports ECDH and ECDSA over the NIST diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index f7287f5d..112c2fa3 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -1479,6 +1479,12 @@ macro_rules! impl_common_secret_functions { let old = std::mem::replace(&mut self.secret, Some(secret)); (self.parts_into_secret().expect("secret just set"), old) } + + /// Takes the `Key`'s `SecretKeyMaterial`, if any. + pub fn steal_secret(&mut self) -> Option<SecretKeyMaterial> + { + std::mem::replace(&mut self.secret, None) + } } } } diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index 68058053..bbb8b1e4 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -1866,6 +1866,14 @@ macro_rules! impl_common_secret_functions { }, } } + + /// Takes the key packet's `SecretKeyMaterial`, if any. + pub fn steal_secret(&mut self) -> Option<key::SecretKeyMaterial> + { + match self { + Key::V4(k) => k.steal_secret(), + } + } } } } |