summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-03-18 17:25:38 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-03-18 17:29:33 +0100
commit9abd0741fe227e27dca2892e855c5ee3a89e38c9 (patch)
tree63d6ce5b3e1915db23de6ceb58603c64f3a3294c
parent97908d6f25f8973aee95a1850ae42af0323698c7 (diff)
openpgp: Use the hex::Dumper in the tests.
-rw-r--r--openpgp/src/serialize/mod.rs33
1 files changed, 3 insertions, 30 deletions
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index 2cef9a28..e8d9b38b 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -2742,36 +2742,9 @@ mod test {
// A convenient function to dump binary data to stdout.
fn binary_pp(data: &[u8]) -> String {
- let mut output = Vec::with_capacity(data.len() * 2 + 3 * data.len() / 4);
-
- for i in 0..data.len() {
- if i > 0 && i % (4 * 4 * 2) == 0 {
- output.push('\n' as u8);
- } else {
- if i > 0 && i % 2 == 0 {
- output.push(' ' as u8);
- }
- if i > 0 && i % (4 * 2) == 0 {
- output.push(' ' as u8);
- }
- }
-
- let top = data[i] >> 4;
- let bottom = data[i] & 0xFu8;
-
- if top < 10u8 {
- output.push('0' as u8 + top)
- } else {
- output.push('A' as u8 + (top - 10u8))
- }
-
- if bottom < 10u8 {
- output.push('0' as u8 + bottom)
- } else {
- output.push('A' as u8 + (bottom - 10u8))
- }
- }
-
+ let mut output = Vec::new();
+ crate::fmt::hex::Dumper::new(&mut output, "")
+ .write_ascii(data).unwrap();
// We know the content is valid UTF-8.
String::from_utf8(output).unwrap()
}