Struct ring::error::Unspecified
source · [−]pub struct Unspecified;
Expand description
An error with absolutely no details.
ring uses this unit type as the error type in most of its results because (a) usually the specific reasons for a failure are obvious or are not useful to know, and/or (b) providing more details about a failure might provide a dangerous side channel, and/or (c) it greatly simplifies the error handling logic.
Result<T, ring::error::Unspecified>
is mostly equivalent to
Result<T, ()>
. However, ring::error::Unspecified
implements
std::error::Error
and users of ring can implement
From<ring::error::Unspecified>
to map this to their own error types, as
described in “Error Handling” in the Rust Book:
use ring::rand::{self, SecureRandom};
enum Error {
CryptoError,
IOError(std::io::Error),
// [...]
}
impl From<ring::error::Unspecified> for Error {
fn from(_: ring::error::Unspecified) -> Self { Error::CryptoError }
}
fn eight_random_bytes() -> Result<[u8; 8], Error> {
let rng = rand::SystemRandom::new();
let mut bytes = [0; 8];
// The `From<ring::error::Unspecified>` implementation above makes this
// equivalent to
// `rng.fill(&mut bytes).map_err(|_| Error::CryptoError)?`.
rng.fill(&mut bytes)?;
Ok(bytes)
}
assert!(eight_random_bytes().is_ok());
Experience with using and implementing other crypto libraries like has shown that sophisticated error reporting facilities often cause significant bugs themselves, both within the crypto library and within users of the crypto library. This approach attempts to minimize complexity in the hopes of avoiding such problems. In some cases, this approach may be too extreme, and it may be important for an operation to provide some details about the cause of a failure. Users of ring are encouraged to report such cases so that they can be addressed individually.
Trait Implementations
sourceimpl Clone for Unspecified
impl Clone for Unspecified
sourcefn clone(&self) -> Unspecified
fn clone(&self) -> Unspecified
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for Unspecified
impl Debug for Unspecified
sourceimpl Display for Unspecified
impl Display for Unspecified
sourceimpl Error for Unspecified
impl Error for Unspecified
sourcefn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
replaced by Error::source, which can support downcasting
sourcefn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
sourceimpl From<EndOfInput> for Unspecified
impl From<EndOfInput> for Unspecified
sourcefn from(_: EndOfInput) -> Self
fn from(_: EndOfInput) -> Self
Performs the conversion.
sourceimpl From<KeyRejected> for Unspecified
impl From<KeyRejected> for Unspecified
sourcefn from(_: KeyRejected) -> Self
fn from(_: KeyRejected) -> Self
Performs the conversion.
sourceimpl From<TryFromSliceError> for Unspecified
impl From<TryFromSliceError> for Unspecified
sourcefn from(_: TryFromSliceError) -> Self
fn from(_: TryFromSliceError) -> Self
Performs the conversion.
sourceimpl PartialEq<Unspecified> for Unspecified
impl PartialEq<Unspecified> for Unspecified
impl Copy for Unspecified
impl StructuralPartialEq for Unspecified
Auto Trait Implementations
impl RefUnwindSafe for Unspecified
impl Send for Unspecified
impl Sync for Unspecified
impl Unpin for Unspecified
impl UnwindSafe for Unspecified
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more