voa_config/config/technology/openpgp/error.rs
1//! Error handling for OpenPGP technology settings.
2
3use const_hex::FromHexError;
4
5use crate::config::technology::openpgp::TRUST_AMOUNT_MAX;
6
7/// The error that can occur when using VOA configuration files.
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10 /// An OpenPGP fingerprint is not formatted correctly.
11 #[error("Invalid OpenPGP fingerprint {fingerprint} while {context}: {source}")]
12 InvalidOpenpgpFingerprint {
13 /// The invalid OpenPGP fingerprint string.
14 fingerprint: String,
15
16 /// The context in which the error occurred.
17 ///
18 /// This is meant to complete the sentence
19 /// "Invalid OpenPGP fingerprint {fingerprint} while ".
20 context: String,
21
22 /// The source error.
23 source: FromHexError,
24 },
25
26 /// An OpenPGP fingerprint has the wrong length.
27 #[error("Invalid OpenPGP fingerprint length {fingerprint} ({}). Need 40 for OpenPGP v4 or 64 for OpenPGP v6", fingerprint.len())]
28 InvalidOpenpgpFingerprintLength {
29 /// The invalid OpenPGP fingerprint string.
30 fingerprint: String,
31 },
32
33 /// A domain name used for an OpenPGP User ID match is invalid.
34 #[error("The domain name {domain_name} is invalid:\n{message}")]
35 InvalidDomainName {
36 /// The invalid domain name.
37 domain_name: String,
38 /// The error message
39 message: String,
40 },
41
42 /// A trust amount does not lie in the allowed range of 1-120.
43 #[error(
44 "The provided trust amount {amount} is outside the allowed range of 1 - {TRUST_AMOUNT_MAX}"
45 )]
46 InvalidTrustAmount {
47 /// The invalid trust amount.
48 amount: usize,
49 },
50
51 /// An integer parsing error occurred.
52 #[error("Integer parsing error while parsing value {value} for {context}: {source}")]
53 ParseInt {
54 /// The invalid value.
55 value: String,
56
57 /// The context in which the error occurred.
58 ///
59 /// This is meant to complete the sentence "Integer parsing error while parsing value
60 /// {value} for ".
61 context: String,
62
63 /// The error source.
64 source: std::num::ParseIntError,
65 },
66}