pub struct Permissions {
pub print: bool,
pub modify: bool,
pub copy: bool,
pub annotate: bool,
pub fill_form: bool,
pub extract: bool,
pub assemble: bool,
pub print_high_quality: bool,
}Expand description
What a document’s security handler permits.
Eight questions, not a bitfield — a caller asks “may I print?”, never “is
bit 3 set?”. A struct of booleans rather than a bitflags-shaped newtype,
because the answers do not compose into a set.
The reserved bits are not dropped: Permissions::from_bits ignores
them and Permissions::bits reconstructs only the eight it knows, so a
writer that must reproduce a document’s /P verbatim keeps the original
word — which is what pdfrum-edit does, copying /Encrypt rather than
rebuilding it.
use pdfrum_crypt::Permissions;
// `/P -1` — every bit set, which is what an unrestricted document says.
// (The standard handler forces `0xFFFF_FFFC` for a `/P` of -4, which
// differs only in the two reserved low bits and decodes the same.)
let all = Permissions::from_bits(0xFFFF_FFFF);
assert_eq!(all, Permissions::ALL);
assert!(all.print);
// Bit 3 alone: printing, and nothing else.
let print_only = Permissions::from_bits(0b100);
assert!(print_only.print);
assert!(!print_only.copy);Fields§
§print: boolBit 3 — print the document.
Revision 3 and above qualify this: with print_high_quality clear,
printing is permitted only in a degraded form.
modify: boolBit 4 — modify the contents by operations other than those controlled by bits 6, 9 and 11.
copy: boolBit 5 — copy or otherwise extract text and graphics.
annotate: boolBit 6 — add or modify text annotations and fill in interactive form fields.
The table couples the two: a document granting this grants both. Bit 9
then grants form filling without annotation editing, which is why
fill_form is a separate field and not implied by this one.
fill_form: boolBit 9 — fill in interactive form fields, including signature fields, even when bit 6 is clear.
extract: boolBit 10 — extract text and graphics for accessibility.
assemble: boolBit 11 — assemble the document: insert, rotate or delete pages, and create bookmarks or thumbnails, even when bit 4 is clear.
print_high_quality: boolBit 12 — print at high resolution rather than as a degraded image.
Implementations§
Source§impl Permissions
impl Permissions
Sourcepub const ALL: Self
pub const ALL: Self
Every permission granted — an unencrypted document, and an owner-authenticated one.
Sourcepub const fn from_bits(bits: u32) -> Self
pub const fn from_bits(bits: u32) -> Self
Decode the /P word (ISO 32000-1 §7.6.4 table 22).
Reserved bits are ignored rather than refused: a damaged or forward-dated file sets bits this table does not name, and the answer to “may I print?” does not depend on them.
Sourcepub const fn bits(self) -> u32
pub const fn bits(self) -> u32
The eight bits back as a word, for a writer that must emit /P.
Not a round trip of from_bits: reserved bits the input carried
are not here, because this type never held them. A save that must
reproduce a document’s /P exactly keeps the original word instead —
which is what pdfrum-edit does today, copying the whole /Encrypt
dictionary.
Trait Implementations§
Source§impl Clone for Permissions
impl Clone for Permissions
Source§fn clone(&self) -> Permissions
fn clone(&self) -> Permissions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more