Skip to main content

PermsCheck

Enum PermsCheck 

Source
pub enum PermsCheck {
    NotApplicable,
    Match,
    Mismatch {
        perms_p: u32,
        dict_p: u32,
        perms_encrypt_metadata: Option<bool>,
        dict_encrypt_metadata: bool,
    },
    MarkerMissing,
}
Expand description

The verdict of Algorithm 3.13 — the only integrity check in PDF encryption (negative result N7).

§Why this is reported and never acted on (T27)

/Perms is a 16-byte block holding an encrypted copy of /P and of /EncryptMetadata. At /V 1–4 those values sit in the file as editable plaintext with no protection at all; /Perms is the one place PDF binds them to the encryption key. That makes it the only thing in clause 7.6 that can detect tampering — and the supplement still states its verdict as should match, with no clause anywhere saying what to do when it does not.

pdfcer therefore reports the disagreement and prefers neither value:

  • It does not refuse the document. The spec’s modality is should, and every other reader opens the file; refusing would make pdfcer reject documents nothing else objects to, on the strength of a check the standard declines to require.
  • It does not silently substitute the decrypted /P for the dictionary’s. That is exactly the shape rule 4 forbids: a value pdfcer inferred to be more trustworthy, becoming what the operator is shown, with no disclosure. Permissions keeps reporting the dictionary /P — the value the file declares and the value every other viewer displays — and the disagreement is surfaced beside it through DocumentEncryption::perms.
  • It does not treat a mismatch as damage. Self::MarkerMissing is the case that means “the decryption itself is suspect”, and it is kept distinct for that reason.

Variants§

§

NotApplicable

There is no /Perms entry to check. /R ≤ 4 has none — the entry was introduced by ExtensionLevel 3 — so this is the ordinary answer for every RC4 and AES-128 document, and is not a negative result.

§

Match

Decrypted cleanly, the adb marker is present, and both recovered values agree with the plaintext dictionary.

§

Mismatch

Decrypted cleanly and the adb marker is present, but a recovered value disagrees with the dictionary.

The most likely innocent cause is a producer that edited /P without re-encrypting /Perms; the most likely non-innocent one is someone widening the permissions of a document they could not decrypt. Nothing in the file distinguishes those, which is precisely why pdfcer reports rather than decides.

Fields

§perms_p: u32

Bytes 0–3 of the decrypted block, little-endian: the permission flags as the encrypting producer recorded them.

§dict_p: u32

/P as it sits in the /Encrypt dictionary, unsigned (T10).

§perms_encrypt_metadata: Option<bool>

Byte 8: Some(true) for ASCII 'T', Some(false) for 'F', None for anything else — a third state the algorithm does not define and which must not be collapsed into false.

§dict_encrypt_metadata: bool

/EncryptMetadata as the dictionary states it (default true).

§

MarkerMissing

Decrypted, but bytes 9–11 are not the literal adb.

A different fact from Self::Mismatch: the marker is a fixed constant, so its absence means the decryption is wrong — a truncated or corrupted /Perms, or a file encryption key that is not the one this document was encrypted with. Since authentication has already succeeded by the time this runs, in practice it points at a damaged /Perms rather than at a wrong password.

Trait Implementations§

Source§

impl Clone for PermsCheck

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 Copy for PermsCheck

Source§

impl Debug for PermsCheck

Source§

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

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

impl Eq for PermsCheck

Source§

impl PartialEq for PermsCheck

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 StructuralPartialEq for PermsCheck

Auto Trait Implementations§

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