pub fn get_char_description(ch: char) -> &'static strExpand description
Get a human-readable description of a character
Examples found in repository?
examples/security_analysis.rs (line 57)
9fn main() {
10 println!("Unicode Security Analysis Example");
11 println!("=================================\n");
12
13 // Example 1: Safe text
14 println!("1. Analyzing safe text:");
15 let safe_text = "Hello World! This is normal text.";
16 analyze_and_report(safe_text);
17
18 // Example 2: Text with invisible characters
19 println!("\n2. Analyzing text with invisible characters:");
20 let invisible_text = "Hello\u{200B}World\u{200C}Test"; // Zero-width space and non-joiner
21 analyze_and_report(invisible_text);
22
23 // Example 3: Bidirectional override attack
24 println!("\n3. Analyzing bidirectional override attack:");
25 let bidi_attack = "filename\u{202E}gpj.exe"; // Right-to-left override
26 analyze_and_report(bidi_attack);
27
28 // Example 4: Homograph attack (Cyrillic characters that look like Latin)
29 println!("\n4. Analyzing potential homograph attack:");
30 let homograph = "раураӏ.com"; // Cyrillic characters that look like "paypal.com"
31 analyze_and_report(homograph);
32
33 // Example 5: Mixed script attack
34 println!("\n5. Analyzing mixed script text:");
35 let mixed_script = "Secure Bank αccount Login"; // Greek alpha instead of 'a'
36 analyze_and_report(mixed_script);
37
38 // Example 6: Complex attack with multiple vectors
39 println!("\n6. Analyzing complex multi-vector attack:");
40 let complex_attack = "bank\u{200B}login\u{202E}moc.evil"; // Invisible char + bidi override
41 analyze_and_report(complex_attack);
42
43 // Example 7: Demonstrate sanitization
44 println!("\n7. Text sanitization example:");
45 let dangerous = "Hello\u{200B}World\u{202E}Dangerous\u{200C}Text";
46 println!("Original: {:?}", dangerous);
47 let sanitized = sanitize_text(dangerous);
48 println!("Sanitized: {:?}", sanitized);
49 println!("Safe to use: {}", analyze_text(&sanitized).risk_level == RiskLevel::Low);
50
51 // Example 8: Character-by-character analysis
52 println!("\n8. Character-by-character analysis:");
53 let test_chars = "a\u{200B}b\u{202E}c";
54 for (i, ch) in test_chars.char_indices() {
55 println!(" Position {}: '{}' (U+{:04X})", i, ch, ch as u32);
56 if is_invisible_char(ch) {
57 println!(" ⚠️ Invisible character: {}", get_char_description(ch));
58 }
59 if is_bidi_char(ch) {
60 println!(" ⚠️ Bidirectional character: {}", get_char_description(ch));
61 }
62 if is_confusable_char(ch) {
63 println!(" ⚠️ Potentially confusable character");
64 }
65 }
66
67 // Example 9: Script detection
68 println!("\n9. Script detection example:");
69 let multi_script = "Hello мир 世界 שלום";
70 let analysis = analyze_text(multi_script);
71 println!("Text: {}", multi_script);
72 println!("Detected scripts:");
73 for script in &analysis.scripts {
74 println!(" - {:?}", script);
75 }
76
77 // Example 10: Security recommendations
78 println!("\n10. Security recommendations:");
79 println!("✅ Always validate user input for invisible characters");
80 println!("✅ Check for bidirectional override attacks in filenames");
81 println!("✅ Be aware of homograph attacks in domain names");
82 println!("✅ Consider normalizing Unicode text before processing");
83 println!("✅ Use allowlists for acceptable character ranges when possible");
84}