1#[cfg(feature = "use_spec")]
2pub use greentic_secrets_spec::{
3 DecryptError, DecryptResult, Error, Result, SecretsError, SecretsResult,
4};
5
6#[cfg(not(feature = "use_spec"))]
7mod legacy {
8 use thiserror::Error;
9
10 pub type Result<T> = std::result::Result<T, Error>;
11 pub type DecryptResult<T> = std::result::Result<T, DecryptError>;
12
13 #[derive(Debug, Clone, PartialEq, Eq, Error)]
14 pub enum Error {
15 #[error("secret identifier must not be empty")]
16 InvalidIdentifier,
17 #[error("{field} contains invalid characters: {value}")]
18 InvalidCharacters { field: &'static str, value: String },
19 #[error("{field} must not be empty")]
20 EmptyComponent { field: &'static str },
21 #[error("uri must start with secrets://")]
22 InvalidScheme,
23 #[error("uri is missing {field}")]
24 MissingSegment { field: &'static str },
25 #[error("uri contains unexpected extra segments")]
26 ExtraSegments,
27 #[error("invalid version segment: {value}")]
28 InvalidVersion { value: String },
29 #[error("encryption algorithm not supported: {0}")]
30 UnsupportedAlgorithm(String),
31 #[error("encryption algorithm {0} requires the 'xchacha' feature")]
32 AlgorithmFeatureUnavailable(String),
33 #[error("crypto error: {0}")]
34 Crypto(String),
35 #[error("storage error: {0}")]
36 Storage(String),
37 #[error("{entity} not found")]
38 NotFound { entity: String },
39 }
40
41 #[derive(Debug, Clone, PartialEq, Eq, Error)]
42 pub enum DecryptError {
43 #[error("message authentication failed")]
44 MacMismatch,
45 #[error("key provider error: {0}")]
46 Provider(String),
47 #[error("invalid envelope: {0}")]
48 InvalidEnvelope(String),
49 #[error("crypto error: {0}")]
50 Crypto(String),
51 }
52
53 pub type SecretsResult<T> = Result<T>;
54 pub type SecretsError = Error;
55}
56
57#[cfg(not(feature = "use_spec"))]
58pub use legacy::*;