Skip to content

Commit 91a3555

Browse files
committed
feat: if the token seems binary, show as hexdump
1 parent 072f312 commit 91a3555

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ log = "0.4"
3535
num-traits = "0.2"
3636
open = "5"
3737
openid = "0.15"
38+
pretty-hex = "0.4.1"
3839
reqwest = "0.12"
3940
serde = { version = "1", features = ["derive"] }
4041
serde_json = "1"

src/utils/inspect.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use biscuit::{Base64Url, CompactPart};
22
use colored_json::to_colored_json_auto;
3+
use pretty_hex::pretty_hex;
34
use serde_json::Value;
45
use std::io::{stdout, Write};
56

@@ -21,7 +22,12 @@ pub fn inspect_part(part: Base64Url) -> anyhow::Result<()> {
2122
match serde_json::from_slice::<Value>(&data) {
2223
Err(err) => {
2324
println!(" Invalid JSON: {err}");
24-
stdout().lock().write_all(&data)?;
25+
if is_text(&data) {
26+
stdout().lock().write_all(&data)?;
27+
} else {
28+
let output = pretty_hex(&data);
29+
stdout().lock().write_all(output.as_bytes())?;
30+
}
2531
}
2632
Ok(value) => {
2733
println!();
@@ -30,3 +36,7 @@ pub fn inspect_part(part: Base64Url) -> anyhow::Result<()> {
3036
}
3137
Ok(())
3238
}
39+
40+
fn is_text(data: &[u8]) -> bool {
41+
String::from_utf8(data.to_vec()).is_ok()
42+
}

0 commit comments

Comments
 (0)