synta-certificate 0.2.6

X.509 certificate structures for synta ASN.1 library
Documentation
//! Error types shared across the crypto submodules.

// ── PrivateKeyError ───────────────────────────────────────────────────────────

/// Type-erased error returned by [`PrivateKey`] operations.
///
/// Wraps a [`Box<dyn Error + Send + Sync>`] in a named struct so that the
/// `impl Error for PrivateKeyError` bound needed by
/// [`CertificateSigner::Error`](super::CertificateSigner::Error)
/// can be satisfied without ambiguity.
///
/// [`PrivateKey`]: super::PrivateKey
#[derive(Debug)]
pub struct PrivateKeyError(pub Box<dyn std::error::Error + Send + Sync + 'static>);

impl std::fmt::Display for PrivateKeyError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.0.fmt(f)
    }
}

impl std::error::Error for PrivateKeyError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        self.0.source()
    }
}

impl PrivateKeyError {
    /// Wrap any `Error + Send + Sync` value.
    pub fn new<E: std::error::Error + Send + Sync + 'static>(e: E) -> Self {
        Self(Box::new(e))
    }
}

// ── NoCryptoError ─────────────────────────────────────────────────────────────

/// Error returned by no-op sentinel crypto types when no backend is compiled in.
#[derive(Debug)]
pub struct NoCryptoError;

impl std::fmt::Display for NoCryptoError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(
            "no crypto backend configured; cannot decrypt PKCS#12 encrypted bags \
                     (enable the 'openssl' feature or provide a Pkcs12Decryptor)",
        )
    }
}

impl std::error::Error for NoCryptoError {}

// ── NoEncryptorError ──────────────────────────────────────────────────────────

/// Error returned by [`NoEncryptor`] and [`NoPkcs12Encryptor`].
///
/// [`NoEncryptor`]: super::NoEncryptor
/// [`NoPkcs12Encryptor`]: super::NoPkcs12Encryptor
#[derive(Debug)]
pub struct NoEncryptorError;

impl std::fmt::Display for NoEncryptorError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(
            "no crypto backend configured; cannot encrypt content \
             (enable the 'openssl' feature or provide an Encryptor implementation)",
        )
    }
}

impl std::error::Error for NoEncryptorError {}

// ── NoSignerError ─────────────────────────────────────────────────────────────

/// Error returned by [`NoSigner`].
///
/// [`NoSigner`]: super::NoSigner
#[derive(Debug)]
pub struct NoSignerError;

impl std::fmt::Display for NoSignerError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(
            "no certificate signer configured; cannot sign certificates \
             (enable the 'openssl' feature or provide a CertificateSigner implementation)",
        )
    }
}

impl std::error::Error for NoSignerError {}

// ── NoSignatureVerifierError ──────────────────────────────────────────────────

/// Error returned by [`NoSignatureVerifier`].
///
/// [`NoSignatureVerifier`]: super::NoSignatureVerifier
#[derive(Debug)]
pub struct NoSignatureVerifierError;

impl std::fmt::Display for NoSignatureVerifierError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(
            "no signature verifier configured; cannot verify certificate signatures \
             (enable the 'openssl' feature or provide a SignatureVerifier implementation)",
        )
    }
}

impl std::error::Error for NoSignatureVerifierError {}

// ── NoKeyIdHasherError ────────────────────────────────────────────────────────

/// Error returned by [`NoKeyIdHasher`].
///
/// [`NoKeyIdHasher`]: super::NoKeyIdHasher
#[derive(Debug)]
pub struct NoKeyIdHasherError;

impl std::fmt::Display for NoKeyIdHasherError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(
            "no crypto backend configured: enable the 'openssl' feature \
             for SubjectKeyIdentifier / AuthorityKeyIdentifier hashing",
        )
    }
}

impl std::error::Error for NoKeyIdHasherError {}

// ── NoEnvelopedDataDecryptorError ─────────────────────────────────────────────

/// Error returned by [`NoEnvelopedDataDecryptor`].
///
/// [`NoEnvelopedDataDecryptor`]: super::NoEnvelopedDataDecryptor
#[derive(Debug)]
pub struct NoEnvelopedDataDecryptorError;

impl std::fmt::Display for NoEnvelopedDataDecryptorError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(
            "no crypto backend configured; cannot decrypt EnvelopedData \
             (enable the 'openssl' feature or provide an EnvelopedDataDecryptor implementation)",
        )
    }
}

impl std::error::Error for NoEnvelopedDataDecryptorError {}