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§
source§impl Debug for X509StructureValidator
impl Debug for X509StructureValidator
source§impl Default for X509StructureValidator
impl Default for X509StructureValidator
source§fn default() -> X509StructureValidator
fn default() -> X509StructureValidator
Returns the “default value” for a type. Read more
source§impl<'a> Validator<'a> for X509StructureValidator
impl<'a> Validator<'a> for X509StructureValidator
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§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more