summaryrefslogtreecommitdiffstats
path: root/autocrypt
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2020-11-19 15:18:34 +0100
committerAzul <azul@riseup.net>2020-11-28 09:12:33 +0100
commit0e75ff3c13cd4a43584fc186510ddbde9d6b6422 (patch)
tree2907eb55f55ff805c02759fba5e2b0167a3225a3 /autocrypt
parentc80d2ab084a021bfa86cb2e4169490a53c8d87fc (diff)
autocrypt: do not implement openpgp::serialize traits
- An autocrypt header is not serialized the same way a Cert is. We might extend the Serialize trait to also allow for armored output. This would make no sense for an autocrypt header. - So just implement a `serialize` function independently of the openpgp crates serialize module.
Diffstat (limited to 'autocrypt')
-rw-r--r--autocrypt/src/lib.rs17
-rw-r--r--autocrypt/src/serialize.rs27
2 files changed, 16 insertions, 28 deletions
diff --git a/autocrypt/src/lib.rs b/autocrypt/src/lib.rs
index 93ece361..a82a1952 100644
--- a/autocrypt/src/lib.rs
+++ b/autocrypt/src/lib.rs
@@ -42,7 +42,6 @@ use openpgp::types::RevocationStatus;
mod cert;
pub use cert::cert_builder;
-mod serialize;
/// Version of Autocrypt to use. `Autocrypt::default()` always returns the
/// latest version.
@@ -179,6 +178,22 @@ impl AutocryptHeader {
None
}
+
+ pub fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> {
+ if self.key.is_none() {
+ return Err(Error::InvalidOperation("No key".into()).into());
+ }
+
+ for attr in self.attributes.iter() {
+ write!(o, "{}={}; ", attr.key, attr.value)?;
+ }
+
+ let mut buf = Vec::new();
+ self.key.as_ref().unwrap().serialize(&mut buf)?;
+ write!(o, "keydata={} ", base64::encode(&buf))?;
+ Ok(())
+ }
+
}
/// A set of parsed Autocrypt headers.
diff --git a/autocrypt/src/serialize.rs b/autocrypt/src/serialize.rs
deleted file mode 100644
index 85979057..00000000
--- a/autocrypt/src/serialize.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-use sequoia_openpgp as openpgp;
-use openpgp::serialize::Marshal;
-
-use super::{
- AutocryptHeader,
- Error,
- Result,
-};
-
-impl openpgp::serialize::Serialize for AutocryptHeader {}
-
-impl Marshal for AutocryptHeader {
- fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> {
- if self.key.is_none() {
- return Err(Error::InvalidOperation("No key".into()).into());
- }
-
- for attr in self.attributes.iter() {
- write!(o, "{}={}; ", attr.key, attr.value)?;
- }
-
- let mut buf = Vec::new();
- self.key.as_ref().unwrap().serialize(&mut buf)?;
- write!(o, "keydata={} ", base64::encode(&buf))?;
- Ok(())
- }
-}