pub(crate) mod backend;
pub mod ec;
pub mod hmac;
pub mod okp;
pub mod rsa;
use core::{error, fmt};
use backend::interface;
use self::backend::Backend;
pub type Result<T, E = Error> = core::result::Result<T, E>;
pub struct Error {
inner: <Backend as interface::Backend>::Error,
}
impl fmt::Display for Error {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.inner, _f)
}
}
impl fmt::Debug for Error {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.inner, _f)
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
error::Error::source(&self.inner)
}
}
impl<E> From<E> for Error
where
<Backend as interface::Backend>::Error: From<E>,
{
fn from(err: E) -> Self {
Self {
inner: <Backend as interface::Backend>::Error::from(err),
}
}
}
#[inline]
#[expect(unused)] pub(crate) fn fill_random(buf: &mut [u8]) -> Result<()> {
<Backend as interface::Backend>::fill_random(buf).map_err(|e| Error { inner: e })
}
#[inline]
pub(crate) fn sha256(data: &[u8]) -> [u8; 32] {
<Backend as interface::Backend>::sha256(data)
}
#[inline]
pub(crate) fn sha384(data: &[u8]) -> [u8; 48] {
<Backend as interface::Backend>::sha384(data)
}
#[inline]
pub(crate) fn sha512(data: &[u8]) -> [u8; 64] {
<Backend as interface::Backend>::sha512(data)
}