#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms)]
extern crate alloc;
use alloc::vec::Vec;
use x509_cert::Certificate;
#[derive(Debug, Default)]
pub struct CertPool {
certs: Vec<Certificate>,
}
impl CertPool {
pub fn new() -> Self {
Self::default()
}
pub fn add(&mut self, cert: Certificate) {
self.certs.push(cert);
}
pub fn len(&self) -> usize {
self.certs.len()
}
pub fn is_empty(&self) -> bool {
self.certs.is_empty()
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
NoPathFound,
DepthExceeded,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::NoPathFound => f.write_str("no certification path found to a trust anchor"),
Error::DepthExceeded => f.write_str("path building exceeded maximum candidate depth"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;
pub fn build_path(
_target: &Certificate,
_pool: &CertPool,
_anchors: &[pkix_path::TrustAnchor],
) -> Result<Vec<Certificate>> {
Err(Error::NoPathFound)
}