From b3ca035d5bcb9146f0baadf7a682fe4828669b6c Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 16 Sep 2020 11:58:19 +0200 Subject: openpgp: Generalize ValidKeyAmalgamation conversions to references. --- openpgp/src/cert/amalgamation/key.rs | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'openpgp') diff --git a/openpgp/src/cert/amalgamation/key.rs b/openpgp/src/cert/amalgamation/key.rs index 397c7a0c..555f8d21 100644 --- a/openpgp/src/cert/amalgamation/key.rs +++ b/openpgp/src/cert/amalgamation/key.rs @@ -980,6 +980,19 @@ impl<'a, P: 'a + key::KeyParts> From> } } +impl<'a, P: 'a + key::KeyParts> From<&ValidPrimaryKeyAmalgamation<'a, P>> + for ValidErasedKeyAmalgamation<'a, P> +{ + fn from(vka: &ValidPrimaryKeyAmalgamation<'a, P>) -> Self { + assert!(std::ptr::eq(vka.ka.cert(), vka.cert.cert())); + ValidErasedKeyAmalgamation { + ka: vka.ka.clone().into(), + cert: vka.cert.clone(), + binding_signature: vka.binding_signature, + } + } +} + impl<'a, P: 'a + key::KeyParts> From> for ValidErasedKeyAmalgamation<'a, P> { @@ -993,6 +1006,19 @@ impl<'a, P: 'a + key::KeyParts> From> } } +impl<'a, P: 'a + key::KeyParts> From<&ValidSubordinateKeyAmalgamation<'a, P>> + for ValidErasedKeyAmalgamation<'a, P> +{ + fn from(vka: &ValidSubordinateKeyAmalgamation<'a, P>) -> Self { + assert!(std::ptr::eq(vka.ka.cert(), vka.cert.cert())); + ValidErasedKeyAmalgamation { + ka: vka.ka.clone().into(), + cert: vka.cert.clone(), + binding_signature: vka.binding_signature, + } + } +} + // We can infallibly convert part X to part Y for everything but // Public -> Secret and Unspecified -> Secret. macro_rules! impl_conversion { @@ -1009,6 +1035,19 @@ macro_rules! impl_conversion { } } } + + impl<'a> From<&$s<'a, $p1>> + for ValidErasedKeyAmalgamation<'a, $p2> + { + fn from(vka: &$s<'a, $p1>) -> Self { + assert!(std::ptr::eq(vka.ka.cert(), vka.cert.cert())); + ValidErasedKeyAmalgamation { + ka: vka.ka.clone().into(), + cert: vka.cert.clone(), + binding_signature: vka.binding_signature, + } + } + } } } -- cgit v1.2.3