totp-sos 3.1.0

RFC-compliant TOTP implementation with minimal dependencies.
Documentation
use thiserror::Error;

/// Errors generated by the library.
#[derive(Debug, Error)]
pub enum Error {
    /// Error generated when a secret is not valid base32.
    #[error("Secret '{0}' is not a valid non-padded base32 string")]
    Secret(String),

    /// Error generated an issuer mismatch is detected.
    #[error("An issuer '{0}' could be retrieved from the path, but a different issuer '{1}' was found in the issuer URL parameter")]
    IssuerMismatch(String, String),

    /// Error generated an issuer contains a colon.
    #[error("Issuer '{0}' must not contain a colon")]
    Issuer(String),

    /// Error generated an account name contains a colon.
    #[error("Account name '{0}' must not contain a colon")]
    AccountName(String),

    /// Error generated step cannot be parsed as a number.
    #[error("Could not parse step '{0}' as a number")]
    Step(String),

    /// Error generated digits cannot be parsed as a number.
    #[error("Could not parse digits '{0}' as a number")]
    Digits(String),

    /// Error generated when an invalid algorithm is detected.
    #[error("Algorithm can only be SHA1, SHA256 or SHA512, not '{0}'")]
    Algorithm(String),

    /// Error generated when decoding a URL.
    #[error("Could not decode URL '{0}'")]
    IssuerDecoding(String),

    /// Error generated when a URL host is invalid.
    #[error("Host should be totp, not '{0}'")]
    Host(String),

    /// Error generated when a URL scheme is invalid.
    #[error("Scheme should be otpauth, not '{0}'")]
    Scheme(String),

    /// Error generated when the length of the shared secret is not at least 128 bits.
    #[error("The length of the shared secret MUST be at least 128 bits; {0} bits is not enough")]
    SecretTooSmall(usize),

    /// Error generated when the number of digits is not in the valid range.
    #[error("Implementations MUST extract a 6-digit code at a minimum and possibly 7 and 8-digit code; {0} digits is not allowed")]
    InvalidDigits(usize),

    /// Errors generated by the URL library.
    #[error(transparent)]
    Url(#[from] url::ParseError),

    /// Errors generated by the system time.
    #[error(transparent)]
    Time(#[from] std::time::SystemTimeError),
}