voa-config 0.1.1

A library for the configuration of technology backends in VOA
Documentation
//! Error handling for OpenPGP technology settings.

use const_hex::FromHexError;

use crate::config::technology::openpgp::TRUST_AMOUNT_MAX;

/// The error that can occur when using VOA configuration files.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// An OpenPGP fingerprint is not formatted correctly.
    #[error("Invalid OpenPGP fingerprint {fingerprint} while {context}: {source}")]
    InvalidOpenpgpFingerprint {
        /// The invalid OpenPGP fingerprint string.
        fingerprint: String,

        /// The context in which the error occurred.
        ///
        /// This is meant to complete the sentence
        /// "Invalid OpenPGP fingerprint {fingerprint} while ".
        context: String,

        /// The source error.
        source: FromHexError,
    },

    /// An OpenPGP fingerprint has the wrong length.
    #[error("Invalid OpenPGP fingerprint length {fingerprint} ({}). Need 40 for OpenPGP v4 or 64 for OpenPGP v6", fingerprint.len())]
    InvalidOpenpgpFingerprintLength {
        /// The invalid OpenPGP fingerprint string.
        fingerprint: String,
    },

    /// A domain name used for an OpenPGP User ID match is invalid.
    #[error("The domain name {domain_name} is invalid:\n{message}")]
    InvalidDomainName {
        /// The invalid domain name.
        domain_name: String,
        /// The error message
        message: String,
    },

    /// A trust amount does not lie in the allowed range of 1-120.
    #[error(
        "The provided trust amount {amount} is outside the allowed range of 1 - {TRUST_AMOUNT_MAX}"
    )]
    InvalidTrustAmount {
        /// The invalid trust amount.
        amount: usize,
    },

    /// An integer parsing error occurred.
    #[error("Integer parsing error while parsing value {value} for {context}: {source}")]
    ParseInt {
        /// The invalid value.
        value: String,

        /// The context in which the error occurred.
        ///
        /// This is meant to complete the sentence "Integer parsing error while parsing value
        /// {value} for ".
        context: String,

        /// The error source.
        source: std::num::ParseIntError,
    },
}