Skip to main content

ring_native_ossl/
error.rs

1//! Error types, mirroring `ring::error`.
2//!
3//! [`Unspecified`] is the general-purpose error type used throughout the crate
4//! whenever the underlying OpenSSL failure reason must not be leaked to callers.
5//! [`KeyRejected`] is returned when a key fails structural validation before any
6//! cryptographic operation is attempted.
7
8/// A detail-less error type, mirroring `ring::error::Unspecified`.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct Unspecified;
11
12impl std::fmt::Display for Unspecified {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        f.write_str("Unspecified")
15    }
16}
17
18impl std::error::Error for Unspecified {}
19
20/// An error indicating that a key was rejected.
21#[derive(Debug)]
22pub struct KeyRejected(&'static str);
23
24impl KeyRejected {
25    pub(crate) fn new(reason: &'static str) -> Self {
26        Self(reason)
27    }
28
29    #[must_use]
30    pub fn description_when_internal(&self) -> &'static str {
31        self.0
32    }
33}
34
35impl std::fmt::Display for KeyRejected {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        write!(f, "KeyRejected: {}", self.0)
38    }
39}
40
41impl std::error::Error for KeyRejected {}