use num_bigint::{BigInt, BigUint};
use zeroize::Zeroize;
pub trait PublicKeyParts {
fn n(&self) -> &BigUint;
fn e(&self) -> &BigUint;
fn size(&self) -> usize {
(self.n().bits() + 7) / 8
}
}
pub trait PrivateKeyParts: PublicKeyParts {
fn d(&self) -> &BigUint;
fn primes(&self) -> &[BigUint];
fn dp(&self) -> Option<&BigUint>;
fn dq(&self) -> Option<&BigUint>;
fn qinv(&self) -> Option<&BigInt>;
fn crt_values(&self) -> Option<&[CrtValue]>;
}
#[derive(Debug, Clone)]
pub struct CrtValue {
pub(crate) exp: BigInt,
pub(crate) coeff: BigInt,
pub(crate) r: BigInt,
}
impl Zeroize for CrtValue {
fn zeroize(&mut self) {
self.exp.zeroize();
self.coeff.zeroize();
self.r.zeroize();
}
}
impl Drop for CrtValue {
fn drop(&mut self) {
self.zeroize();
}
}