#![cfg_attr(not(feature = "std"), no_std)]
#![deny(unsafe_code)]
#![deny(unused_qualifications)]
#[cfg(feature = "alloc")]
extern crate alloc;
pub mod algorithm_registry;
pub mod api;
pub mod error;
pub mod traits;
pub mod wasm_common;
#[cfg(feature = "alloc")]
pub mod aead_semantic;
#[cfg(feature = "alloc")]
pub mod contexts;
#[cfg(feature = "alloc")]
pub mod providers;
#[cfg(feature = "alloc")]
pub mod security;
#[cfg(feature = "wasm")]
pub mod wasm;
#[cfg(feature = "alloc")]
pub use aead_semantic::{
AeadDecryptSemantic,
DecryptSemanticOutcome,
};
pub use algorithm_registry::*;
pub use api::*;
#[cfg(feature = "alloc")]
pub use contexts::{
AeadContext,
HashContext,
KemContext,
SignatureContext,
};
pub use error::{
Error,
HexDecodeError,
Result,
};
#[cfg(feature = "alloc")]
pub use providers::LibQCryptoProvider;
#[cfg(feature = "alloc")]
pub use security::SecurityValidator;
pub use traits::*;
#[cfg(feature = "wasm")]
pub use wasm::*;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn init() -> Result<()> {
Ok(())
}
pub fn version() -> &'static str {
VERSION
}
#[cfg(feature = "alloc")]
pub fn create_hash_context() -> HashContext {
HashContext::new()
}
#[cfg(feature = "alloc")]
pub fn create_kem_context() -> KemContext {
KemContext::new()
}
#[cfg(feature = "alloc")]
pub fn create_signature_context() -> SignatureContext {
SignatureContext::new()
}
#[cfg(all(not(feature = "std"), feature = "no_std_panic_handler"))]
mod no_std_panic_handler {
use core::panic::PanicInfo;
#[panic_handler]
#[allow(clippy::empty_loop)]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_init() {
assert!(init().is_ok());
}
#[test]
fn test_version() {
assert!(!version().is_empty());
assert_eq!(version(), VERSION);
}
#[test]
fn test_no_std_compatibility() {
#[cfg(not(feature = "std"))]
use alloc::string::ToString;
let error = Error::InvalidKeySize {
expected: 32,
actual: 16,
};
assert_eq!(error.to_string(), "Invalid key size: expected 32, got 16");
#[cfg(feature = "alloc")]
{
let public_key = KemPublicKey::new(vec![1, 2, 3, 4]);
assert_eq!(public_key.as_bytes(), &[1, 2, 3, 4]);
let secret_key = KemSecretKey::new(vec![5, 6, 7, 8]);
assert_eq!(secret_key.as_bytes(), &[5, 6, 7, 8]);
}
}
}