Skip to main content

coven_crypto/
error.rs

1//! Failures callers distinguish without parsing error text.
2
3/// A cryptographic operation could not produce or authenticate its result.
4#[derive(Debug, thiserror::Error)]
5pub enum CryptoError {
6    /// The device cannot provide a cryptographic service needed by this call.
7    #[error("cryptographic service unavailable: {0}")]
8    Unavailable(#[source] Box<dyn std::error::Error + Send + Sync>),
9    /// The ciphertext, key, path, index or associated data did not authenticate.
10    #[error("ciphertext authentication failed")]
11    Authentication,
12    /// A sealed value was truncated or had invalid framing.
13    #[error("invalid sealed value")]
14    Malformed,
15    /// The opened key's audience or identity disagrees with its clear routing prefix.
16    #[error("sealed key payload disagrees with its routing prefix")]
17    KeyIdentity,
18    /// X25519 produced a non-contributory shared secret.
19    #[error("X25519 public key has low order")]
20    WeakSealingKey,
21    /// The Ed25519 public key is invalid or weak.
22    #[error("invalid or weak Ed25519 public key")]
23    InvalidSigningKey,
24    /// The member's signature did not verify.
25    #[error("signature verification failed")]
26    Signature,
27}
28
29/// A key or serialized secret violates its representation.
30#[derive(Debug, thiserror::Error, PartialEq, Eq)]
31pub enum MaterialError {
32    /// The encoded secret or sealed value is malformed.
33    #[error("invalid key material encoding")]
34    Encoding,
35    /// A different key already has this store key id.
36    #[error("conflicting store key id {0}")]
37    StoreKeyConflict(coven_foundation::id_source::KeyId),
38    /// A different key already has this circle id and key id.
39    #[error("conflicting key id {key} for circle {circle}")]
40    CircleKeyConflict {
41        /// The circle whose key id was reused.
42        circle: crate::CircleId,
43        /// The conflicting key id.
44        key: coven_foundation::id_source::KeyId,
45    },
46    /// The keyring does not hold this store key.
47    #[error("unknown store key id {0}")]
48    UnknownStoreKey(coven_foundation::id_source::KeyId),
49    /// The keyring does not hold this circle key.
50    #[error("unknown key id {key} for circle {circle}")]
51    UnknownCircleKey {
52        /// The circle whose key is missing.
53        circle: crate::CircleId,
54        /// The missing key id.
55        key: coven_foundation::id_source::KeyId,
56    },
57}