ockam_identity/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use ockam_core::compat::string::String;
use ockam_core::{
    errcode::{Kind, Origin},
    Error,
};

/// Identity crate error
#[repr(u8)]
#[derive(Clone, Debug)]
pub enum IdentityError {
    /// Invalid key type
    InvalidKeyType = 1,
    /// Invalid Key Data
    InvalidKeyData,
    /// Invalid Identifier format
    InvalidIdentifier(String),
    /// Identity Change History is empty
    EmptyIdentity,
    /// Identity Verification Failed
    IdentityVerificationFailed,
    /// PurposeKeyAttestation Verification Failed
    PurposeKeyAttestationVerificationFailed,
    /// Credential Verification Failed
    CredentialVerificationFailed,
    /// Unknown Authority
    UnknownAuthority,
    /// No CredentialRetriever
    NoCredentialRetriever,
    /// Unknown version of the Credential
    UnknownCredentialVersion,
    /// Invalid data_type value for Credential
    InvalidCredentialDataType,
    /// Unknown version of the Identity
    UnknownIdentityVersion,
    /// Invalid data_type value for Identity
    InvalidIdentityDataType,
    /// Unknown version of the PurposeKeyAttestation
    UnknownPurposeKeyAttestationVersion,
    /// Invalid data_type value for PurposeKeyAttestation
    InvalidPurposeKeyAttestationDataType,
    /// SecureChannelTrustCheckFailed
    SecureChannelTrustCheckFailed,
    /// Invalid Nonce value
    InvalidNonce,
    /// Nonce overflow
    NonceOverflow,
    /// Unknown message destination
    UnknownChannelMsgDestination,
    /// Duplicate Secure Channel
    DuplicateSecureChannel,
    /// Consistency Error
    ConsistencyError,
    /// Secret Key doesn't correspond to the Identity
    WrongSecretKey,
    /// CredentialRetriever was already set
    CredentialRetrieverCreatorAlreadySet,
    /// Credential is missing in the cache
    CachedCredentialMissing,
    /// Given address is already a subscriber for that RemoteCredentialRetriever
    AddressAlreadySubscribedForThatCredentialRetriever,
    /// Given address hasn't been subscribed for that RemoteCredentialRetriever
    AddressIsNotSubscribedForThatCredentialRetriever,
    /// Credential retriever couldn't return a credential
    NoCredential,
    /// Persistence is currently only supported for key exchange only channels
    PersistentSupportIsLimited,
    /// Secure Channel not found in the storage
    PersistentSecureChannelNotFound,
    /// Unknown Secure Channel Role value
    UnknownRole,
    /// Handshake ended up in an internal invalid state
    HandshakeInternalError,
}

impl ockam_core::compat::error::Error for IdentityError {}

impl core::fmt::Display for IdentityError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        core::fmt::Debug::fmt(self, f)
    }
}

impl From<IdentityError> for Error {
    #[track_caller]
    fn from(err: IdentityError) -> Self {
        let kind = Kind::Unknown; // FIXME: fill these in with more
                                  // meaningful error kinds
        Error::new(Origin::Identity, kind, err)
    }
}