apollo_redaction/strategy/
full.rs1use crate::RedactionStrategy;
2use std::fmt;
3
4#[derive(Default, Clone)]
21pub struct FullRedactor;
22
23impl<T: AsRef<str>> RedactionStrategy<T> for FullRedactor {
24 fn display(&self, value: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 let len = value.as_ref().chars().count().max(6);
26 for _ in 0..len {
27 write!(f, "*")?;
28 }
29 Ok(())
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36 use crate::Redacted;
37
38 fn full(input: &str) -> String {
39 Redacted::<_, FullRedactor>::new(input).to_string()
40 }
41
42 #[test]
43 fn test_full_redaction() {
44 assert_eq!(full("secret"), "******");
45 assert_eq!(full("verylongsecret"), "**************");
46 }
47
48 #[test]
49 fn test_minimum_length() {
50 assert_eq!(full("abc"), "******");
51 assert_eq!(full("a"), "******");
52 assert_eq!(full(""), "******");
53 }
54
55 #[test]
56 fn test_unicode() {
57 assert_eq!(full("안녕하세요한글"), "*******");
59 }
60}