diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-05-21 17:50:22 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-05-22 15:45:29 +0200 |
commit | 387ac1cc1477d37003e659c3183b81300afcb2c3 (patch) | |
tree | 8d7180c9e3b776147feacbc06dc475455016afac /tool | |
parent | 5d59509fd7e09f19eb5d21ec94b7905ac30af562 (diff) |
openpgp: Trait Serialize/Parse cleanup.
- Currently, when we serialize a packet structure, like Signature,
we get a full packet with CTB and length, even though we didn't
really ask for that. If we want to create an embedded signature,
we need to use the special interface Signature::serialize_naked()
to get it without frame.
- Also consider Key. Here, we don't know whether it is supposed to
be primary or subkey, or public or secret. Therefore, we have
SerializeKey, which is like Serialize, but also gets a tag. Now,
if Key::serialize() would only emit the body, it wouldn't need to
know what kind of key to emit.
- The same applies to trait Parse. If we use, say,
Signature::from_bytes(), the parser expects a framed signature.
If we want to parse an embedded signature, we need to use a
special interface again.
- This patch changes how we parse and serialize packet structures to
not expect or emit the frame. If we want to include the frame, we
need to explicitly wrap it into an enum Packet.
- This patch does not include any cleanups and optimizations to keep
the size manageable.
- See #255.
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/commands/key.rs | 3 | ||||
-rw-r--r-- | tool/src/commands/sign.rs | 10 |
2 files changed, 7 insertions, 6 deletions
diff --git a/tool/src/commands/key.rs b/tool/src/commands/key.rs index 90f7284c..409f3739 100644 --- a/tool/src/commands/key.rs +++ b/tool/src/commands/key.rs @@ -3,6 +3,7 @@ use failure::Fail; use clap::ArgMatches; use itertools::Itertools; +use openpgp::Packet; use openpgp::tpk::{TPKBuilder, CipherSuite}; use openpgp::packet::KeyFlags; use openpgp::armor::{Writer, Kind}; @@ -211,7 +212,7 @@ pub fn generate(m: &ArgMatches, force: bool) -> failure::Fallible<()> { { let w = create_or_stdout(Some(&rev_path), force)?; let mut w = Writer::new(w, Kind::Signature, &[])?; - rev.serialize(&mut w)?; + Packet::Signature(rev).serialize(&mut w)?; } } else { return Err( diff --git a/tool/src/commands/sign.rs b/tool/src/commands/sign.rs index f527f3a7..fdd9c15c 100644 --- a/tool/src/commands/sign.rs +++ b/tool/src/commands/sign.rs @@ -89,8 +89,8 @@ fn sign_data(input: &mut io::Read, output_path: Option<&str>, // When extending a detached signature, prepend any existing // signatures first. - for sig in prepend_sigs { - sig.serialize(&mut output)?; + for sig in prepend_sigs.into_iter() { + Packet::Signature(sig).serialize(&mut output)?; } // Stream an OpenPGP message. @@ -284,12 +284,12 @@ fn sign_message(input: &mut io::Read, output_path: Option<&str>, _ => (), } - ops.serialize(&mut sink)?; + Packet::OnePassSig(ops).serialize(&mut sink)?; seen_signature = true; }, - Packet::Signature(ref sig) => { - sig.serialize(&mut sink) + Packet::Signature(sig) => { + Packet::Signature(sig).serialize(&mut sink) .context("Failed to serialize")?; if let State::Signing { ref mut signature_count } = state { *signature_count -= 1; |