1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Error)]
10pub enum Error {
11 #[error("key not found: {0:?}")]
13 KeyNotFound(crate::KeyId),
14
15 #[error("key has expired")]
17 KeyExpired,
18
19 #[error("invalid key state: {0}")]
21 InvalidKeyState(String),
22
23 #[error("cryptographic error: {0}")]
25 CryptoError(String),
26
27 #[error("storage error: {0}")]
29 StorageError(String),
30
31 #[error("insufficient entropy")]
33 InsufficientEntropy,
34
35 #[error("rotation failed: {0}")]
37 RotationFailed(String),
38
39 #[error("serialisation error: {0}")]
41 SerializationError(String),
42
43 #[error("I/O error: {0}")]
45 IoError(#[from] std::io::Error),
46}
47
48impl Error {
49 pub fn crypto<S: Into<String>>(msg: S) -> Self {
51 Self::CryptoError(msg.into())
52 }
53
54 pub fn storage<S: Into<String>>(msg: S) -> Self {
56 Self::StorageError(msg.into())
57 }
58}