secrets_core/
errors.rs

1use thiserror::Error;
2
3/// Result alias for domain operations.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Result alias for decryption operations.
7pub type DecryptResult<T> = std::result::Result<T, DecryptError>;
8
9/// Core domain error variants.
10#[derive(Debug, Clone, PartialEq, Eq, Error)]
11pub enum Error {
12    /// Secret identifier was empty or otherwise invalid.
13    #[error("secret identifier must not be empty")]
14    InvalidIdentifier,
15    /// Component failed validation due to unexpected characters.
16    #[error("{field} contains invalid characters: {value}")]
17    InvalidCharacters {
18        /// Name of the component.
19        field: &'static str,
20        /// Offending value.
21        value: String,
22    },
23    /// Component must not be empty.
24    #[error("{field} must not be empty")]
25    EmptyComponent {
26        /// Name of the component.
27        field: &'static str,
28    },
29    /// URI scheme must always be `secrets`.
30    #[error("uri must start with secrets://")]
31    InvalidScheme,
32    /// URI was missing the specified segment.
33    #[error("uri is missing {field}")]
34    MissingSegment {
35        /// Name of the missing segment.
36        field: &'static str,
37    },
38    /// URI contained more segments than expected.
39    #[error("uri contains unexpected extra segments")]
40    ExtraSegments,
41    /// Version component failed validation.
42    #[error("invalid version segment: {value}")]
43    InvalidVersion {
44        /// Offending value.
45        value: String,
46    },
47    /// Requested encryption algorithm is not recognised.
48    #[error("encryption algorithm not supported: {0}")]
49    UnsupportedAlgorithm(String),
50    /// Algorithm requires a feature that is not compiled in.
51    #[error("encryption algorithm {0} requires the 'xchacha' feature")]
52    AlgorithmFeatureUnavailable(String),
53    /// Low-level crypto failure.
54    #[error("crypto error: {0}")]
55    Crypto(String),
56    /// Backing store failed to satisfy the request.
57    #[error("storage error: {0}")]
58    Storage(String),
59    /// Requested entity could not be found.
60    #[error("{entity} not found")]
61    NotFound {
62        /// Name of the missing entity (usually a URI).
63        entity: String,
64    },
65}
66
67/// Fine grained errors emitted by decrypt operations.
68#[derive(Debug, Clone, PartialEq, Eq, Error)]
69pub enum DecryptError {
70    /// Authentication tag mismatch or tampered ciphertext.
71    #[error("message authentication failed")]
72    MacMismatch,
73    /// Key provider returned an error.
74    #[error("key provider error: {0}")]
75    Provider(String),
76    /// Envelope was malformed or missing required fields.
77    #[error("invalid envelope: {0}")]
78    InvalidEnvelope(String),
79    /// Generic crypto failure.
80    #[error("crypto error: {0}")]
81    Crypto(String),
82}