grafos_securestore/
error.rs

1//! Error types for the secure store.
2
3use crate::epoch::EpochId;
4use alloc::string::String;
5use core::fmt;
6
7/// Errors returned by secure store operations.
8#[derive(Debug, PartialEq)]
9pub enum SecureStoreError {
10    /// No epoch is currently in the Active state.
11    NoActiveEpoch,
12    /// The requested epoch has expired.
13    EpochExpired(EpochId),
14    /// The requested epoch does not exist.
15    EpochNotFound(EpochId),
16    /// The key for the requested epoch is unavailable (expired or missing lease).
17    KeyUnavailable(EpochId),
18    /// A cryptographic operation failed.
19    CryptoError(String),
20    /// A storage operation failed.
21    StorageError(String),
22}
23
24impl fmt::Display for SecureStoreError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Self::NoActiveEpoch => write!(f, "no active epoch"),
28            Self::EpochExpired(id) => write!(f, "epoch {} expired", id.0),
29            Self::EpochNotFound(id) => write!(f, "epoch {} not found", id.0),
30            Self::KeyUnavailable(id) => write!(f, "key unavailable for epoch {}", id.0),
31            Self::CryptoError(msg) => write!(f, "crypto error: {}", msg),
32            Self::StorageError(msg) => write!(f, "storage error: {}", msg),
33        }
34    }
35}