Skip to main content

DocError

Enum DocError 

Source
#[non_exhaustive]
pub enum DocError {
Show 14 variants Io(Error), Encryption(EncryptionUnsupported), PasswordRequired, PasswordRequiresNormalisation, PasswordRequiredR6, Header(PdfError), Xref(XrefError), BadObject { id: ObjId, offset: u64, source: ParseError, }, ObjectIdMismatch { expected: ObjId, found: ObjId, offset: u64, }, ObjectStreamMissing { container: ObjId, num: u32, }, ObjectStream { container: ObjId, source: ObjStmError, }, ObjectStreamIdMismatch { container: ObjId, index: u32, expected: u32, found: u32, }, NoCatalog, Recovery(RecoverError),
}
Expand description

Errors from loading a document.

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.
§

Io(Error)

File I/O failed.

§

Encryption(EncryptionUnsupported)

The document is encrypted with a configuration pdfcer will not decrypt (§7.6). The inner error names which configuration and why — an unimplemented cipher, an unsourced algorithm, a different security handler, or a document no conforming reader may open at all.

Those are four different facts with four different next actions, which is why this is not one flat “encrypted files are unsupported”.

§

PasswordRequired

The document is encrypted with a configuration pdfcer can decrypt, but no password opened it.

§7.6.3.1 requires trying the empty user password first and silently, so reaching this error means the empty password was already tried and failed: the document genuinely has a non-empty user password. The caller should prompt and retry with Document::from_bytes_with_password.

N6: ISO 32000-1 states no error model here at all — no retry limit, no reporting requirement, nothing about distinguishing a wrong password from a malformed one. All of that is pdfcer policy.

§

PasswordRequiresNormalisation

Nothing authenticated, and the supplied password contains characters /R 5’s password preprocessing may have changed before hashing — so “wrong password” is not the only explanation.

The Adobe supplement’s step 1 applies SASLprep (RFC 4013) with the Normalize and BIDI options before the UTF-8 conversion. pdfcer implements the UTF-8 conversion and the 127-byte truncation exactly and does not implement SASLprep; neither RFC is staged in the project’s spec corpus, and a stringprep dependency was not taken for a read-only increment.

For an all-ASCII password SASLprep is the identity, so this error can never arise from one. pdfcer still attempts a non-ASCII password — SASLprep is the identity for much more than ASCII, and getting it wrong cannot open a document with a wrong key, only fail to open one with the right password. This variant exists so that failure does not masquerade as Self::PasswordRequired’s “you typed it wrong”, which would send the operator to re-check a password that was correct.

Reported only at /R 5. Password encoding below that is PDFDocEncoding (T8), a different unimplemented question.

§

PasswordRequiredR6

Authentication failed at handler revision 6 (AES-256 hardened), where the failure is not unambiguously “wrong password” (Pass 5.4).

/R 6’s key derivation (Algorithm 2.B) contains a genuine spec ambiguity — A13, the loop-exit test, which is internally inconsistent between steps (e) and (f) and produces a different digest (hence a different key, hence a failed authentication) depending on the reading. pdfcer defaults to the reading pypdf and Acrobat write (crate::crypto::r6::A13Reading::PerformThenTest); a document written by an implementation that took the other reading would fail here with a correct password. This variant names A13 so that failure is not reported as “you typed it wrong” (R169: a spec ambiguity is disclosed, never silently resolved). Raised only at /R 6.

§

Header(PdfError)

The %PDF- header probe failed — not a PDF.

§

Xref(XrefError)

The cross-reference machinery failed — a damaged/unreadable xref chain, or the deliberate /Encrypt capability-gap refusal (XrefErrorKind::EncryptionUnsupported).

§

BadObject

An indirect object at an xref-declared offset failed to parse.

Fields

§id: ObjId

The object the xref table pointed at.

§offset: u64

The offset the xref entry gave.

§source: ParseError

The underlying structural error.

§

ObjectIdMismatch

The object parsed at an offset doesn’t match the xref entry that pointed there (wrong number or generation) — the table and body disagree; strict Pass 1 refuses rather than guessing which is right.

Fields

§expected: ObjId

What the xref entry promised.

§found: ObjId

What the bytes at the offset declared.

§offset: u64

The offset in question.

§

ObjectStreamMissing

A type-2 cross-reference entry (§7.5.8.3) named an object stream that is not present as a loadable file-level object.

§7.5.7: “there shall be an entry for it in a cross-reference table or cross-reference stream” — so a missing container means the file’s own xref contradicts itself.

Fields

§container: ObjId

The container the type-2 entry named (generation always 0).

§num: u32

The object that was to be read from it.

§

ObjectStream

An object stream (§7.5.7) could not be decoded or read.

Fields

§container: ObjId

The container object stream.

§source: ObjStmError

What went wrong inside it.

§

ObjectStreamIdMismatch

The object number stored in an object stream’s pair table disagrees with the object number its type-2 cross-reference entry promised — the xref and the container contradict each other, and the strict loader refuses rather than picking one (the same posture as DocError::ObjectIdMismatch for file-level objects).

Fields

§container: ObjId

The container object stream.

§index: u32

The index within it that was read.

§expected: u32

The object number the type-2 entry promised.

§found: u32

The object number the pair table actually stored.

§

NoCatalog

The trailer has no usable /Root (Table 15 requires it; a conformant update trailer always repeats it — see the RAG’s gotcha on why fallback-to-older-trailers is a repair heuristic, not Pass 1 behavior).

§

Recovery(RecoverError)

Cross-reference recovery (decision 013) was attempted after the strict load failed, but could not produce a document — no confirmable objects, no /Catalog, or the entry cap. A named fail-clean refusal, never a partial/garbage document. (An encrypted recovered file is refused as XrefErrorKind::EncryptionUnsupported via DocError::Xref instead, matching the clean-path capability gap.)

Trait Implementations§

Source§

impl Debug for DocError

Source§

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

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

impl Display for DocError

Source§

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

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

impl Error for DocError

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<EncryptionUnsupported> for DocError

Source§

fn from(source: EncryptionUnsupported) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for DocError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<RecoverError> for DocError

Source§

fn from(source: RecoverError) -> Self

Converts to this type from the input type.
Source§

impl From<XrefError> for DocError

Source§

fn from(source: XrefError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for DocError

§

impl !UnwindSafe for DocError

§

impl Forget for DocError

§

impl Freeze for DocError
where *const () is !null: Freeze, PhantomData<ErrorData<CustomOwner>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, &'static str: Freeze,

§

impl Move for DocError

§

impl Send for DocError
where Repr: Send, RawVecInner: Send, &'static str: Send,

§

impl Sync for DocError
where Repr: Sync, RawVecInner: Sync,

§

impl Unpin for DocError
where *const () is !null: Unpin, &'static SimpleMessage: Unpin, *const Custom is !null: Unpin, *const u8 is !null: Unpin, &'static str: Unpin,

§

impl UnsafeUnpin for DocError
where *const () is !null: UnsafeUnpin, PhantomData<ErrorData<CustomOwner>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, &'static str: UnsafeUnpin,

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> 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> 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.