use ic_transport_types::Delegation;
use thiserror::Error;
#[cfg(feature = "pem")]
#[derive(Error, Debug)]
pub enum PemError {
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("Only {0} curve is supported: {1:?}")]
UnsupportedKeyCurve(String, Vec<u8>),
#[cfg(feature = "pem")]
#[error("An error occurred while reading the file: {0}")]
PemError(#[from] pem::PemError),
#[cfg(feature = "pem")]
#[error("An error occurred while reading the file: {0}")]
DerError(#[from] pkcs8::der::Error),
#[error("Invalid private key: {0}")]
InvalidPrivateKey(String),
#[error("A key was rejected by k256: {0}")]
ErrorStack(#[from] k256::pkcs8::Error),
}
#[derive(Error, Debug)]
pub enum DelegationError {
#[error("A delegation could not be parsed")]
Parse,
#[error("A link was missing in the delegation chain")]
BrokenChain {
from: Vec<u8>,
to: Option<Delegation>,
},
#[error("The delegation chain contained a key with an unknown algorithm")]
UnknownAlgorithm,
#[error("A canister signature in the delegation chain could not be verified: {0}")]
InvalidCanisterSignature(String),
#[error("A delegated-to identity encountered an error: {0}")]
IdentityError(String),
}