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§

source§

impl Clone for Unspecified

source§

fn clone(&self) -> Unspecified

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Unspecified

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Unspecified

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<EndOfInput> for Unspecified

source§

fn from(_: EndOfInput) -> Self

Converts to this type from the input type.
source§

impl From<KeyRejected> for Unspecified

source§

fn from(_: KeyRejected) -> Self

Converts to this type from the input type.
source§

impl From<TryFromSliceError> for Unspecified

source§

fn from(_: TryFromSliceError) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Unspecified> for Unspecified

source§

fn eq(&self, other: &Unspecified) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Unspecified

source§

impl StructuralPartialEq for Unspecified

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.