Struct x509_parser::validate::X509StructureValidator
source · [−]pub struct X509StructureValidator;
Available on crate feature
validate
only.Expand description
Default X.509 structure validator for X509Certificate
This Validator
iterates the X.509 Certificate fields, and verifies the
DER encoding and structure:
- numbers with wrong encoding/sign (for ex. serial number)
- strings with characters not allowed in DER type (for ex. ‘*’ in
PrintableString
)
Examples
Validate structure, collect warnings and errors to a Vec
:
use x509_parser::certificate::X509Certificate;
use x509_parser::validate::*;
#[cfg(feature = "validate")]
fn validate_certificate(x509: &X509Certificate<'_>) -> Result<(), &'static str> {
let mut logger = VecLogger::default();
println!(" Subject: {}", x509.subject());
// validate and print warnings and errors to stderr
let ok = X509StructureValidator.validate(&x509, &mut logger);
print!("Structure validation status: ");
if ok {
println!("Ok");
} else {
println!("FAIL");
}
for warning in logger.warnings() {
eprintln!(" [W] {}", warning);
}
for error in logger.errors() {
eprintln!(" [E] {}", error);
}
println!();
if !logger.errors().is_empty() {
return Err("validation failed");
}
Ok(())
}
Trait Implementations
sourceimpl Debug for X509StructureValidator
impl Debug for X509StructureValidator
sourceimpl Default for X509StructureValidator
impl Default for X509StructureValidator
sourcefn default() -> X509StructureValidator
fn default() -> X509StructureValidator
Returns the “default value” for a type. Read more
sourceimpl<'a> Validator<'a> for X509StructureValidator
impl<'a> Validator<'a> for X509StructureValidator
type Item = X509Certificate<'a>
type Item = X509Certificate<'a>
The item to validate
sourcefn validate<L: Logger>(&self, item: &'a Self::Item, l: &mut L) -> bool
fn validate<L: Logger>(&self, item: &'a Self::Item, l: &mut L) -> bool
Attempts to validate current item. Read more
fn chain<V2>(self, v2: V2) -> ChainValidator<'a, Self, V2, Self::Item> where
Self: Sized,
V2: Validator<'a, Item = Self::Item>,
Auto Trait Implementations
impl RefUnwindSafe for X509StructureValidator
impl Send for X509StructureValidator
impl Sync for X509StructureValidator
impl Unpin for X509StructureValidator
impl UnwindSafe for X509StructureValidator
Blanket Implementations
sourceimpl<'a, T, E> AsTaggedExplicit<'a, E> for T where
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for T where
T: 'a,
sourceimpl<'a, T, E> AsTaggedImplicit<'a, E> for T where
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for T where
T: 'a,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more