summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-12-20 17:17:36 +0100
committerJustus Winter <justus@sequoia-pgp.org>2018-12-27 16:29:22 +0100
commit92b5aa4e6067d1566b2759385dcfec966b6700c1 (patch)
tree633fc7bbd1174ecea3e0550c8d3d8f90b73a7e8b /openpgp
parentf69cf9bb74ad5ee7002ac1e84caaad635b9b52b3 (diff)
openpgp: Implement serialize_chksumd for SecretKey.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/serialize/mod.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index 482df71d..75a1c940 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -357,6 +357,26 @@ impl Serialize for crypto::mpis::SecretKey {
}
}
+impl crypto::mpis::SecretKey {
+ /// Writes this secret key with a checksum to `w`.
+ pub fn serialize_chksumd<W: io::Write>(&self, w: &mut W) -> Result<()> {
+ use nettle::Hash;
+ use nettle::hash::insecure_do_not_use::Sha1;
+
+ // First, the MPIs.
+ self.serialize(w)?;
+
+ // The checksum is SHA1 over the serialized MPIs.
+ let mut hash = Sha1::default();
+ self.serialize(&mut hash)?;
+ let mut digest = [0u8; 20];
+ hash.digest(&mut digest);
+ w.write_all(&digest)?;
+
+ Ok(())
+ }
+}
+
impl Serialize for crypto::mpis::Ciphertext {
fn serialize<W: io::Write>(&self, w: &mut W) -> Result<()> {
use crypto::mpis::Ciphertext::*;