#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
use ffi::common::OQS_STATUS;
pub use oqs_sys as ffi;
mod macros;
#[cfg(feature = "std")]
pub fn init() {
use std::sync::Once;
static INIT: Once = Once::new();
INIT.call_once(|| {
unsafe { ffi::common::OQS_init() };
});
}
#[cfg(not(feature = "std"))]
pub fn init() {
unsafe { ffi::common::OQS_init() };
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
AlgorithmDisabled,
Error,
#[allow(clippy::upper_case_acronyms)]
ErrorExternalOpenSSL,
InvalidLength,
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::AlgorithmDisabled => write!(f, "OQS Error: Algorithm has been disabled"),
Error::ErrorExternalOpenSSL => write!(f, "OQS error: OpenSSL call failed"),
_ => write!(f, "OQS Error!"),
}
}
}
fn status_to_result(status: OQS_STATUS) -> Result<()> {
match status {
OQS_STATUS::OQS_SUCCESS => Ok(()),
OQS_STATUS::OQS_ERROR => Err(Error::Error),
OQS_STATUS::OQS_EXTERNAL_LIB_ERROR_OPENSSL => Err(Error::ErrorExternalOpenSSL),
}
}
pub mod kem;
pub mod sig;