diff options
author | Azul <azul@riseup.net> | 2020-11-17 07:04:01 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2020-11-24 12:24:36 +0100 |
commit | 43ad20c16ccee274cc4ecdb327e70e2349fa12ad (patch) | |
tree | 8f5a4ee4c08643a914fb519e609c987d57617a40 /openpgp/src | |
parent | 7fb0e9302b1145d959bdb81b064b453d21f49b3a (diff) |
openpgp: seal Aead trait.
- Seal the Aead trait so it cannot be implemented outside the openpgp
crate.
- This way we can extend the trait without breaking the API
compatibility.
- See #538.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/crypto/aead.rs | 12 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/cng/aead.rs | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/nettle/aead.rs | 2 |
3 files changed, 15 insertions, 1 deletions
diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs index d6b937b4..17153aa1 100644 --- a/openpgp/src/crypto/aead.rs +++ b/openpgp/src/crypto/aead.rs @@ -16,6 +16,7 @@ use crate::Error; use crate::Result; use crate::crypto::SessionKey; use crate::crypto::mem::secure_cmp; +use crate::seal; use crate::parse::Cookie; /// Disables authentication checks. @@ -33,7 +34,16 @@ pub(crate) fn chunk_size_usize(chunk_size: u64) -> Result<usize> { } /// An AEAD mode of operation. -pub trait Aead { +/// +/// # Sealed trait +/// +/// This trait is [sealed] and cannot be implemented for types outside this crate. +/// Therefore it can be extended in a non-breaking way. +/// If you want to implement the trait inside the crate +/// 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 Aead : seal::Sealed { /// Adds associated data `ad`. fn update(&mut self, ad: &[u8]); diff --git a/openpgp/src/crypto/backend/cng/aead.rs b/openpgp/src/crypto/backend/cng/aead.rs index d0208221..d30073ca 100644 --- a/openpgp/src/crypto/backend/cng/aead.rs +++ b/openpgp/src/crypto/backend/cng/aead.rs @@ -2,6 +2,7 @@ use crate::{Error, Result}; use crate::crypto::aead::Aead; +use crate::seal; use crate::types::{AEADAlgorithm, SymmetricAlgorithm}; use super::symmetric::Ctr; @@ -73,6 +74,7 @@ impl EaxAes { } +impl seal::Sealed for EaxAes {} impl Aead for EaxAes { /// Adds associated data `ad`. fn update(&mut self, ad: &[u8]) { diff --git a/openpgp/src/crypto/backend/nettle/aead.rs b/openpgp/src/crypto/backend/nettle/aead.rs index 1614a20a..797dd040 100644 --- a/openpgp/src/crypto/backend/nettle/aead.rs +++ b/openpgp/src/crypto/backend/nettle/aead.rs @@ -4,8 +4,10 @@ use nettle::{aead, cipher}; use crate::{Error, Result}; use crate::crypto::aead::Aead; +use crate::seal; use crate::types::{AEADAlgorithm, SymmetricAlgorithm}; +impl<T: nettle::aead::Aead> seal::Sealed for T {} impl<T: nettle::aead::Aead> Aead for T { fn update(&mut self, ad: &[u8]) { self.update(ad) |