interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / spki / src / error.rs

68 lines · 1885 bytes Raw Blame History
1//! Error types
2
3use core::fmt;
4use der::asn1::ObjectIdentifier;
5
6/// Result type with `spki` crate's [`Error`] type.
7pub type Result<T> = core::result::Result<T, Error>;
8
9#[cfg(feature = "pem")]
10use der::pem;
11
12/// Error type
13#[derive(Copy, Clone, Debug, Eq, PartialEq)]
14#[non_exhaustive]
15pub enum Error {
16 /// Algorithm parameters are missing.
17 AlgorithmParametersMissing,
18
19 /// ASN.1 DER-related errors.
20 Asn1(der::Error),
21
22 /// Malformed cryptographic key contained in a SPKI document.
23 ///
24 /// This is intended for relaying errors related to the raw data contained
25 /// in [`SubjectPublicKeyInfo::subject_public_key`][`crate::SubjectPublicKeyInfo::subject_public_key`].
26 KeyMalformed,
27
28 /// Unknown algorithm OID.
29 OidUnknown {
30 /// Unrecognized OID value found in e.g. a SPKI `AlgorithmIdentifier`.
31 oid: ObjectIdentifier,
32 },
33}
34
35impl fmt::Display for Error {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Error::AlgorithmParametersMissing => {
39 f.write_str("AlgorithmIdentifier parameters missing")
40 }
41 Error::Asn1(err) => write!(f, "ASN.1 error: {}", err),
42 Error::KeyMalformed => f.write_str("SPKI cryptographic key data malformed"),
43 Error::OidUnknown { oid } => {
44 write!(f, "unknown/unsupported algorithm OID: {}", oid)
45 }
46 }
47 }
48}
49
50impl From<der::Error> for Error {
51 fn from(err: der::Error) -> Error {
52 if let der::ErrorKind::OidUnknown { oid } = err.kind() {
53 Error::OidUnknown { oid }
54 } else {
55 Error::Asn1(err)
56 }
57 }
58}
59
60#[cfg(feature = "pem")]
61impl From<pem::Error> for Error {
62 fn from(err: pem::Error) -> Error {
63 der::Error::from(err).into()
64 }
65}
66
67#[cfg(feature = "std")]
68impl std::error::Error for Error {}