pub struct DocumentEncryption {
pub config: EncryptionConfig,
pub auth: AuthKind,
pub perms: PermsCheck,
/* private fields */
}Fields§
§config: EncryptionConfigThe parsed /Encrypt dictionary.
auth: AuthKindWhich 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: PermsCheckThe 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
impl DocumentEncryption
Sourcepub fn edit_refusal(&self, bits: &[PermissionBit]) -> Option<EncryptedRefusal>
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.
Sourcepub fn refusal_cause(&self) -> EncryptedRefusal
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
impl DocumentEncryption
Sourcepub fn appendable(&self) -> bool
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.
Sourcepub fn uses_rc4(&self) -> bool
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).
Sourcepub fn rc4_append(&self) -> Rc4Append
pub fn rc4_append(&self) -> Rc4Append
The RC4 append policy in force; Rc4Append::Refuse unless
Document::set_rc4_append changed it.
Sourcepub fn grants(&self, bit: PermissionBit) -> bool
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.