diff options
author | Neal H. Walfield <neal@pep.foundation> | 2020-03-03 23:20:33 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2020-03-03 23:52:03 +0100 |
commit | a61bfdab687e9c0b6c5e263ed304f48183059a45 (patch) | |
tree | 545d516b6b2fe513f63caf3bcc81024338459583 /openpgp/src/serialize/cert_armored.rs | |
parent | 93dbeb3160262726d4c60b4811cf352c08dfc5b3 (diff) |
openpgp: Only impl Serialize for objects that are normally exported.
- Add two new traits: `Marshal` and `MarshalInto`.
- Implement them instead of `Serialize` and `SerializeInto`.
- Only implement `Serialize` and `SerializeInto` for data structures
that are normally exported.
- This should prevent users from accidentally serializing a bare
signature (`Signature`) when they meant to serialize a signature
packet (`Packet`), for instance.
- Fixes #368.
Diffstat (limited to 'openpgp/src/serialize/cert_armored.rs')
-rw-r--r-- | openpgp/src/serialize/cert_armored.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/openpgp/src/serialize/cert_armored.rs b/openpgp/src/serialize/cert_armored.rs index 5baaa8b6..32146cec 100644 --- a/openpgp/src/serialize/cert_armored.rs +++ b/openpgp/src/serialize/cert_armored.rs @@ -7,7 +7,8 @@ use crate::cert::{Cert, amalgamation::ValidAmalgamation}; use crate::Result; use crate::types::RevocationStatus; use crate::serialize::{ - Serialize, SerializeInto, generic_serialize_into, generic_export_into, + Marshal, MarshalInto, + generic_serialize_into, generic_export_into, }; use crate::policy::StandardPolicy as P; @@ -83,7 +84,9 @@ impl Cert { /// assert!(armored.contains("Mr. Pink ☮☮☮")); /// # Ok(()) } /// ``` - pub fn armored<'a>(&'a self) -> impl Serialize + SerializeInto + 'a { + pub fn armored<'a>(&'a self) + -> impl crate::serialize::Serialize + crate::serialize::SerializeInto + 'a + { Encoder::new(self) } } @@ -124,7 +127,9 @@ impl<'a> Encoder<'a> { } } -impl<'a> Serialize for Encoder<'a> { +impl<'a> crate::serialize::Serialize for Encoder<'a> {} + +impl<'a> Marshal for Encoder<'a> { fn serialize(&self, o: &mut dyn io::Write) -> Result<()> { self.serialize_common(o, false) } @@ -134,7 +139,9 @@ impl<'a> Serialize for Encoder<'a> { } } -impl<'a> SerializeInto for Encoder<'a> { +impl<'a> crate::serialize::SerializeInto for Encoder<'a> {} + +impl<'a> MarshalInto for Encoder<'a> { fn serialized_len(&self) -> usize { let h = self.cert.armor_headers(); let headers_len = |