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/keyid.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/keyid.rs')
-rw-r--r-- | openpgp/src/keyid.rs | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs index ddd8b247..fb511316 100644 --- a/openpgp/src/keyid.rs +++ b/openpgp/src/keyid.rs @@ -117,16 +117,7 @@ impl From<Fingerprint> for KeyID { impl KeyID { /// Converts a u64 to a KeyID. pub fn new(data: u64) -> KeyID { - let bytes = [ - (data >> (7 * 8)) as u8, - (data >> (6 * 8)) as u8, - (data >> (5 * 8)) as u8, - (data >> (4 * 8)) as u8, - (data >> (3 * 8)) as u8, - (data >> (2 * 8)) as u8, - (data >> (1 * 8)) as u8, - (data >> (0 * 8)) as u8 - ]; + let bytes = data.to_be_bytes(); Self::from_bytes(&bytes[..]) } @@ -134,15 +125,7 @@ impl KeyID { pub fn as_u64(&self) -> Result<u64> { match &self { KeyID::V4(ref b) => - Ok(0u64 - | ((b[0] as u64) << (7 * 8)) - | ((b[1] as u64) << (6 * 8)) - | ((b[2] as u64) << (5 * 8)) - | ((b[3] as u64) << (4 * 8)) - | ((b[4] as u64) << (3 * 8)) - | ((b[5] as u64) << (2 * 8)) - | ((b[6] as u64) << (1 * 8)) - | ((b[7] as u64) << (0 * 8))), + Ok(u64::from_be_bytes(*b)), KeyID::Invalid(_) => Err(Error::InvalidArgument("Invalid KeyID".into()).into()), } |