#![deny(missing_docs)]
#![deny(warnings)]
#![allow(clippy::double_must_use)]
#![deny(unsafe_code)]
#[macro_use]
mod macros;
#[allow(unsafe_code)]
mod boringssl;
#[cfg(any(doc, feature = "bytes"))]
#[forbid(unsafe_code)]
pub mod bytes;
#[forbid(unsafe_code)]
pub mod hash;
#[forbid(unsafe_code)]
pub mod hmac;
#[cfg(any(doc, feature = "insecure"))]
#[forbid(unsafe_code)]
pub mod insecure;
#[cfg(any(doc, feature = "insecure"))]
#[forbid(unsafe_code)]
mod insecure_rc4;
#[cfg(any(doc, feature = "kdf"))]
#[forbid(unsafe_code)]
pub mod kdf;
#[forbid(unsafe_code)]
pub mod password;
#[forbid(unsafe_code)]
pub mod public;
#[forbid(unsafe_code)]
mod util;
use std::fmt::{self, Debug, Display, Formatter};
use boringssl::BoringError;
pub struct Error(ErrorInner);
impl Error {
fn new(s: String) -> Error {
Error(ErrorInner::Mundane(s))
}
}
#[doc(hidden)]
impl From<BoringError> for Error {
fn from(err: BoringError) -> Error {
Error(ErrorInner::Boring(err))
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
match &self.0 {
ErrorInner::Mundane(err) => write!(f, "{}", err),
ErrorInner::Boring(err) => write!(f, "boringssl: {}", err),
}
}
}
impl Debug for Error {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
match &self.0 {
ErrorInner::Mundane(err) => write!(f, "{}", err),
ErrorInner::Boring(err) => {
if err.stack_depth() == 1 {
write!(f, "boringssl: {:?}", err)
} else {
write!(f, "boringssl:\n{:?}", err)
}
}
}
}
}
impl std::error::Error for Error {}
enum ErrorInner {
Mundane(String),
Boring(BoringError),
}
#[cfg(test)]
mod tests {
use super::Error;
#[test]
fn test_send() {
fn assert_send<T: Send>() {}
assert_send::<Error>();
}
#[test]
fn test_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<Error>();
}
}