use ms_codec::codex32::Codex32String;
fn contains_window(haystack: &str, needle: &str, window: usize) -> bool {
if needle.len() < window {
return false;
}
let nbytes = needle.as_bytes();
nbytes
.windows(window)
.filter_map(|w| std::str::from_utf8(w).ok())
.any(|sub| haystack.contains(sub))
}
#[test]
fn debug_does_not_echo_secret_string() {
let secret = "ms10testsxxxxxxxxxxxxxxxxxxxxxxxxxx4nzvca9cmczlw";
let c32 = Codex32String::from_string(secret.into()).unwrap();
let dbg = format!("{c32:?}");
assert!(
!dbg.contains(secret),
"Codex32String Debug leaked the full secret string: {dbg}"
);
assert!(
!contains_window(&dbg, secret, 8),
"Codex32String Debug leaked an 8-char window of the secret: {dbg}"
);
assert!(
dbg.contains("[REDACTED"),
"Codex32String Debug missing the [REDACTED marker: {dbg}"
);
}
#[test]
fn debug_reports_a_plausible_length_only() {
let secret = "ms10testsxxxxxxxxxxxxxxxxxxxxxxxxxx4nzvca9cmczlw";
let c32 = Codex32String::from_string(secret.into()).unwrap();
let dbg = format!("{c32:?}");
let len = secret.chars().count();
assert!(
dbg.contains(&len.to_string()),
"expected the public char-count {len} in Debug: {dbg}"
);
}
#[test]
fn codex32_string_is_zeroize_on_drop() {
fn _assert_zod<T: zeroize::ZeroizeOnDrop>() {}
_assert_zod::<ms_codec::codex32::Codex32String>();
}