#![cfg(feature = "crypto")]
#![cfg_attr(docsrs, doc(cfg(feature = "crypto")))]
use {
crate::{crypto, global::error::*},
std::io::Read,
};
#[cfg(feature = "compression")]
pub use super::global::compressor::Compressor;
#[inline(always)]
pub fn gen_keypair() -> crypto::SigningKey {
let bytes = [0u8; 32].map(|_| simplerand::rand());
crypto::SigningKey::from_bytes(&bytes)
}
pub fn read_keypair<R: Read>(mut handle: R) -> InternalResult<crypto::SigningKey> {
let mut keypair_bytes = [0; crate::SECRET_KEY_LENGTH + crate::PUBLIC_KEY_LENGTH];
handle.read_exact(&mut keypair_bytes)?;
crypto::SigningKey::from_keypair_bytes(&keypair_bytes).map_err(|err| InternalError::ParseError(err.to_string()))
}
pub fn read_verifying_key<T: Read>(mut handle: T) -> InternalResult<crypto::VerifyingKey> {
let mut keypair_bytes = [0; crate::PUBLIC_KEY_LENGTH];
handle.read_exact(&mut keypair_bytes)?;
crypto::VerifyingKey::from_bytes(&keypair_bytes).map_err(|err| InternalError::ParseError(err.to_string()))
}
pub fn read_secret_key<T: Read>(mut handle: T) -> InternalResult<crypto::SigningKey> {
let mut secret_bytes = [0; crate::SECRET_KEY_LENGTH];
handle.read_exact(&mut secret_bytes)?;
Ok(crypto::SigningKey::from_bytes(&secret_bytes))
}