pub enum X509Error {
Show 22 variants Generic, InvalidVersion, InvalidSerial, InvalidAlgorithmIdentifier, InvalidX509Name, InvalidDate, InvalidSPKI, InvalidSubjectUID, InvalidIssuerUID, InvalidExtensions, InvalidAttributes, DuplicateExtensions, DuplicateAttributes, InvalidSignatureValue, InvalidTbsCertificate, InvalidUserCertificate, InvalidCertificate, SignatureVerificationError, SignatureUnsupportedAlgorithm, InvalidNumber, Der(BerError), NomError(ErrorKind),
}
Expand description

An error that can occur while parsing or validating a certificate.

Variants

Generic

InvalidVersion

InvalidSerial

InvalidAlgorithmIdentifier

InvalidX509Name

InvalidDate

InvalidSPKI

InvalidSubjectUID

InvalidIssuerUID

InvalidExtensions

InvalidAttributes

DuplicateExtensions

DuplicateAttributes

InvalidSignatureValue

InvalidTbsCertificate

InvalidUserCertificate

InvalidCertificate

Top-level certificate structure is invalid

SignatureVerificationError

SignatureUnsupportedAlgorithm

InvalidNumber

Der(BerError)

NomError(ErrorKind)

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The lower-level source of this error, if any. Read more

🔬 This is a nightly-only experimental API. (backtrace)

Returns a stack backtrace, if available, of where this error occurred. Read more

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Parse a DER-encoded X.509 Certificate, and return the remaining of the input and the built object.

The returned object uses zero-copy, and so has the same lifetime as the input.

Note that only parsing is done, not validation.

Certificate  ::=  SEQUENCE  {
        tbsCertificate       TBSCertificate,
        signatureAlgorithm   AlgorithmIdentifier,
        signatureValue       BIT STRING  }
Example

To parse a certificate and print the subject and issuer:

let res = parse_x509_certificate(DER);
match res {
    Ok((_rem, x509)) => {
        let subject = x509.subject();
        let issuer = x509.issuer();
        println!("X.509 Subject: {}", subject);
        println!("X.509 Issuer: {}", issuer);
    },
    _ => panic!("x509 parsing failed: {:?}", res),
}

Parse a DER-encoded TbsCertificate object

TBSCertificate  ::=  SEQUENCE  {
     version         [0]  Version DEFAULT v1,
     serialNumber         CertificateSerialNumber,
     signature            AlgorithmIdentifier,
     issuer               Name,
     validity             Validity,
     subject              Name,
     subjectPublicKeyInfo SubjectPublicKeyInfo,
     issuerUniqueID  [1]  IMPLICIT UniqueIdentifier OPTIONAL,
                          -- If present, version MUST be v2 or v3
     subjectUniqueID [2]  IMPLICIT UniqueIdentifier OPTIONAL,
                          -- If present, version MUST be v2 or v3
     extensions      [3]  Extensions OPTIONAL
                          -- If present, version MUST be v3 --  }

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Extension  ::=  SEQUENCE  {
    extnID      OBJECT IDENTIFIER,
    critical    BOOLEAN DEFAULT FALSE,
    extnValue   OCTET STRING  }

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

CertificateList  ::=  SEQUENCE  {
     tbsCertList          TBSCertList,
     signatureAlgorithm   AlgorithmIdentifier,
     signatureValue       BIT STRING  }

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

CertificationRequest ::= SEQUENCE {
    certificationRequestInfo CertificationRequestInfo,
    signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }},
    signature          BIT STRING
}

Attempt to parse input bytes into a DER object (enforcing constraints)

Parse the SubjectPublicKeyInfo struct portion of a DER-encoded X.509 Certificate

Parse the X.501 type Name, used for ex in issuer and subject of a X.509 certificate

CertificationRequestInfo ::= SEQUENCE {
     version       INTEGER { v1(0) } (v1,...),
     subject       Name,
     subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }},
     attributes    [0] Attributes{{ CRIAttributes }}
}

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Attempt to parse input bytes into a DER object (enforcing constraints)

Creates an error from the input position and an ErrorKind

Combines an existing error with a new one created from the input position and an ErrorKind. This is useful when backtracking through a parse tree, accumulating error context on the way Read more

Creates an error from an input position and an expected character

Combines two existing errors. This function is used to compare errors generated in various branches of alt. Read more

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error Read more

Maps a function over the result of a parser

Creates a second parser from the output of the first one, then apply over the rest of the input

Applies a second parser over the output of the first one

Applies a second parser after the first one, return their results as a tuple

Applies a second parser over the input if the first one failed

automatically converts the parser’s output and error values to another type, as long as they implement the From trait Read more

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error Read more

Maps a function over the result of a parser

Creates a second parser from the output of the first one, then apply over the rest of the input

Applies a second parser over the output of the first one

Applies a second parser after the first one, return their results as a tuple

Applies a second parser over the input if the first one failed

automatically converts the parser’s output and error values to another type, as long as they implement the From trait Read more

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error Read more

Maps a function over the result of a parser

Creates a second parser from the output of the first one, then apply over the rest of the input

Applies a second parser over the output of the first one

Applies a second parser after the first one, return their results as a tuple

Applies a second parser over the input if the first one failed

automatically converts the parser’s output and error values to another type, as long as they implement the From trait Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

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.