identity_kit/did/error.rs
1/// Why a string is not a valid DID or DID URL.
2///
3/// Positions are byte offsets into the input that was parsed.
4#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5#[non_exhaustive]
6pub enum DidError {
7 /// The input does not start with the lowercase `did:` scheme.
8 #[error("missing `did:` scheme prefix")]
9 MissingScheme,
10 /// The method name is empty or contains a character other than `a-z` and `0-9`.
11 #[error("invalid method name: unexpected character at byte {position}")]
12 InvalidMethodName {
13 /// Byte offset of the offending character.
14 position: usize,
15 },
16 /// The method-specific id is missing, empty, or ends with `:`.
17 #[error("method-specific id is empty or ends with `:`")]
18 EmptyMethodSpecificId,
19 /// A character that is not allowed at this position of a DID.
20 #[error("invalid character {ch:?} at byte {position}")]
21 InvalidChar {
22 /// Byte offset of the offending character.
23 position: usize,
24 /// The offending character.
25 ch: char,
26 },
27 /// A `%` that is not followed by exactly two hexadecimal digits.
28 #[error("incomplete or non-hex percent-encoding at byte {position}")]
29 InvalidPercentEncoding {
30 /// Byte offset of the `%`.
31 position: usize,
32 },
33 /// The input is longer than the configured maximum.
34 #[error("input exceeds the maximum length of {max} bytes")]
35 TooLong {
36 /// The maximum number of bytes accepted.
37 max: usize,
38 },
39 /// The DID URL path is not a valid RFC 3986 `path-abempty`.
40 #[error("invalid DID URL path")]
41 InvalidPath,
42 /// The DID URL query contains a character not allowed by RFC 3986.
43 #[error("invalid DID URL query")]
44 InvalidQuery,
45 /// The DID URL fragment contains a character not allowed by RFC 3986.
46 #[error("invalid DID URL fragment")]
47 InvalidFragment,
48}