use crate::enums::{SignatureAlgorithm, SignatureScheme};
use crate::error::Error;
use pki_types::CertificateDer;
use alloc::boxed::Box;
use alloc::sync::Arc;
use alloc::vec::Vec;
use core::fmt::Debug;
pub trait SigningKey: Debug + Send + Sync {
fn choose_scheme(&self, offered: &[SignatureScheme]) -> Option<Box<dyn Signer>>;
fn algorithm(&self) -> SignatureAlgorithm;
}
pub trait Signer: Debug + Send + Sync {
fn sign(&self, message: &[u8]) -> Result<Vec<u8>, Error>;
fn scheme(&self) -> SignatureScheme;
}
#[derive(Clone, Debug)]
pub struct CertifiedKey {
pub cert: Vec<CertificateDer<'static>>,
pub key: Arc<dyn SigningKey>,
pub ocsp: Option<Vec<u8>>,
}
impl CertifiedKey {
pub fn new(cert: Vec<CertificateDer<'static>>, key: Arc<dyn SigningKey>) -> Self {
Self {
cert,
key,
ocsp: None,
}
}
pub fn end_entity_cert(&self) -> Result<&CertificateDer<'_>, Error> {
self.cert
.first()
.ok_or(Error::NoCertificatesPresented)
}
}