Skip to main content

scp_platform/
error.rs

1//! Platform error types for SCP platform abstraction traits.
2//!
3//! All platform trait methods return [`PlatformError`] as their error type.
4//! See ADR-006 for the platform adapter architecture.
5
6use crate::traits::KeyType;
7
8/// Errors returned by platform abstraction trait implementations.
9///
10/// Each variant covers a distinct failure mode across the four platform traits
11/// ([`KeyCustody`](crate::traits::KeyCustody), [`DeviceAttestation`](crate::traits::DeviceAttestation),
12/// [`Push`](crate::traits::Push), [`Storage`](crate::traits::Storage)).
13/// See ADR-006 for the full platform adapter design.
14#[derive(Debug, thiserror::Error)]
15pub enum PlatformError {
16    /// The specified key handle does not exist or has been destroyed.
17    #[error("key not found")]
18    KeyNotFound,
19
20    /// An operation was attempted with a key of the wrong type.
21    ///
22    /// For example, calling `sign` with an X25519 key handle, or calling
23    /// `dh_agree` with an Ed25519 key handle.
24    #[error("wrong key type: expected {expected:?}, got {actual:?}")]
25    WrongKeyType {
26        /// The key type the operation requires.
27        expected: KeyType,
28        /// The key type that was actually provided.
29        actual: KeyType,
30    },
31
32    /// A storage operation failed.
33    #[error("storage error: {0}")]
34    StorageError(String),
35
36    /// A device attestation operation failed.
37    #[error("attestation error: {0}")]
38    AttestationError(String),
39
40    /// A push notification operation failed.
41    #[error("push error: {0}")]
42    PushError(String),
43
44    /// A key custody operation failed for reasons other than key-not-found or
45    /// wrong-key-type.
46    #[error("custody error: {0}")]
47    CustodyError(String),
48}