From 9abd0741fe227e27dca2892e855c5ee3a89e38c9 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 18 Mar 2020 17:25:38 +0100 Subject: openpgp: Use the hex::Dumper in the tests. --- openpgp/src/serialize/mod.rs | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'openpgp/src/serialize') 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() } -- cgit v1.2.3