diff options
-rw-r--r-- | openpgp/src/crypto/aead.rs | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/ecdh.rs | 2 | ||||
-rw-r--r-- | openpgp/src/fmt.rs | 34 | ||||
-rw-r--r-- | openpgp/src/lib.rs | 2 | ||||
-rw-r--r-- | openpgp/src/utils.rs | 38 |
5 files changed, 42 insertions, 36 deletions
diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs index 4e16c888..dddc2698 100644 --- a/openpgp/src/crypto/aead.rs +++ b/openpgp/src/crypto/aead.rs @@ -9,7 +9,7 @@ use crate::types::{ AEADAlgorithm, SymmetricAlgorithm, }; -use crate::fmt::{ +use crate::utils::{ write_be_u64, }; use crate::Error; diff --git a/openpgp/src/crypto/ecdh.rs b/openpgp/src/crypto/ecdh.rs index d6c21897..0cde90b3 100644 --- a/openpgp/src/crypto/ecdh.rs +++ b/openpgp/src/crypto/ecdh.rs @@ -13,7 +13,7 @@ use crate::types::{ SymmetricAlgorithm, PublicKeyAlgorithm, }; -use crate::fmt::{ +use crate::utils::{ write_be_u64, read_be_u64, }; diff --git a/openpgp/src/fmt.rs b/openpgp/src/fmt.rs index 845b5af1..643750dc 100644 --- a/openpgp/src/fmt.rs +++ b/openpgp/src/fmt.rs @@ -226,34 +226,8 @@ pub(crate) fn from_hex(hex: &str, pretty: bool) -> Result<Vec<u8>> { Ok(bytes) } -pub(crate) fn read_be_u64(b: &[u8]) -> u64 { - assert_eq!(b.len(), 8); - ((b[0] as u64) << 56) as u64 - | ((b[1] as u64) << 48) - | ((b[2] as u64) << 40) - | ((b[3] as u64) << 32) - | ((b[4] as u64) << 24) - | ((b[5] as u64) << 16) - | ((b[6] as u64) << 8) - | ((b[7] as u64) << 0) -} - -pub(crate) fn write_be_u64(b: &mut [u8], n: u64) { - assert_eq!(b.len(), 8); - b[0] = (n >> 56) as u8; - b[1] = (n >> 48) as u8; - b[2] = (n >> 40) as u8; - b[3] = (n >> 32) as u8; - b[4] = (n >> 24) as u8; - b[5] = (n >> 16) as u8; - b[6] = (n >> 8) as u8; - b[7] = (n >> 0) as u8; -} - #[cfg(test)] mod test { - use super::*; - #[test] fn from_hex() { use super::from_hex as fh; @@ -380,12 +354,4 @@ mod test { type\n\ "); } - - quickcheck! { - fn be_u64_roundtrip(n: u64) -> bool { - let mut b = [0; 8]; - write_be_u64(&mut b, n); - n == read_be_u64(&b) - } - } } diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 05830cc2..88b381bf 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -147,6 +147,8 @@ mod fingerprint; mod keyid; mod keyhandle; pub use keyhandle::KeyHandle; + +pub(crate) mod utils; #[cfg(test)] mod tests; diff --git a/openpgp/src/utils.rs b/openpgp/src/utils.rs new file mode 100644 index 00000000..5abc968b --- /dev/null +++ b/openpgp/src/utils.rs @@ -0,0 +1,38 @@ +//! Utility functions that don't fit anywhere else. + +pub fn read_be_u64(b: &[u8]) -> u64 { + assert_eq!(b.len(), 8); + ((b[0] as u64) << 56) as u64 + | ((b[1] as u64) << 48) + | ((b[2] as u64) << 40) + | ((b[3] as u64) << 32) + | ((b[4] as u64) << 24) + | ((b[5] as u64) << 16) + | ((b[6] as u64) << 8) + | ((b[7] as u64) << 0) +} + +pub fn write_be_u64(b: &mut [u8], n: u64) { + assert_eq!(b.len(), 8); + b[0] = (n >> 56) as u8; + b[1] = (n >> 48) as u8; + b[2] = (n >> 40) as u8; + b[3] = (n >> 32) as u8; + b[4] = (n >> 24) as u8; + b[5] = (n >> 16) as u8; + b[6] = (n >> 8) as u8; + b[7] = (n >> 0) as u8; +} + +#[cfg(test)] +mod test { + use super::*; + + quickcheck! { + fn be_u64_roundtrip(n: u64) -> bool { + let mut b = [0; 8]; + write_be_u64(&mut b, n); + n == read_be_u64(&b) + } + } +} |