identity-kit 0.2.1

DID, key management and verifiable credential primitives
Documentation
/// Why a string is not a valid DID, DID URL or DID method.
///
/// Positions are byte offsets into the input that was parsed.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum DidError {
    /// The input does not start with the lowercase `did:` scheme.
    #[error("missing `did:` scheme prefix")]
    MissingScheme,
    /// The method name is empty or contains a character other than `a-z` and `0-9`.
    #[error("invalid method name: unexpected character at byte {position}")]
    InvalidMethodName {
        /// Byte offset of the offending character.
        position: usize,
    },
    /// The method-specific id is missing, empty, or ends with `:`.
    #[error("method-specific id is empty or ends with `:`")]
    EmptyMethodSpecificId,
    /// The namespace of a [`DidMethod`](super::DidMethod) is empty, has a second segment, or
    /// contains a character that is not an `idchar`.
    #[error("invalid method namespace: unexpected character or end of input at byte {position}")]
    InvalidNamespace {
        /// Byte offset of the offending character, or of the end of the input.
        position: usize,
    },
    /// A character that is not allowed at this position of a DID.
    #[error("invalid character {ch:?} at byte {position}")]
    InvalidChar {
        /// Byte offset of the offending character.
        position: usize,
        /// The offending character.
        ch: char,
    },
    /// A `%` that is not followed by exactly two hexadecimal digits.
    #[error("incomplete or non-hex percent-encoding at byte {position}")]
    InvalidPercentEncoding {
        /// Byte offset of the `%`.
        position: usize,
    },
    /// The input is longer than the configured maximum.
    #[error("input exceeds the maximum length of {max} bytes")]
    TooLong {
        /// The maximum number of bytes accepted.
        max: usize,
    },
    /// The DID URL path is not a valid RFC 3986 `path-abempty`.
    #[error("invalid DID URL path")]
    InvalidPath,
    /// The DID URL query contains a character not allowed by RFC 3986.
    #[error("invalid DID URL query")]
    InvalidQuery,
    /// The DID URL fragment contains a character not allowed by RFC 3986.
    #[error("invalid DID URL fragment")]
    InvalidFragment,
    /// The key of a `did:jwk` holds a JSON number with no finite double value, such as
    /// `1e400`, which the JSON Canonicalization Scheme cannot encode. `serde_json` only keeps
    /// such a number when its `arbitrary_precision` feature is on.
    #[error("the JSON number {number} has no finite double value, so it cannot be canonicalized")]
    UnsupportedNumber {
        /// The number as written.
        number: String,
    },
}