#[cfg(feature = "alloc")]
use alloc::boxed::Box;
use crate::traits::{modular::ModulusParams, NonZero, UnsignedModularInt};
pub trait RawPrivateKeyConstructible: UnsignedModularInt {}
#[cfg(not(feature = "alloc"))]
impl<T> RawPrivateKeyConstructible for T where
T: crate::traits::modular::FixedWidthUnsignedInt + PartialOrd
{
}
pub trait PublicKeyParts<T: UnsignedModularInt> {
type MontyParams: ModulusParams<Modulus = T>;
fn n(&self) -> &NonZero<T>;
fn e(&self) -> &T;
fn size(&self) -> usize {
(self.n().bits() as usize).div_ceil(8)
}
fn n_params(&self) -> &Self::MontyParams;
fn n_bits_precision(&self) -> u32 {
self.n().bits_precision()
}
#[cfg(feature = "alloc")]
fn n_bytes(&self) -> Box<[u8]> {
self.n().to_be_bytes_trimmed_vartime()
}
#[cfg(feature = "alloc")]
fn e_bytes(&self) -> Box<[u8]> {
self.e().to_be_bytes_trimmed_vartime()
}
}
pub trait PrivateKeyParts<T>: PublicKeyParts<T>
where
T: UnsignedModularInt,
{
fn d(&self) -> &T;
#[cfg(feature = "alloc")]
fn primes(&self) -> &[T] {
&[]
}
#[cfg(feature = "alloc")]
fn dp(&self) -> Option<&T> {
None
}
#[cfg(feature = "alloc")]
fn dq(&self) -> Option<&T> {
None
}
#[cfg(feature = "alloc")]
fn qinv(&self) -> Option<&<Self::MontyParams as ModulusParams>::MontgomeryForm> {
None
}
#[cfg(feature = "alloc")]
fn p_params(&self) -> Option<&Self::MontyParams> {
None
}
#[cfg(feature = "alloc")]
fn q_params(&self) -> Option<&Self::MontyParams> {
None
}
}