diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-10-26 15:03:01 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-10-26 15:30:51 +0200 |
commit | 6cac049b99c98e001404b57ef4049773618c73ed (patch) | |
tree | 9895c4a2537bc564fb65d3a11d92fede71314a13 /openpgp/src | |
parent | 2fcb61a0be2d89400d2ff5764f6377426bb2bdfc (diff) |
openpgp: Fix serializing keys that have no secrets.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/serialize/mod.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs index 5fd79b97..11afe809 100644 --- a/openpgp/src/serialize/mod.rs +++ b/openpgp/src/serialize/mod.rs @@ -731,6 +731,15 @@ impl SerializeKey for Key { let have_secret_key = (tag == Tag::SecretKey || tag == Tag::SecretSubkey) && self.secret.is_some(); + + // Only emit packets with the SecretKey or SecretSubkey tags + // if we have secrets. + let tag = match tag { + Tag::SecretKey if ! have_secret_key => Tag::PublicKey, + Tag::SecretSubkey if ! have_secret_key => Tag::PublicSubkey, + t => t, + }; + let len = 1 + 4 + 1 + self.mpis.serialized_len() + if have_secret_key { |