diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-08-12 15:39:39 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-08-20 12:17:20 +0200 |
commit | bb447441a4a94563736760e28f368e1186064c57 (patch) | |
tree | 48f3ed194a2a356bc7e59fac8233336960ecadad | |
parent | 837192beb3700d8fb110560261036c856f4bf13e (diff) |
openpgp: Make key::Encrypted::ciphertext fallible.
-rw-r--r-- | openpgp/src/packet/key.rs | 4 | ||||
-rw-r--r-- | openpgp/src/serialize.rs | 5 | ||||
-rw-r--r-- | tool/src/commands/dump.rs | 6 |
3 files changed, 9 insertions, 6 deletions
diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 9699f4ea..2cd1becc 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -1409,8 +1409,8 @@ impl Encrypted { } /// Returns the encrypted secret key material. - pub fn ciphertext(&self) -> &[u8] { - &self.ciphertext + pub fn ciphertext(&self) -> Result<&[u8]> { + Ok(&self.ciphertext) } /// Decrypts the secret key material using `password`. diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs index 87c12cd6..4aababcd 100644 --- a/openpgp/src/serialize.rs +++ b/openpgp/src/serialize.rs @@ -1826,7 +1826,7 @@ impl<P, R> Key4<P, R> write_byte(o, 254)?; write_byte(o, e.algo().into())?; e.s2k().serialize(o)?; - o.write_all(e.ciphertext())?; + o.write_all(e.ciphertext()?)?; }, } } @@ -1847,7 +1847,8 @@ impl<P, R> Key4<P, R> u.map(|mpis| mpis.serialized_len()) + 2, // Two octet checksum. SecretKeyMaterial::Encrypted(ref e) => - 1 + e.s2k().serialized_len() + e.ciphertext().len(), + 1 + e.s2k().serialized_len() + + e.ciphertext().unwrap().len(), } } else { 0 diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs index 93986342..b149f837 100644 --- a/tool/src/commands/dump.rs +++ b/tool/src/commands/dump.rs @@ -440,8 +440,10 @@ impl PacketDumper { writeln!(output, "{} Sym. algo: {}", ii, e.algo())?; if pd.mpis { - pd.dump_mpis(output, &ii, &[e.ciphertext()], - &["ciphertext"])?; + if let Ok(ciphertext) = e.ciphertext() { + pd.dump_mpis(output, &ii, &[ciphertext], + &["ciphertext"])?; + } } }, } |