summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-12-04 16:47:50 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-12-04 16:47:50 +0100
commit2d30c6b093ba8a50764461e876ea9f32d60d329c (patch)
tree56e2645695f8fb3a02a659ad7cf816c9f5cf656f
parenta2f7d84a4d2a9771b8b2d1efd47386d45b6b8881 (diff)
openpgp: Make digest computation more robust.justus/fix-615
-rw-r--r--openpgp/src/crypto/backend/cng/hash.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/openpgp/src/crypto/backend/cng/hash.rs b/openpgp/src/crypto/backend/cng/hash.rs
index 73121c23..5b5559f1 100644
--- a/openpgp/src/crypto/backend/cng/hash.rs
+++ b/openpgp/src/crypto/backend/cng/hash.rs
@@ -33,7 +33,8 @@ impl Digest for Mutex<cng::Hash> {
let buffer = old.finish()
.expect("CNG to not fail internally");
- digest.copy_from_slice(&buffer.as_slice()[..digest.len()]);
+ let l = buffer.len().min(digest.len());
+ mut digest[..l].copy_from_slice(&buffer.as_slice()[..l]);
Ok(())
}
}