From b21f22daa452f98845ab9c0ad0cf4b36bbe31251 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 17 Nov 2020 15:54:54 +0100 Subject: openpgp: seal traits in cert::amalgamation - Seal `ValidAmalgamation`, `ValidateAmalgamation` and `key::PrimaryKey` - Sealing traits so they cannot be implemented outside the openpgp crate. This way we can extend the traits without breaking the API compatibility. Every implementation of a sealed trait needs to also implement the `seal::Sealed` marker trait. - Implementing `seal::Sealed` for `ValidKeyAmalgamation<'a, P, R, R2>` also implements it for - `ValidPrimaryKeyAmalgamation<'a, P>` - `ValidSubordinateKeyAmalgamation<'a, P>` - `ValidErasedKeyAmalgamation<'a, P>` Therefore these can implement `ValidateAmalgamation` and `key::PrimaryKey` without explicitly implementing `seal::Sealed` - See #538. --- openpgp/src/cert.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'openpgp/src/cert.rs') diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs index 1b32d87f..f6232bc6 100644 --- a/openpgp/src/cert.rs +++ b/openpgp/src/cert.rs @@ -162,6 +162,7 @@ use crate::{ packet::Unknown, Packet, PacketPile, + seal, KeyID, Fingerprint, KeyHandle, @@ -445,7 +446,7 @@ type UnknownBundles = ComponentBundles; /// you also need to implement the `seal::Sealed` marker trait. /// /// [sealed]: https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed -pub trait Preferences<'a>: crate::seal::Sealed { +pub trait Preferences<'a>: seal::Sealed { /// Returns the supported symmetric algorithms ordered by /// preference. /// @@ -2798,8 +2799,6 @@ pub struct ValidCert<'a> { time: time::SystemTime, } -impl<'a> crate::seal::Sealed for ValidCert<'a> {} - impl<'a> std::ops::Deref for ValidCert<'a> { type Target = Cert; @@ -3393,7 +3392,8 @@ macro_rules! impl_pref { } } -impl<'a> crate::cert::Preferences<'a> for ValidCert<'a> +impl<'a> seal::Sealed for ValidCert<'a> {} +impl<'a> Preferences<'a> for ValidCert<'a> { impl_pref!(preferred_symmetric_algorithms, &'a [SymmetricAlgorithm]); impl_pref!(preferred_hash_algorithms, &'a [HashAlgorithm]); -- cgit v1.2.3