asimov_keyring/keyring_error.rs
1// This is free and unencumbered software released into the public domain.
2
3use asimov_id::KeyError;
4use thiserror::Error;
5
6/// An error locating a user, accessing key storage, or decoding a key.
7///
8/// I/O, keyring-backend, and key-decoding errors retain their underlying error
9/// as a source and can be converted into this type with [`From`].
10#[derive(Debug, Error)]
11pub enum KeyringError {
12 /// The requested user could not be found.
13 #[error("user not found")]
14 UserNotFound,
15
16 /// A user name is not a portable, single filename component.
17 #[error("invalid keyring user: {0}")]
18 InvalidUser(#[from] asimov_core::InvalidFilenameComponent),
19
20 /// A panic poisoned an in-process keyring coordination lock.
21 #[cfg(feature = "std")]
22 #[error("keyring coordination lock poisoned")]
23 LockPoisoned,
24
25 /// A stored secret has an invalid length; its contents are never included.
26 #[error("corrupt secret key: expected 32 bytes, got {length}")]
27 CorruptSecret {
28 /// Number of bytes in the stored secret.
29 length: usize,
30 },
31
32 /// A filesystem or other I/O operation failed.
33 ///
34 /// Available with the `std` feature.
35 #[cfg(feature = "std")]
36 #[error("I/O error: {0}")]
37 IoError(#[from] std::io::Error),
38
39 /// Publishing a rekeyed public key and restoring the previous secret failed.
40 ///
41 /// The backend may retain the new secret. After resolving the storage
42 /// failures, `Keyring::ensure_secret_key` repairs the cache from the stored
43 /// secret without rotating it again.
44 #[cfg(feature = "std")]
45 #[error(
46 "public-key publication failed: {cache_error}; secret rollback failed: {rollback_error}"
47 )]
48 RekeyRollbackFailed {
49 /// The failure publishing the public-key cache.
50 #[source]
51 cache_error: std::io::Error,
52 /// The failure restoring or removing the secret-key entry.
53 rollback_error: keyring_core::Error,
54 },
55
56 /// The keyring backend failed to initialize or access a secret-key entry.
57 #[error("keyring error: {0}")]
58 KeyringError(#[from] keyring_core::Error),
59
60 /// A key could not be decoded, for example from a stored public-key file.
61 #[error("key error: {0}")]
62 KeyError(#[from] KeyError),
63}