Skip to content

Commit 495f254

Browse files
committed
use data_encoding crate for hex
1 parent 56974fd commit 495f254

File tree

4 files changed

+5
-18
lines changed

4 files changed

+5
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mitmproxy-contentviews/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ workspace = true
1414
[dependencies]
1515
anyhow = { version = "1.0.97", features = ["backtrace"] }
1616
log = "0.4.27"
17+
data-encoding = "2.8.0"
1718
pretty-hex = "0.4.1"
1819
mitmproxy-highlight = { path = "../mitmproxy-highlight" }
1920
serde = { version = "1.0", features = ["derive"] }

mitmproxy-contentviews/src/hex_stream.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::{Metadata, Prettify, Reencode};
22
use anyhow::{Context, Result};
3-
use pretty_hex::{HexConfig, PrettyHex};
4-
use std::num::ParseIntError;
53

64
pub struct HexStream;
75

@@ -25,17 +23,7 @@ impl Prettify for HexStream {
2523
}
2624

2725
fn prettify(&self, data: &[u8], _metadata: &dyn Metadata) -> Result<String> {
28-
Ok(data
29-
.hex_conf(HexConfig {
30-
title: false,
31-
ascii: false,
32-
width: 0,
33-
group: 0,
34-
chunk: 0,
35-
max_bytes: usize::MAX,
36-
display_offset: 0,
37-
})
38-
.to_string())
26+
Ok(data_encoding::HEXLOWER.encode(data))
3927
}
4028

4129
fn render_priority(&self, data: &[u8], _metadata: &dyn Metadata) -> f64 {
@@ -53,10 +41,8 @@ impl Reencode for HexStream {
5341
if data.len() % 2 != 0 {
5442
anyhow::bail!("Invalid hex string: uneven number of characters");
5543
}
56-
(0..data.len())
57-
.step_by(2)
58-
.map(|i| u8::from_str_radix(&data[i..i + 2], 16))
59-
.collect::<Result<Vec<u8>, ParseIntError>>()
44+
data_encoding::HEXLOWER_PERMISSIVE
45+
.decode(data.as_bytes())
6046
.context("Invalid hex string")
6147
}
6248
}

src/processes/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub use image;
22
use std::path::PathBuf;
3-
use std::sync::LazyLock;
43

54
#[cfg(any(target_os = "linux", target_os = "macos"))]
65
mod nix_list;

0 commit comments

Comments
 (0)