pub struct VerifyContext<'a> { /* private fields */ }Expand description
Verification builder/configuration.
Implementations§
Source§impl<'a> VerifyContext<'a>
impl<'a> VerifyContext<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a context with conservative defaults.
Defaults:
- no pre-set key, no key resolver
- manifests disabled
- same-document URIs only
- all transforms allowed
- pre-digest buffers not stored
Sourcepub fn key(self, key: &'a dyn VerifyingKey) -> Self
pub fn key(self, key: &'a dyn VerifyingKey) -> Self
Set a pre-resolved verification key.
Sourcepub fn key_resolver(self, resolver: &'a dyn KeyResolver) -> Self
pub fn key_resolver(self, resolver: &'a dyn KeyResolver) -> Self
Set a key resolver fallback used when key() is not provided.
Sourcepub fn process_manifests(self, enabled: bool) -> Self
pub fn process_manifests(self, enabled: bool) -> Self
Enable or disable <Manifest> processing.
When enabled, references in <ds:Manifest> elements that are direct
element children of <ds:Object> are processed only when the direct-child
<ds:Object> or <ds:Manifest> itself is referenced from <SignedInfo>
by an ID-based same-document fragment URI such as #id or
#xpointer(id('id')), and that reference uses only canonicalization
transforms (or implicit canonicalization). Filtering or binary transforms
do not prove that the complete Manifest structure was authenticated.
Only those signed Manifest references are returned in
VerifyResult::manifest_references.
Manifest parsing begins only after every <SignedInfo> reference digest
validates; a failure returns immediately with no Manifest results.
Nested <ds:Manifest> descendants under <ds:Object> are not
processed.
Direct-child unsigned/unreferenced Manifests are skipped and do not
appear in VerifyResult::manifest_references.
Whole-document same-document references such as URI="" or
URI="#xpointer(/)" do not mark a specific direct-child
<ds:Object>/<ds:Manifest> as signed for this option.
Manifests are parsed and processed only after the SignedInfo references
and SignatureValue both validate. Their digest mismatches, policy
violations, and processing failures are then reported independently in
VerifyResult::manifest_references and do not alter VerifyResult::status.
Callers that enable process_manifests(true) must inspect
VerifyResult::manifest_references in addition to VerifyResult::status
when interpreting verify() results.
Structural/parse errors in Manifest content abort verify() and are
returned as Err(...).
Sourcepub fn allowed_uri_types(self, types: UriTypeSet) -> Self
pub fn allowed_uri_types(self, types: UriTypeSet) -> Self
Restrict allowed reference URI classes.
Sourcepub fn allowed_transforms<I, S>(self, transforms: I) -> Self
pub fn allowed_transforms<I, S>(self, transforms: I) -> Self
Restrict allowed transform algorithms by URI.
Example values:
http://www.w3.org/2000/09/xmldsig#enveloped-signaturehttp://www.w3.org/2001/10/xml-exc-c14n#
When a <Reference> has no explicit canonicalization transform, XMLDSig
applies implicit default C14N (http://www.w3.org/TR/2001/REC-xml-c14n-20010315).
If an allowlist is configured, include that URI as well unless all
references use explicit Transform::C14n(...).
Sourcepub fn store_pre_digest(self, enabled: bool) -> Self
pub fn store_pre_digest(self, enabled: bool) -> Self
Store pre-digest buffers for diagnostics.
Sourcepub fn xpath_here_semantics(self, semantics: XPathHereSemantics) -> Self
pub fn xpath_here_semantics(self, semantics: XPathHereSemantics) -> Self
Select the node returned by XPath’s here() extension function.
The default follows XMLDSig and returns the <XPath> parameter.
Use XPathHereSemantics::XmlSecLegacy only for documents known to
have been generated with libxmlsec1’s <Transform> interpretation.
Sourcepub fn verify(&self, xml: &str) -> Result<VerifyResult, DsigError>
pub fn verify(&self, xml: &str) -> Result<VerifyResult, DsigError>
Verify one XMLDSig signature using this context.
Returns Ok(VerifyResult) for both valid and invalid signatures; inspect
VerifyResult::status for the core <SignedInfo> and signature-value
outcome. When Manifest processing is enabled, inspect every
VerifyResult::manifest_references entry separately. Err(...) is
reserved for pipeline failures.