Skip to main content

DocumentEncryption

Struct DocumentEncryption 

Source
pub struct DocumentEncryption {
    pub config: EncryptionConfig,
    pub auth: AuthKind,
    pub perms: PermsCheck,
    /* private fields */
}

Fields§

§config: EncryptionConfig

The parsed /Encrypt dictionary.

§auth: AuthKind

Which password opened it. AuthKind::EmptyUser is the no-prompt case — the document had an empty user password, which every conforming reader tries silently before prompting.

§perms: PermsCheck

The Algorithm 3.13 /Perms verdict — the only integrity check in PDF encryption, and a should, not a shall.

PermsCheck::NotApplicable for every /R ≤ 4 document, where the entry does not exist. That is the ordinary answer, not a failed check, and a front end must not render it as one.

§Why it is here rather than acted on

/Perms holds an encrypted copy of /P and /EncryptMetadata. The plaintext copies sit in the /Encrypt dictionary where anyone can edit them, with no integrity protection anywhere else in clause 7.6 (N7). So a disagreement is the one signal PDF gives that a document’s stated permissions are not the ones its encryptor recorded — and no clause says what to do about it.

pdfcer reports it and prefers neither value: EncryptionConfig::permissions keeps returning the dictionary’s /P, because that is what the file declares and what every other viewer shows, and this field carries the disagreement beside it. Silently substituting the decrypted copy would be pdfcer deciding, on an inference, what the operator is told — the exact shape project rule 4 forbids. Refusing the document would reject files nothing else objects to, on the strength of a check the standard declines to require. See PermsCheck’s own docs (T27).

Implementations§

Source§

impl DocumentEncryption

Source

pub fn edit_refusal(&self, bits: &[PermissionBit]) -> Option<EncryptedRefusal>

Why an edit governed by any of bits would be refused, or None when it is allowed. This is the test every editing verb applies, so a shell can ask before calling one.

Editing verbs and the bits they need: annotation verbs need Annotate; fills and form-data import need FillForms or Annotate; page insert, delete, rotate, reorder, labels, merge and outline items need Assemble; everything else needs ModifyContents.

Source

pub fn refusal_cause(&self) -> EncryptedRefusal

The cause of an encryption refusal a verb has already returned, when the shell does not know which permission that verb needs.

A refusal under an RC4 policy that does not allow saving is reported as Rc4NotAllowed — allowing RC4 is then necessary for every edit, though a permission refusal may remain after it. Otherwise the refusal can only have come from the password, so it is PermissionDenied. Call it only after a refusal: it does not test whether an edit is allowed (use edit_refusal for that).

Source§

impl DocumentEncryption

Source

pub fn appendable(&self) -> bool

Whether an incremental save can append under this document’s key. false for an RC4 document unless Document::set_rc4_append opted in: pdfcer never chooses RC4 (decision 190), so crate::writer::save_incremental refuses it with crate::writer::WriteError::Rc4AppendRefused.

Source

pub fn uses_rc4(&self) -> bool

Whether strings or streams are encrypted with RC4 (/V 1–2, or a /V 4 crypt filter with /CFM /V2; ISO 32000-2 §7.6.2).

Source

pub fn rc4_append(&self) -> Rc4Append

The RC4 append policy in force; Rc4Append::Refuse unless Document::set_rc4_append changed it.

Source

pub fn grants(&self, bit: PermissionBit) -> bool

Whether bit lets the operator who opened the document do what it governs (ISO 32000-2 Table 22). The owner password grants everything; a user (or empty-user) open is held to the declared /P. A bit the document’s revision does not define is not granted.

Trait Implementations§

Source§

impl Clone for DocumentEncryption

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 DocumentEncryption

Source§

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

Formats the value using the given formatter. Read more

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.