pub trait Validate {
    // Required method
    fn validate<W, E>(&self, warn: W, err: E) -> bool
       where W: FnMut(&str),
             E: FnMut(&str);

    // Provided method
    fn validate_to_vec(&self) -> (bool, Vec<String>, Vec<String>) { ... }
}
👎Deprecated since 0.13.0: please use X509StructureValidator instead
Available on crate feature validate only.
Expand description

Trait for validating item (for ex. validate X.509 structure)

§Examples

Using callbacks:

use x509_parser::certificate::X509Certificate;
use x509_parser::validate::Validate;
#[cfg(feature = "validate")]
fn validate_certificate(x509: &X509Certificate<'_>) -> Result<(), &'static str> {
    println!("  Subject: {}", x509.subject());
    // validate and print warnings and errors to stderr
    let ok = x509.validate(
        |msg| {
            eprintln!("  [W] {}", msg);
        },
        |msg| {
            eprintln!("  [E] {}", msg);
        },
    );
    print!("Structure validation status: ");
    if ok {
        println!("Ok");
        Ok(())
    } else {
        println!("FAIL");
        Err("validation failed")
    }
}

Collecting warnings and errors to Vec:

use x509_parser::certificate::X509Certificate;
use x509_parser::validate::Validate;

#[cfg(feature = "validate")]
fn validate_certificate(x509: &X509Certificate<'_>) -> Result<(), &'static str> {
    println!("  Subject: {}", x509.subject());
    // validate and print warnings and errors to stderr
    let (ok, warnings, errors) = x509.validate_to_vec();
    print!("Structure validation status: ");
    if ok {
        println!("Ok");
    } else {
        println!("FAIL");
    }
    for warning in &warnings {
        eprintln!("  [W] {}", warning);
    }
    for error in &errors {
        eprintln!("  [E] {}", error);
    }
    println!();
    if !errors.is_empty() {
        return Err("validation failed");
    }
    Ok(())
}

Required Methods§

source

fn validate<W, E>(&self, warn: W, err: E) -> bool
where W: FnMut(&str), E: FnMut(&str),

👎Deprecated since 0.13.0: please use X509StructureValidator instead

Attempts to validate current item.

Returns true if item was validated.

Call warn() if a non-fatal error was encountered, and err() if the error is fatal. These fucntions receive a description of the error.

Provided Methods§

source

fn validate_to_vec(&self) -> (bool, Vec<String>, Vec<String>)

👎Deprecated since 0.13.0: please use X509StructureValidator instead

Attempts to validate current item, storing warning and errors in Vec.

Returns the validation result (true if validated), the list of warnings, and the list of errors.

Object Safety§

This trait is not object safe.

Implementors§