diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2020-04-03 17:34:28 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2020-05-11 15:53:38 +0200 |
commit | bad0aa4e36e6c504627bde16ae95daeb557d301b (patch) | |
tree | df4dfe796e821d845fb823a62648c957633975a1 /openpgp/src/packet/pkesk.rs | |
parent | 8e4932b7084ed0ed10fe250b5bdc69bc9001880c (diff) |
openpgp: Use {to,from}_be_bytes.
- Replace bitshifts with the conversion functions from the standard
library.
Diffstat (limited to 'openpgp/src/packet/pkesk.rs')
-rw-r--r-- | openpgp/src/packet/pkesk.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index 6aa7eb66..0724e50f 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -70,11 +70,15 @@ impl PKESK3 { psk.push(algo.into()); psk.extend_from_slice(session_key); - // Compute the sum modulo 65536. - let checksum - = session_key.iter().map(|&x| x as usize).sum::<usize>() & 0xffff; - psk.push((checksum >> 8) as u8); - psk.push((checksum >> 0) as u8); + // Compute the sum modulo 65536, i.e. as u16. + let checksum = session_key + .iter() + .cloned() + .map(u16::from) + .fold(0u16, u16::wrapping_add); + + psk.extend_from_slice(&checksum.to_be_bytes()); + let psk: SessionKey = psk.into(); let esk = recipient.encrypt(&psk)?; Ok(PKESK3{ |