Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 27 variants SignatureInvalid { index: usize, }, SignatureNotVerified { index: usize, reason: VerificationErrorKind, }, MalformedCertificate { index: usize, }, ValidityPeriod { index: usize, }, ChainBroken { index: usize, }, TrustAnchorRejected { defect: AnchorDefect, }, NoTrustedPath, PathTooLong, EkuNotPermittedByIssuer { index: usize, }, CaEmptySubject { index: usize, }, NotCA { index: usize, }, KeyUsageMissing { index: usize, }, CrlSignMissing { index: usize, }, UnhandledCriticalExtension { index: usize, }, NoRevAvailProfileViolation { index: usize, prohibition: NoRevAvailProhibition, }, NameConstraintViolation { index: usize, }, PolicyViolation { index: usize, }, Der(DerError), ValidityPeriodExceedsMax { index: usize, }, AlgorithmNotAllowed { index: usize, }, KeyTooSmall { index: usize, }, MissingSan, MissingRfc822San, MissingEku, MissingLeafPolicyOid { required: ObjectIdentifier, }, SubjectDnAttrRuleUnmet, DuplicateCertificate { first: usize, second: usize, },
}
Expand description

Errors returned by path validation.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

SignatureInvalid

Certificate signature verification failed at the given chain index: the signature does not verify, or is not a well-formed signature value (VerificationErrorKind::InvalidSignature).

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

SignatureNotVerified

The certificate’s signature could not be checked at the given chain index: the SignatureVerifier does not support its algorithm or the issuer’s key, or the issuer’s key is malformed. reason says which; it is never VerificationErrorKind::InvalidSignature.

Fields

§index: usize

Zero-based index into the chain slice of the certificate.

§reason: VerificationErrorKind

Why the verifier could not check the signature.

§

MalformedCertificate

A structural encoding error was found in a certificate.

Returned when the outer signatureAlgorithm OID differs from the inner TBSCertificate.signature OID (RFC 5280 §4.1.1.2; parameters are not compared, see check_oid_consistency for rationale), when a certificate carries more than one instance of an extension (RFC 5280 §4.2), and when a security-relevant extension fails to decode.

Fields

§index: usize

Zero-based index into the chain slice of the malformed certificate.

The underlying der::Error is intentionally not stored here to keep this variant no_std-compatible and to preserve the stable API shape. Callers that need the root-cause parse error should validate the DER certificate independently before calling validate_path.

§

ValidityPeriod

Certificate validity period check failed (expired or not yet valid).

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

ChainBroken

Issuer/subject name linkage is broken at the given chain index.

Fields

§index: usize

Zero-based index into the chain slice where the break was found.

§

TrustAnchorRejected

The trust anchor certificate itself does not satisfy the profile a CA certificate must meet, or is outside its validity period.

RFC 5280 §6.1 treats the anchor as an input and never examines it, so the literal algorithm accepts an expired root, a root with no BasicConstraints, and a root bearing an unrecognised critical extension. This workspace checks it anyway: a certificate’s own constraints are the issuer’s statement about what it may be used for, and honouring them belongs here rather than being left to whoever assembled the trust store.

Structural defects are caught when the anchor is built (TrustAnchor::from_cert), so a root that cannot be a CA never enters a trust store. AnchorDefect::Expired and AnchorDefect::NotYetValid depend on the clock and are therefore reported by validate_path.

§Which anchor this describes

The error names a defect, not an anchor, and several anchors may share a subject name. When more than one is outside its window – a rollover pair straddling the clock, with the old root past its notAfter and the new one short of its notBefore – AnchorDefect::Expired is reported, so the answer does not depend on the order the trust store supplied its anchors in.

An anchor skipped for its window is reported only when no anchor produced a more specific failure. A trust store holding an expired root beside an unrelated root of the same name whose signature check fails reports the signature failure, and the expiry does not appear. The specific error is the more useful one, but the expiry is not additionally reported.

Fields

§defect: AnchorDefect

Which requirement the anchor fails.

§

NoTrustedPath

No path from the subject certificate to any trust anchor was found.

§

PathTooLong

Path length exceeds ValidationPolicy::max_path_len.

