use thiserror::Error;
use super::interface;
pub(crate) mod ec;
pub(crate) mod hmac;
pub(crate) mod okp;
pub(crate) mod rsa;
#[allow(dead_code)] #[derive(Debug, Error)]
pub(crate) enum BackendError {
#[error(transparent)]
OpenSsl(#[from] openssl::error::ErrorStack),
#[error("No prime data was found in private key")]
NoPrimeData,
#[error("openssl variant does not support feature: {0}")]
Unsupported(String),
}
#[derive(Debug)]
pub(crate) enum Backend {}
impl interface::Backend for Backend {
type EcPrivateKey = ec::PrivateKey;
type EcPublicKey = ec::PublicKey;
type EdPrivateKey = okp::PrivateKey;
type EdPublicKey = okp::PublicKey;
type Error = BackendError;
type HmacKey = hmac::Key;
type RsaPrivateKey = rsa::PrivateKey;
type RsaPublicKey = rsa::PublicKey;
fn fill_random(buf: &mut [u8]) -> Result<(), Self::Error> {
openssl::rand::rand_bytes(buf)?;
Ok(())
}
fn sha256(data: &[u8]) -> [u8; 32] {
openssl::sha::sha256(data)
}
fn sha384(data: &[u8]) -> [u8; 48] {
openssl::sha::sha384(data)
}
fn sha512(data: &[u8]) -> [u8; 64] {
openssl::sha::sha512(data)
}
}