#![cfg_attr(not(feature = "std"), no_std)]
#![doc = include_str!("../README.md")]
extern crate alloc;
pub mod baseline;
pub mod basic;
pub mod counters;
pub mod credential;
pub mod material;
pub mod participants;
pub mod prepare;
pub mod preservation;
pub mod properties;
pub mod source;
pub mod timestamp;
#[derive(Debug)]
pub enum Error {
Cms(structured_cms::Error),
Encoding {
field: &'static str,
cause: structured_asn1::Error,
},
Pkix(structured_pkix::Error),
Syntax {
code: structured_cms::ErrorCode,
field: &'static str,
at: u64,
},
Resource {
at: u64,
cause: structured_asn1::memory::MemoryError,
field: &'static str,
},
Foreign {
at: u64,
},
}
impl Error {
pub(crate) fn resource(
cause: structured_asn1::memory::MemoryError,
field: &'static str,
at: u64,
) -> Self {
Self::Resource { at, cause, field }
}
pub(crate) fn encoding(cause: structured_asn1::Error, field: &'static str) -> Self {
Self::Encoding { cause, field }
}
#[must_use]
pub fn is_terminal(&self) -> bool {
match self {
Self::Cms(error) => error.is_terminal(),
Self::Encoding { cause, .. } => {
cause.is_resource() || cause.code() == structured_asn1::ErrorCode::TagTooLarge
}
Self::Pkix(error) => {
error.is_resource() || error.code() == structured_pkix::ErrorCode::ForeignReader
}
Self::Resource { .. } | Self::Foreign { .. } => true,
Self::Syntax { .. } => false,
}
}
#[must_use]
pub fn offset(&self) -> u64 {
match self {
Self::Cms(error) => error.offset(),
Self::Encoding { cause, .. } => cause.offset(),
Self::Pkix(error) => error.offset(),
Self::Resource { at, .. } | Self::Foreign { at } | Self::Syntax { at, .. } => *at,
}
}
#[must_use]
pub fn field(&self) -> Option<&'static str> {
match self {
Self::Cms(cause) => Some(cause.field()),
Self::Pkix(cause) => Some(cause.field()),
Self::Encoding { field, .. }
| Self::Syntax { field, .. }
| Self::Resource { field, .. } => Some(*field),
Self::Foreign { .. } => None,
}
}
}
impl From<structured_cms::Error> for Error {
fn from(cause: structured_cms::Error) -> Self {
Self::Cms(cause)
}
}
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Level {
Basic,
Timestamped,
LongTerm,
Archival,
}
#[derive(Debug, Clone, Copy)]
pub struct Cades(());
pub(crate) const ISSUER: Cades = Cades(());