§

EkuNotPermittedByIssuer

A CA in the path has an ExtendedKeyUsage that does not permit what is being asked of the chain below it. See ValidationPolicy::enforce_ca_eku.

Fields

§index: usize

Position of the CA whose ExtendedKeyUsage excludes it. This is the certificate that narrowed the permitted set to the point of failure, not the leaf that asked.

§

CaEmptySubject

A certificate that issues another in the path is a CA whose subject names nothing, against RFC 5280 §4.1.2.6.

Distinct from NotCA because the certificate does claim to be a CA; what it lacks is a name to be one under. See AnchorDefect::EmptySubject for why an empty DN on a CA is not merely non-conforming: §6.1.3(a)(4) name chaining compares DNs, and an empty DN matches an empty DN, so such a CA chains to any other certificate issued by any other unnamed CA.

Fields

§index: usize

Position of the offending certificate in the chain.

§

NotCA

An intermediate certificate is missing BasicConstraints cA=TRUE.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

KeyUsageMissing

An intermediate certificate has a KeyUsage extension with keyCertSign not set.

This error is only returned when a KeyUsage extension is present and the keyCertSign bit is explicitly absent or zero (RFC 5280 §6.1.4(n): “If a KeyUsage extension is present, verify that the keyCertSign bit is set.”).

Certificates with no KeyUsage extension are not rejected by this check; RFC 5280 does not require the extension to be present on CA certificates.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

CrlSignMissing

An intermediate certificate has a KeyUsage extension with cRLSign not set.

This error is only returned when ValidationPolicy::require_crl_sign_on_cas is true and the intermediate’s KeyUsage extension is present with the cRLSign bit explicitly absent or zero. Certificates with no KeyUsage extension are not rejected by this check (RFC 5280 does not require the extension to be present on CA certificates).

RFC 5280 §6.1 does not mandate this check; it is an opt-in policy that restores PKITS §4.7.4 / §4.7.5 conformance for callers who treat a CA cert without cRLSign as non-issuable. Default is off.

Disambiguation: pkix_revocation::Error::CrlSignMissing (same variant name, different crate) fires during CRL verification when the CRL signer cert lacks cRLSign (RFC 5280 §6.3.3(f)). This variant fires during path validation when an intermediate CA cert in the chain lacks cRLSign and the caller opted into the policy check.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

UnhandledCriticalExtension

A critical extension is present that this implementation does not handle.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

NoRevAvailProfileViolation

A certificate carries noRevAvail together with something RFC 9608 §3 forbids alongside it.

RFC 9608 §3 lists four prohibitions and ends: “If any of the above are violated in a certificate, then the relying party MUST consider the certificate invalid.” That sentence is addressed to a relying party rather than to an issuer, which is why this is a path-validation error and not only a lint finding.

§Why this is enforced even though pkix-path checks no revocation

noRevAvail asserts that no revocation information will ever be published. RFC 9608 §4 accordingly skips RFC 5280 §6.1.3 step (a)(3) for such a certificate, and pkix-chain implements that skip. §3 is the only thing that makes the skip safe: without it, any certificate carrying noRevAvail would escape revocation checking permanently. Enforcing it here — before any revocation work is driven, and whether or not the caller does any — keeps the guard with the thing it guards.

A certificate that contradicts itself this way is also one §6.1’s state machine cannot otherwise see: it asserts that no revocation information exists while naming where to fetch it, and two relying parties reading different halves reach different verdicts.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§prohibition: NoRevAvailProhibition

Which of RFC 9608 §3’s prohibitions the certificate violates.

§

NameConstraintViolation

Certificate name constraints violated (RFC 5280 §4.2.1.10); index is the 0-based chain position.

Also returned when a constraint is in effect for a name the validator cannot evaluate: a URI without an authority or with an IP-address host, a name of an unsupported form (otherName, ediPartyName, registeredID) under a constraint of that form, a non-IA5String subject emailAddress, or a SmtpUTF8Mailbox whose domain is not ASCII.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

PolicyViolation

Certificate policy validation failed (RFC 5280 §6.1.5(g)).

