diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-03-25 11:01:36 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-03-25 11:01:36 +0100 |
commit | 6632a2b5591908d68e49fc42377c4ad6a55c840b (patch) | |
tree | ba524cc027dc2ffca4a174d16f43f71534836a09 /openpgp/src/conversions.rs | |
parent | fee8268526e7fdefe41055e7bd10a84c06b88e44 (diff) |
openpgp: Add a public API for hex conversions.
Diffstat (limited to 'openpgp/src/conversions.rs')
-rw-r--r-- | openpgp/src/conversions.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/openpgp/src/conversions.rs b/openpgp/src/conversions.rs index 77236fbd..c1034f64 100644 --- a/openpgp/src/conversions.rs +++ b/openpgp/src/conversions.rs @@ -67,6 +67,28 @@ impl Duration for time::Duration { } } +/// Converts buffers to and from hexadecimal numbers. +pub mod hex { + /// Encodes the given buffer as hexadecimal number. + pub fn encode<B: AsRef<[u8]>>(buffer: B) -> String { + super::to_hex(buffer.as_ref(), false) + } + + /// Encodes the given buffer as hexadecimal number with spaces. + pub fn encode_pretty<B: AsRef<[u8]>>(buffer: B) -> String { + super::to_hex(buffer.as_ref(), true) + } + + /// Decodes the given hexadecimal number. + pub fn decode<H: AsRef<str>>(hex: H) -> ::Result<Vec<u8>> { + super::from_hex(hex.as_ref(), false) + } + + /// Decodes the given hexadecimal number, ignoring whitespace. + pub fn decode_pretty<H: AsRef<str>>(hex: H) -> ::Result<Vec<u8>> { + super::from_hex(hex.as_ref(), true) + } +} /// A helpful debugging function. #[allow(dead_code)] |