ring-native-ossl 0.1.10

A ring-compatible API backed by native-ossl (OpenSSL)
Documentation
//! Error types, mirroring `ring::error`.
//!
//! [`Unspecified`] is the general-purpose error type used throughout the crate
//! whenever the underlying OpenSSL failure reason must not be leaked to callers.
//! [`KeyRejected`] is returned when a key fails structural validation before any
//! cryptographic operation is attempted.

/// A detail-less error type, mirroring `ring::error::Unspecified`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Unspecified;

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

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

/// An error indicating that a key was rejected.
#[derive(Debug)]
pub struct KeyRejected(&'static str);

impl KeyRejected {
    pub(crate) fn new(reason: &'static str) -> Self {
        Self(reason)
    }

    #[must_use]
    pub fn description_when_internal(&self) -> &'static str {
        self.0
    }
}

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

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