Returned when explicit_policy reaches zero and the valid policy tree is empty, meaning no acceptable certificate policy exists for the chain.

Fields

§index: usize

Zero-based index of the certificate where the violation was detected.

§

Der(DerError)

ASN.1 / DER encoding or decoding error.

Returned when a structural encoding error is found in a certificate or when re-encoding TBSCertificate for signature verification fails. Signature verification now uses heap-allocated encoding (no fixed size limit), so this error reflects a genuine DER encoding defect in the certificate, not an implementation size constraint.

The inner DerError is an opaque newtype; the underlying der::Error is intentionally not exposed so a future major-version bump in the der crate cannot cascade into a semver break here.

§

ValidityPeriodExceedsMax

A certificate’s validity period (notAfter − notBefore) exceeds ValidationPolicy::max_validity_secs.

This check fires for every certificate in the chain, not just the leaf.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

AlgorithmNotAllowed

A certificate’s signature algorithm OID is not in ValidationPolicy::allowed_signature_algs.

The check fires before signature verification so the error is diagnostic rather than a confusing SignatureInvalid.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

KeyTooSmall

An RSA public key’s modulus is smaller than ValidationPolicy::min_rsa_key_bits bits.

Non-RSA keys (EC, Ed25519, …) are not affected by this check.

Fields

§index: usize

Zero-based index into the chain slice of the failing certificate.

§

MissingSan

The leaf certificate (chain index 0) has no SubjectAltName extension, or the extension is present but empty.

Only checked when ValidationPolicy::require_subject_alt_name is true. Intermediate CA certificates are not subject to this check.

§

MissingRfc822San

The leaf certificate (chain index 0) has a SubjectAltName extension but none of its entries is an rfc822Name (email address).

Only checked when ValidationPolicy::require_rfc822_san is true. Intermediate CA certificates are not subject to this check.

§

MissingEku

The leaf certificate (chain index 0) does not assert all OIDs required by ValidationPolicy::required_leaf_eku.

anyExtendedKeyUsage (2.5.29.37.0) does not satisfy a specific OID requirement — each required OID must be listed explicitly.

§

MissingLeafPolicyOid

The leaf certificate’s CertificatePolicies extension does not assert a required policy OID from ValidationPolicy::required_leaf_policy_oids.

anyPolicy (2.5.29.32.0) does not satisfy a specific OID requirement; each required OID must be listed explicitly in the leaf’s CertificatePolicies extension.

Distinct from Error::PolicyViolation, which signals failure of the RFC 5280 §6.1 policy tree (initial_policy_set / initial_explicit_policy). MissingLeafPolicyOid signals a leaf-only assertion check that is independent of the policy tree.

Fields

§required: ObjectIdentifier

The required policy OID that the leaf does not assert.

§

SubjectDnAttrRuleUnmet

The leaf certificate’s Subject DN does not satisfy ValidationPolicy::required_leaf_subject_dn_attrs.

This variant carries no payload; richer “which branch of the rule failed” diagnostics are a non-breaking follow-up.

§

DuplicateCertificate

Two certificates in the chain share the same (issuer DN, serial number).

Per RFC 5280 §4.1.2.2, the combination of issuer DN and serial number uniquely identifies a certificate. A cert appearing twice at different chain positions is a construction error. Returned as a diagnostic rather than a confusing Error::SignatureInvalid or Error::ChainBroken.

Note: two certificates with the same public key but different issuer+serial are distinct certificates (e.g. cross-signed CAs) and are not rejected by this check.

first and second are the zero-based chain indices of the two duplicates.

Fields

§first: usize

First occurrence index.

§second: usize

Second occurrence index.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Error

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Error

Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl Hash for Error

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Error

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Forget for Error

§

impl Freeze for Error
where &'static str: Freeze, *const str is !null: Freeze, PhantomData<str>: Freeze,

§

impl Move for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error
where &'static str: Send, BoxRaw<str>: Send,

§

impl Sync for Error
where BoxRaw<str>: Sync,

§

impl Unpin for Error
where &'static str: Unpin, Box<str>: Unpin,

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error
where &'static str: UnwindSafe, BoxRaw<str>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.