ockam_identity/
error.rs

1use ockam_core::compat::string::String;
2use ockam_core::{
3    errcode::{Kind, Origin},
4    Error,
5};
6
7/// Identity crate error
8#[repr(u8)]
9#[derive(Clone, Debug)]
10pub enum IdentityError {
11    /// Invalid key type
12    InvalidKeyType = 1,
13    /// Invalid Key Data
14    InvalidKeyData,
15    /// Invalid Identifier format
16    InvalidIdentifier(String),
17    /// Identity Change History is empty
18    EmptyIdentity,
19    /// Identity Verification Failed
20    IdentityVerificationFailed,
21    /// PurposeKeyAttestation Verification Failed
22    PurposeKeyAttestationVerificationFailed,
23    /// Credential Verification Failed
24    CredentialVerificationFailed,
25    /// Unknown Authority
26    UnknownAuthority,
27    /// No CredentialRetriever
28    NoCredentialRetriever,
29    /// Unknown version of the Credential
30    UnknownCredentialVersion,
31    /// Invalid data_type value for Credential
32    InvalidCredentialDataType,
33    /// Unknown version of the Identity
34    UnknownIdentityVersion,
35    /// Invalid data_type value for Identity
36    InvalidIdentityDataType,
37    /// Unknown version of the PurposeKeyAttestation
38    UnknownPurposeKeyAttestationVersion,
39    /// Invalid data_type value for PurposeKeyAttestation
40    InvalidPurposeKeyAttestationDataType,
41    /// SecureChannelTrustCheckFailed
42    SecureChannelTrustCheckFailed,
43    /// Invalid Nonce value
44    InvalidNonce,
45    /// Nonce overflow
46    NonceOverflow,
47    /// Unknown message destination
48    UnknownChannelMsgDestination,
49    /// Duplicate Secure Channel
50    DuplicateSecureChannel,
51    /// Consistency Error
52    ConsistencyError,
53    /// Secret Key doesn't correspond to the Identity
54    WrongSecretKey,
55    /// CredentialRetriever was already set
56    CredentialRetrieverCreatorAlreadySet,
57    /// Credential is missing in the cache
58    CachedCredentialMissing,
59    /// Given address is already a subscriber for that RemoteCredentialRetriever
60    AddressAlreadySubscribedForThatCredentialRetriever,
61    /// Given address hasn't been subscribed for that RemoteCredentialRetriever
62    AddressIsNotSubscribedForThatCredentialRetriever,
63    /// Credential retriever couldn't return a credential
64    NoCredential,
65    /// Persistence is currently only supported for key exchange only channels
66    PersistentSupportIsLimited,
67    /// Secure Channel not found in the storage
68    PersistentSecureChannelNotFound,
69    /// Unknown Secure Channel Role value
70    UnknownRole,
71    /// Handshake ended up in an internal invalid state
72    HandshakeInternalError,
73}
74
75impl ockam_core::compat::error::Error for IdentityError {}
76
77impl core::fmt::Display for IdentityError {
78    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
79        core::fmt::Debug::fmt(self, f)
80    }
81}
82
83impl From<IdentityError> for Error {
84    #[track_caller]
85    fn from(err: IdentityError) -> Self {
86        // FIXME: fill these in with more meaningful error kinds
87        let kind = match err {
88            IdentityError::InvalidIdentifier(_) => Kind::Parse,
89            _ => Kind::Unknown,
90        };
91        Error::new(Origin::Identity, kind, err)
92    }
93}