use candid::Principal;
pub type CertificateVerificationResult<T = ()> = Result<T, CertificateVerificationError>;
#[derive(thiserror::Error, Debug, Clone)]
pub enum CertificateVerificationError {
#[error(
"BLS DER-encoded public key must be {expected} bytes long, but is {actual} bytes long"
)]
DerKeyLengthMismatch {
expected: usize,
actual: usize,
},
#[error("BLS DER-encoded public key is invalid. Expected the following prefix: {expected:?}, but got {actual:?}")]
DerPrefixMismatch {
expected: Vec<u8>,
actual: Vec<u8>,
},
#[error("Certificate time is too far in the future. Received {certificate_time:?}, expected {max_certificate_time:?} or earlier")]
TimeTooFarInTheFuture {
certificate_time: u128,
max_certificate_time: u128,
},
#[error("Certificate time is too far in the past. Received {certificate_time:?}, expected {min_certificate_time:?} or later")]
TimeTooFarInThePast {
certificate_time: u128,
min_certificate_time: u128,
},
#[error(
"Canister ID {canister_id} is not within the certificate's range: {canister_ranges:?}"
)]
PrincipalOutOfRange {
canister_id: Principal,
canister_ranges: Vec<(Principal, Principal)>,
},
#[error("Subnet canister ID ranges not found in certificate at path: {path:?}")]
SubnetCanisterIdRangesNotFound {
path: Vec<Vec<u8>>,
},
#[error("Subnet public key not found in certificate at path: {path:?}")]
SubnetPublicKeyNotFound {
path: Vec<Vec<u8>>,
},
#[error(r#"Time not found in certificate at path: {path:?}"#)]
MissingTimePathInTree {
path: Vec<Vec<u8>>,
},
#[error("Certificate time decoding failed due to an overflow: {timestamp:?}")]
TimeDecodingFailed { timestamp: Vec<u8> },
#[error("Signature verification failed")]
SignatureVerificationFailed,
#[error("CBOR decoding failed")]
CborDecodingFailed(#[from] ic_cbor::CborError),
#[error("The certificate contained more than one delegation")]
CertificateHasTooManyDelegations,
}