mod check;
mod scope;
mod selection;
pub use check::check;
pub use scope::Scope;
use crate::binary::Location;
use crate::credential::{Checked, Credential, ParticipantCredentials};
use crate::reference::VisitError;
use crate::xml::{Access, AccessError, Snapshot, Xml};
use structured_asn1::memory::{MemoryError, OwnedVec, Work};
use structured_ltv::baseline::CredentialMaterial;
use structured_ltv::material::{ArchiveError, ArtifactRef, IndexError};
use structured_ltv::timestamp::{ObligationError, TimestampScope};
#[derive(Clone, Copy)]
pub enum Need<'value, 'document, N, D, G> {
Known(ArtifactRef<'value, 'document>),
Open(Location<N, D, G>),
Missing,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Completeness {
Complete,
Unsupported,
Unprocessed,
Unusable,
Malformed,
}
pub trait Provider<X: Xml, A> {
type Error;
fn visit<VE, W: Work>(
&self,
credential: &Checked<'_, '_, A, X::Id, X::Document, X::Generation>,
open: &[super::Opaque<X::Id, X::Document, X::Generation>],
access: &Access<'_, X, W>,
visitor: impl for<'value, 'document> FnMut(
Need<'value, 'document, X::Id, X::Document, X::Generation>,
) -> Result<(), VE>,
) -> Result<Completeness, VisitError<Self::Error, VE>>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Missing {
Absent,
Uncovered,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Finding {
pub dependency: usize,
pub cause: Missing,
}
pub struct Entry<N, D, G> {
source: Credential<N, D, G>,
completeness: Completeness,
findings: OwnedVec<Finding>,
}
impl<N: Copy, D: Copy, G: Copy> Entry<N, D, G> {
#[must_use]
pub fn source(&self) -> Credential<N, D, G> {
self.source
}
#[must_use]
pub fn completeness(&self) -> Completeness {
self.completeness
}
#[must_use]
pub fn findings(&self) -> &[Finding] {
&self.findings
}
}
pub struct Report<'auth, 'path, 'document, A, N, D, G> {
credentials: &'auth ParticipantCredentials<'path, 'document, A, N, D, G>,
scope: TimestampScope<N, D, G>,
entries: OwnedVec<Entry<N, D, G>>,
complete: bool,
}
impl<'auth, 'path, 'document, A, N: Copy, D: Copy, G: Copy>
Report<'auth, 'path, 'document, A, N, D, G>
{
#[must_use]
pub fn credentials(&self) -> &'auth ParticipantCredentials<'path, 'document, A, N, D, G> {
self.credentials
}
#[must_use]
pub fn scope(&self) -> TimestampScope<N, D, G> {
self.scope
}
#[must_use]
pub fn entries(&self) -> &[Entry<N, D, G>] {
&self.entries
}
#[must_use]
pub fn all_requirements_met(&self) -> bool {
self.complete
}
#[must_use]
pub fn snapshot(&self) -> Snapshot<D, G> {
self.credentials.snapshot()
}
}
impl<'path, 'document, A, N: Copy, D: Copy, G: Copy> CredentialMaterial
for Report<'_, 'path, 'document, A, N, D, G>
{
type Id = N;
type Document = D;
type Generation = G;
type Credentials = ParticipantCredentials<'path, 'document, A, N, D, G>;
fn scope(&self) -> TimestampScope<N, D, G> {
self.scope
}
fn snapshot(&self) -> Snapshot<D, G> {
self.credentials.snapshot()
}
fn credentials(&self) -> &Self::Credentials {
self.credentials
}
fn all_requirements_met(&self) -> bool {
self.complete
}
}
#[derive(Debug)]
pub enum Error<E, PE, N> {
Foreign {
node: N,
},
Access(AccessError<E, N>),
Obligation(ObligationError<N>),
Index(IndexError<N>),
Archive(ArchiveError<N>),
Provider {
node: N,
cause: PE,
},
Resource {
node: N,
cause: MemoryError,
},
CallbackProtocol {
node: N,
},
}
pub type CheckResult<'auth, 'path, 'document, X, A, PE> = Result<
Report<
'auth,
'path,
'document,
A,
<X as Xml>::Id,
<X as Xml>::Document,
<X as Xml>::Generation,
>,
Error<<X as Xml>::Error, PE, <X as Xml>::Id>,
>;
pub(super) type ProcessingResult<T, X, PE> =
Result<T, Error<<X as Xml>::Error, PE, <X as Xml>::Id>>;