use once_cell::sync::Lazy;
#[cfg(not(feature = "std"))]
use crate::sync::RwLock;
#[cfg(feature = "std")]
use parking_lot::RwLock;
#[derive(Default)]
pub struct Config {
pub is_ephemeral_key_compressed: bool,
pub is_hkdf_key_compressed: bool,
}
pub static ECIES_CONFIG: Lazy<RwLock<Config>> = Lazy::new(|| {
let config: Config = Config::default();
RwLock::new(config)
});
pub fn update_config(config: Config) {
*ECIES_CONFIG.write() = config;
}
pub fn reset_config() {
update_config(Config::default())
}
pub fn is_ephemeral_key_compressed() -> bool {
ECIES_CONFIG.read().is_ephemeral_key_compressed
}
pub fn is_hkdf_key_compressed() -> bool {
ECIES_CONFIG.read().is_hkdf_key_compressed
}
#[cfg(all(not(feature = "x25519"), not(feature = "ed25519")))]
pub fn get_ephemeral_key_size() -> usize {
use crate::consts::{COMPRESSED_PUBLIC_KEY_SIZE, UNCOMPRESSED_PUBLIC_KEY_SIZE};
if is_ephemeral_key_compressed() {
COMPRESSED_PUBLIC_KEY_SIZE
} else {
UNCOMPRESSED_PUBLIC_KEY_SIZE
}
}
#[cfg(any(feature = "x25519", feature = "ed25519"))]
pub fn get_ephemeral_key_size() -> usize {
use crate::consts::PUBLIC_KEY_SIZE;
PUBLIC_KEY_SIZE
}