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

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The item to validate

Attempts to validate current item. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.