diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-10-06 14:20:26 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-10-06 14:56:16 +0200 |
commit | 7abeaa9a1e64d3a396eaa714bb31f34dcb408898 (patch) | |
tree | 649c45cb07bc572d4700646e407d792eada63b31 /openpgp/src/serialize.rs | |
parent | 30b553c35e021ecb2b0fa6c934e98750044c5d52 (diff) |
openpgp: Use common mpi::SecretKeyMaterial::serialize_with_checksum.
Diffstat (limited to 'openpgp/src/serialize.rs')
-rw-r--r-- | openpgp/src/serialize.rs | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs index 2c5f99af..032cc70b 100644 --- a/openpgp/src/serialize.rs +++ b/openpgp/src/serialize.rs @@ -1823,22 +1823,11 @@ impl<P, R> Key4<P, R> self.mpis().serialize(o)?; if have_secret_key { + use crypto::mpi::SecretKeyChecksum; match self.optional_secret().unwrap() { SecretKeyMaterial::Unencrypted(ref u) => u.map(|mpis| -> Result<()> { - // S2K usage. - write_byte(o, 0)?; - - // To compute the checksum, serialize to a buffer first. - let mut buf = Vec::new(); - mpis.serialize(&mut buf)?; - let buf: crate::crypto::mem::Protected = buf.into(); - let checksum: usize = buf.iter().map(|x| *x as usize) - .sum(); - - // Then, just write out the buffer. - o.write_all(&buf)?; - write_be_u16(o, checksum as u16)?; - Ok(()) + write_byte(o, 0)?; // S2K usage. + mpis.serialize_with_checksum(o, SecretKeyChecksum::Sum16) })?, SecretKeyMaterial::Encrypted(ref e) => { // S2K usage. |