use alloc::vec::Vec;
use secrecy::SecretSlice;
use crate::{crypto::Result, jwa};
#[derive(Clone)]
pub(crate) struct PrivateKeyPrimeComponents {
pub p: SecretSlice<u8>,
pub q: SecretSlice<u8>,
pub dp: SecretSlice<u8>,
pub dq: SecretSlice<u8>,
pub qi: SecretSlice<u8>,
}
#[derive(Clone)]
pub(crate) struct PrivateKeyComponents {
pub d: SecretSlice<u8>,
pub prime: PrivateKeyPrimeComponents,
}
#[derive(Clone, PartialEq, Eq)]
pub(crate) struct PublicKeyComponents {
pub n: Vec<u8>,
pub e: Vec<u8>,
}
pub(crate) trait PrivateKey: Sized {
type Signature: Into<Vec<u8>> + AsRef<[u8]>;
type PublicKey: PublicKey;
fn generate(bits: usize) -> Result<Self>;
fn from_components(private: PrivateKeyComponents, public: PublicKeyComponents) -> Result<Self>;
fn to_public_key(&self) -> Self::PublicKey;
fn private_components(&self) -> Result<PrivateKeyComponents>;
fn public_components(&self) -> PublicKeyComponents;
fn sign(&mut self, alg: jwa::RsaSigning, data: &[u8]) -> Result<Self::Signature>;
}
pub(crate) trait PublicKey: Sized {
fn from_components(components: PublicKeyComponents) -> Result<Self>;
fn components(&self) -> PublicKeyComponents;
fn verify(&mut self, alg: jwa::RsaSigning, msg: &[u8], signature: &[u8]) -> Result<bool>;
}