Rust and WASM did-method-plc tools and structures
1//! Example of validating did:plc identifiers 2 3use atproto_plc::Did; 4 5fn main() { 6 println!("DID Validation Examples\n"); 7 println!("{}", "=".repeat(60)); 8 9 let test_dids = vec![ 10 ("did:plc:ewvi7nxzyoun6zhxrhs64oiz", true, "Valid DID"), 11 ("did:plc:z72i7hdynmk6r22z27h6tvur", true, "Valid DID"), 12 ("did:plc:abc123", false, "Too short"), 13 ( 14 "did:plc:0123456789012345678901234", 15 false, 16 "Contains invalid characters (0,1,8,9)", 17 ), 18 ( 19 "DID:PLC:EWVI7NXZYOUN6ZHXRHS64OIZ", 20 false, 21 "Uppercase not allowed", 22 ), 23 ("did:web:example.com", false, "Wrong DID method"), 24 ( 25 "did:plc:ewvi7nxzyoun6zhxrhs64oizextrachars", 26 false, 27 "Too long", 28 ), 29 ]; 30 31 for (did_str, should_be_valid, description) in test_dids { 32 print!("\nTesting: {}\n ", did_str); 33 print!("Description: {}\n ", description); 34 35 match Did::parse(did_str) { 36 Ok(did) => { 37 if should_be_valid { 38 println!("✅ Valid"); 39 println!(" Identifier: {}", did.identifier()); 40 println!(" Full DID: {}", did.as_str()); 41 } else { 42 println!("❌ ERROR: Expected invalid, but was accepted!"); 43 } 44 } 45 Err(e) => { 46 if !should_be_valid { 47 println!("✅ Correctly rejected"); 48 println!(" Reason: {}", e); 49 } else { 50 println!("❌ ERROR: Expected valid, but was rejected!"); 51 println!(" Error: {}", e); 52 } 53 } 54 } 55 } 56 57 println!("\n{}", "=".repeat(60)); 58 println!("\nValidation complete!"); 59}