use std::array::TryFromSliceError;
#[derive(Debug)]
pub enum Error {
Serialization,
TimestampElapsed,
InvalidPublicKey,
InvalidPrivateKey,
PSQGenerationError,
PSQDerivationError,
CredError,
RegistrationError,
CryptoError,
OsError,
Decoding,
}
#[cfg(debug_assertions)]
fn print_error(m: &str, e: &impl std::fmt::Debug) {
use std::backtrace;
eprintln!("{m} {e:?}");
let bt = backtrace::Backtrace::capture();
eprintln!("{bt}");
}
impl From<libcrux_kem::Error> for Error {
fn from(_e: libcrux_kem::Error) -> Self {
#[cfg(debug_assertions)]
print_error("KEM error", &_e);
Self::CryptoError
}
}
impl From<libcrux_chacha20poly1305::AeadError> for Error {
fn from(_e: libcrux_chacha20poly1305::AeadError) -> Self {
#[cfg(debug_assertions)]
print_error("Chacha20Poly1305 error", &_e);
Self::CryptoError
}
}
impl From<libcrux_hkdf::ExtractError> for Error {
fn from(_e: libcrux_hkdf::ExtractError) -> Self {
#[cfg(debug_assertions)]
print_error("HKDF error", &_e);
Self::CryptoError
}
}
impl From<libcrux_hkdf::ExpandError> for Error {
fn from(_e: libcrux_hkdf::ExpandError) -> Self {
#[cfg(debug_assertions)]
print_error("HKDF error", &_e);
Self::CryptoError
}
}
impl From<TryFromSliceError> for Error {
fn from(_e: TryFromSliceError) -> Self {
#[cfg(debug_assertions)]
print_error("TryFromSliceError", &_e);
Self::CryptoError
}
}
const PSK_LENGTH: usize = 32;
type Psk = [u8; PSK_LENGTH];
pub mod cred;
pub mod impls;
pub mod psk_registration;
pub mod traits;