apollo_redaction/strategy/
password.rs1use crate::RedactionStrategy;
2use std::fmt;
3
4#[derive(Default, Clone)]
22pub struct PasswordRedactor;
23
24impl<T> RedactionStrategy<T> for PasswordRedactor {
25 fn display(&self, _value: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "********")
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33 use crate::Redacted;
34
35 fn password(input: &str) -> String {
36 Redacted::<_, PasswordRedactor>::new(input).to_string()
37 }
38
39 #[test]
40 fn test_fixed_length() {
41 assert_eq!(password("short"), "********");
42 assert_eq!(password("a_very_long_password_123!"), "********");
43 assert_eq!(password("x"), "********");
44 assert_eq!(password(""), "********");
45 }
46}