ic_agent/identity/
error.rs

1use ic_transport_types::Delegation;
2use thiserror::Error;
3
4/// An error happened while reading a PEM file.
5#[cfg(feature = "pem")]
6#[derive(Error, Debug)]
7pub enum PemError {
8    /// An error occurred with disk I/O.
9    #[error(transparent)]
10    Io(#[from] std::io::Error),
11
12    /// An unsupported curve was detected
13    #[error("Only {0} curve is supported: {1:?}")]
14    UnsupportedKeyCurve(String, Vec<u8>),
15
16    /// An error occurred while reading the file in PEM format.
17    #[cfg(feature = "pem")]
18    #[error("An error occurred while reading the file: {0}")]
19    PemError(#[from] pem::PemError),
20
21    /// An error occurred while reading the file in DER format.
22    #[cfg(feature = "pem")]
23    #[error("An error occurred while reading the file: {0}")]
24    DerError(#[from] der::Error),
25
26    /// The private key is invalid.
27    #[error("Invalid private key: {0}")]
28    InvalidPrivateKey(String),
29
30    /// The key was rejected by k256.
31    #[error("A key was rejected by k256: {0}")]
32    ErrorStack(#[from] k256::pkcs8::Error),
33}
34
35/// An error occurred constructing a [`DelegatedIdentity`](super::delegated::DelegatedIdentity).
36#[derive(Error, Debug)]
37pub enum DelegationError {
38    /// Parsing error in delegation bytes.
39    #[error("A delegation could not be parsed")]
40    Parse,
41    /// A key in the chain did not match the signature of the next chain link.
42    #[error("A link was missing in the delegation chain")]
43    BrokenChain {
44        /// The key that should have matched the next delegation
45        from: Vec<u8>,
46        /// The delegation that didn't match, or `None` if the `Identity` didn't match
47        to: Option<Delegation>,
48    },
49    /// A key with an unknown algorithm was used. The IC supports Ed25519, secp256k1, and prime256v1, and in ECDSA the curve must be specified.
50    #[error("The delegation chain contained a key with an unknown algorithm")]
51    UnknownAlgorithm,
52    /// One of `Identity`'s functions returned an error.
53    #[error("A delegated-to identity encountered an error: {0}")]
54    IdentityError(String),
55}