pub struct Unspecified;
Expand description
An error with absolutely no details.
aws-lc-rs 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, aws_lc_rs::error::Unspecified>
is mostly equivalent to
Result<T, ()>
. However, aws_lc_rs::error::Unspecified
implements
std::error::Error
and users can implement
From<error::Unspecified>
to map this to their own error types, as
described in “Error Handling” in the Rust Book:
use aws_lc_rs::rand::{self, SecureRandom};
enum Error {
CryptoError,
IOError(std::io::Error),
// [...]
}
impl From<aws_lc_rs::error::Unspecified> for Error {
fn from(_: aws_lc_rs::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<aws_lc_rs::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 aws-lc-rs are encouraged to report such cases so that they can be addressed individually.
Trait Implementations§
Source§impl Clone for Unspecified
impl Clone for Unspecified
Source§fn clone(&self) -> Unspecified
fn clone(&self) -> Unspecified
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Unspecified
impl Debug for Unspecified
Source§impl Display for Unspecified
impl Display for Unspecified
Source§impl Error for Unspecified
impl Error for Unspecified
Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
Source§impl From<()> for Unspecified
impl From<()> for Unspecified
Source§impl From<EndOfInput> for Unspecified
Available on crate features ring-sig-verify
or ring-io
only.
impl From<EndOfInput> for Unspecified
ring-sig-verify
or ring-io
only.