summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-04-30 14:23:54 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-05-03 15:20:37 +0200
commitcd04993ae5c35d2dd24818bf71f9eddd0802a8a0 (patch)
treeca33ba1812a5609a2fb511ba6ca417c1c9806944 /openpgp
parent90782208aa073c21fdf6d7e37575f58677c969b5 (diff)
openpgp: Move TPK/TSK serialization code to mod serialize.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/serialize/mod.rs2
-rw-r--r--openpgp/src/serialize/tpk.rs (renamed from openpgp/src/tpk/tsk.rs)94
-rw-r--r--openpgp/src/tpk/mod.rs99
3 files changed, 99 insertions, 96 deletions
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index 35e31981..8307da75 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -16,6 +16,8 @@ use autocrypt;
use super::*;
mod partial_body;
+mod tpk;
+pub use self::tpk::TSK;
use self::partial_body::PartialBodyFilter;
pub mod writer;
pub mod stream;
diff --git a/openpgp/src/tpk/tsk.rs b/openpgp/src/serialize/tpk.rs
index 6d0e57a8..f72dc132 100644
--- a/openpgp/src/tpk/tsk.rs
+++ b/openpgp/src/serialize/tpk.rs
@@ -3,6 +3,98 @@ use TPK;
use packet::{Key, Tag};
use serialize::{Serialize, SerializeKey};
+impl Serialize for TPK {
+ fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> {
+ self.primary().serialize(o, Tag::PublicKey)?;
+
+ for s in self.selfsigs() {
+ s.serialize(o)?;
+ }
+ for s in self.self_revocations() {
+ s.serialize(o)?;
+ }
+ for s in self.other_revocations() {
+ s.serialize(o)?;
+ }
+ for s in self.certifications() {
+ s.serialize(o)?;
+ }
+
+ for u in self.userids.iter() {
+ u.userid().serialize(o)?;
+ for s in u.self_revocations() {
+ s.serialize(o)?;
+ }
+ for s in u.selfsigs() {
+ s.serialize(o)?;
+ }
+ for s in u.other_revocations() {
+ s.serialize(o)?;
+ }
+ for s in u.certifications() {
+ s.serialize(o)?;
+ }
+ }
+
+ for u in self.user_attributes.iter() {
+ u.user_attribute().serialize(o)?;
+ for s in u.self_revocations() {
+ s.serialize(o)?;
+ }
+ for s in u.selfsigs() {
+ s.serialize(o)?;
+ }
+ for s in u.other_revocations() {
+ s.serialize(o)?;
+ }
+ for s in u.certifications() {
+ s.serialize(o)?;
+ }
+ }
+
+ for k in self.subkeys.iter() {
+ k.subkey().serialize(o, Tag::PublicSubkey)?;
+ for s in k.self_revocations() {
+ s.serialize(o)?;
+ }
+ for s in k.selfsigs() {
+ s.serialize(o)?;
+ }
+ for s in k.other_revocations() {
+ s.serialize(o)?;
+ }
+ for s in k.certifications() {
+ s.serialize(o)?;
+ }
+ }
+
+ for u in self.unknowns.iter() {
+ u.unknown.serialize(o)?;
+
+ for s in u.sigs.iter() {
+ s.serialize(o)?;
+ }
+ }
+
+ for s in self.bad.iter() {
+ s.serialize(o)?;
+ }
+
+ Ok(())
+ }
+}
+
+impl TPK {
+ /// Derive a [`TSK`] object from this key.
+ ///
+ /// This object writes out secret keys during serialization.
+ ///
+ /// [`TSK`]: serialize/struct.TSK.html
+ pub fn as_tsk<'a>(&'a self) -> TSK<'a> {
+ TSK::new(self)
+ }
+}
+
/// A reference to a TPK that allows serialization of secret keys.
///
/// To avoid accidental leakage `TPK::serialize()` skips secret keys.
@@ -34,7 +126,7 @@ pub struct TSK<'a> {
impl<'a> TSK<'a> {
/// Creates a new view for the given `TPK`.
- pub(crate) fn new(tpk: &'a TPK) -> Self {
+ fn new(tpk: &'a TPK) -> Self {
Self {
tpk: tpk,
filter: None,
diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs
index 7336d831..cff7f538 100644
--- a/openpgp/src/tpk/mod.rs
+++ b/openpgp/src/tpk/mod.rs
@@ -33,7 +33,7 @@ use {
Fingerprint,
};
use parse::{Parse, PacketParserResult, PacketParser};
-use serialize::{Serialize, SerializeInto, SerializeKey};
+use serialize::SerializeInto;
use conversions::Time;
use constants::ReasonForRevocation;
@@ -41,8 +41,6 @@ mod lexer;
mod grammar;
mod builder;
mod bindings;
-mod tsk;
-pub use self::tsk::TSK;
use self::lexer::Lexer;
pub use self::lexer::Token;
@@ -842,10 +840,10 @@ impl UserAttributeBinding {
/// An unknown component and any associated signatures.
#[derive(Debug, Clone, PartialEq)]
pub struct UnknownBinding {
- pub(crate) // XXX for TSK::serialize()
+ pub(crate) // XXX for serialization, see #245
unknown: Unknown,
- pub(crate) // XXX for TSK::serialize()
+ pub(crate) // XXX for serialization, see #245
sigs: Vec<Signature>,
}
@@ -2824,15 +2822,6 @@ impl TPK {
TPK::from_packet_pile(PacketPile::from(combined))
}
- /// Derive a [`TSK`] object from this key.
- ///
- /// This object writes out secret keys during serialization.
- ///
- /// [`TSK`]: tpk/struct.TSK.html
- pub fn as_tsk<'a>(&'a self) -> TSK<'a> {
- TSK::new(self)
- }
-
/// Returns whether at least one of the keys includes a secret
/// part.
pub fn is_tsk(&self) -> bool {
@@ -2845,90 +2834,10 @@ impl TPK {
}
}
-impl Serialize for TPK {
- fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> {
- self.primary().serialize(o, Tag::PublicKey)?;
-
- for s in self.primary_selfsigs.iter() {
- s.serialize(o)?;
- }
- for s in self.primary_self_revocations.iter() {
- s.serialize(o)?;
- }
- for s in self.primary_certifications.iter() {
- s.serialize(o)?;
- }
- for s in self.primary_other_revocations.iter() {
- s.serialize(o)?;
- }
-
- for u in self.userids.iter() {
- u.userid.serialize(o)?;
- for s in u.self_revocations() {
- s.serialize(o)?;
- }
- for s in u.selfsigs.iter() {
- s.serialize(o)?;
- }
- for s in u.other_revocations() {
- s.serialize(o)?;
- }
- for s in u.certifications.iter() {
- s.serialize(o)?;
- }
- }
-
- for u in self.user_attributes.iter() {
- u.user_attribute.serialize(o)?;
- for s in u.self_revocations() {
- s.serialize(o)?;
- }
- for s in u.selfsigs.iter() {
- s.serialize(o)?;
- }
- for s in u.other_revocations() {
- s.serialize(o)?;
- }
- for s in u.certifications.iter() {
- s.serialize(o)?;
- }
- }
-
- for k in self.subkeys.iter() {
- k.subkey.serialize(o, Tag::PublicSubkey)?;
- for s in k.self_revocations() {
- s.serialize(o)?;
- }
- for s in k.selfsigs.iter() {
- s.serialize(o)?;
- }
- for s in k.other_revocations() {
- s.serialize(o)?;
- }
- for s in k.certifications.iter() {
- s.serialize(o)?;
- }
- }
-
- for u in self.unknowns.iter() {
- u.unknown.serialize(o)?;
-
- for s in u.sigs.iter() {
- s.serialize(o)?;
- }
- }
-
- for s in self.bad.iter() {
- s.serialize(o)?;
- }
-
- Ok(())
- }
-}
-
#[cfg(test)]
mod test {
use crypto::KeyPair;
+ use serialize::Serialize;
use super::*;
use KeyID;