1#[derive(Debug, thiserror::Error)]
2pub enum CoseKeyError {
3 #[cfg(feature = "p256")]
4 #[error("Invalid P256 key")]
5 InvalidP256Key,
6 #[cfg(feature = "p384")]
7 #[error("Invalid P384 key")]
8 InvalidP384Key,
9 #[cfg(feature = "bls")]
10 #[error(transparent)]
11 BlsSignatureError(#[from] bls_signatures::Error),
12 #[error("Public encoded point does not match")]
13 MismatchPrivateKey,
14 #[error("Invalid KeyType")]
15 InvalidKty,
16 #[error("Unknown algorithm '{0:?}'. Algorithms need to be IANA assigned")]
17 UnknownAlg(coset::Algorithm),
18 #[error("A COSE key must have an algorithm")]
19 MissingAlg,
20 #[error("Unknown elliptic curve '{0}'")]
21 UnknownCurve(i64),
22 #[error("Expected the KeyConfirmation to be of type '{0}' but was '{1}'")]
23 InvalidAlg(i64, i64),
24 #[error("Missing 'crv' claim")]
25 MissingCrv,
26 #[error("Missing EC point '{0}'")]
27 MissingPoint(&'static str),
28 #[error("Invalid key length ; expected '{0}' got '{1}'")]
29 InvalidKeyLength(usize, usize),
30 #[error("{0}")]
31 InvalidCborIntegerClaimKey(core::num::TryFromIntError),
32 #[error(transparent)]
33 CborDeserializationError(#[from] ciborium::de::Error<std::io::Error>),
34 #[error(transparent)]
35 CborSerializationError(#[from] ciborium::ser::Error<std::io::Error>),
36 #[error(transparent)]
37 CborValueError(#[from] ciborium::value::Error),
38 #[cfg(feature = "pem")]
39 #[error(transparent)]
40 Pkcs8Error(#[from] pkcs8::spki::Error),
41 #[error("Signature error {0}")]
42 SignatureError(String),
43 #[error(transparent)]
44 InfallibleError(#[from] core::convert::Infallible),
45}
46
47#[cfg(feature = "ed25519")]
48impl From<ed25519_dalek::SignatureError> for CoseKeyError {
49 fn from(e: ed25519_dalek::SignatureError) -> Self {
50 Self::SignatureError(format!("{e:?}"))
51 }
52}