Skip to content

Commit

Permalink
Test secret hash truncation
Browse files Browse the repository at this point in the history
When using `hashes` to hash a secret and print it in `Debug` we truncate
the hash into an 8 byte identifier, test it.
  • Loading branch information
tcharding committed Aug 22, 2024
1 parent fea0fc2 commit 371ec9b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,31 @@ mod test {
"0100000000000000020000000000000003000000000000000400000000000000"
);
}
#[test]
fn test_display_obfuscation() {
#[rustfmt::skip]
static SK_BYTES: [u8; 32] = [
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
];

let sk = SecretKey::from_slice(&SK_BYTES).expect("sk");

#[cfg(feature = "std")]
{
let got = format!("{:?}", sk);
let want = "SecretKey(#2f4d520bd6874292)";
assert_eq!(got, want);
}
#[cfg(all(not(feature = "std"), feature = "hashes"))]
{
let got = format!("{:?}", sk);
let want = "SecretKey(#de5a451f70110720)";
assert_eq!(got, want);
}
}

#[test]
#[cfg(feature = "alloc")]
Expand Down

0 comments on commit 371ec9b

Please sign in to comment.