pub fn is_valid_did_method_web(did: &str, strict: bool) -> boolExpand description
Validates if a string is a properly formatted Web DID.
A valid Web DID must start with the prefix did:web: followed by content that
depends on the strictness mode:
§Strict Mode (strict = true)
- Only a valid hostname is allowed after
did:web: - No additional path segments permitted
§Non-Strict Mode (strict = false)
- First segment must be a valid hostname
- Additional colon-separated segments are allowed
- Each additional segment must be non-empty and alphanumeric
§Arguments
did- The DID string to validatestrict- Whether to use strict hostname-only validation
§Returns
true if the DID is a valid Web DID according to the specified mode, false otherwise
§Examples
use atproto_identity::validation::is_valid_did_method_web;
// Valid in both modes
assert!(is_valid_did_method_web("did:web:example.com", true));
assert!(is_valid_did_method_web("did:web:example.com", false));
// Valid only in non-strict mode
assert!(!is_valid_did_method_web("did:web:example.com:path", true));
assert!(is_valid_did_method_web("did:web:example.com:path", false));
assert!(is_valid_did_method_web("did:web:example.com:path:subpath", false));
// Invalid in both modes
assert!(!is_valid_did_method_web("did:web:192.168.1.1", true));
assert!(!is_valid_did_method_web("did:web:example.com:", false));