pub struct Permissions { /* private fields */ }Expand description
The user access permissions of an encrypted document, from /P (ISO 32000-2 Table 22).
/P is read as a 32-bit two’s-complement value and only the defined bits are looked at
(§7.6.4.2; research ch. 04 §7.3). Under revision 2 the R3-only bits (9–12) don’t exist and
their operations follow bits 3–6, as qpdf and Acrobat interpret them.
These are a policy marker the file asks readers to honour, not access control: anyone who can open the file can decrypt it (research ch. 04 §7.5). Enforcing them is the caller’s choice.
use laminapdf_syntax::crypt::Permissions;
let p = Permissions::new(-3116, 4); // print, copy, form filling, accessibility; reserved bits set
assert!(p.print_low_res() && p.extract() && p.fill_forms() && p.accessibility());
assert!(!p.modify() && !p.print_high_res());Added in 0.2.0.
Implementations§
Source§impl Permissions
impl Permissions
Sourcepub const fn new(p: i64, revision: u8) -> Self
pub const fn new(p: i64, revision: u8) -> Self
Permissions from a /P value (any integer; its low 32 bits are used) and the handler’s
revision /R.
Added in 0.2.0.
Sourcepub const fn raw(&self) -> u32
pub const fn raw(&self) -> u32
The /P bits as an unsigned 32-bit value, unmasked.
Added in 0.2.0.
Sourcepub const fn bits(&self) -> u32
pub const fn bits(&self) -> u32
The defined bits only: 3–6, plus 9–12 from revision 3 on.
Added in 0.2.0.
Sourcepub const fn print_low_res(&self) -> bool
pub const fn print_low_res(&self) -> bool
Bit 3: printing is allowed (possibly only at low quality, see Self::print_high_res).
Added in 0.2.0.
Sourcepub const fn print_high_res(&self) -> bool
pub const fn print_high_res(&self) -> bool
Bits 3 and 12: faithful (high-quality) printing is allowed. Under R2, bit 3 alone.
Added in 0.2.0.
Sourcepub const fn modify(&self) -> bool
pub const fn modify(&self) -> bool
Bit 4: modifying the contents is allowed (other than by annotation, forms or assembly).
Added in 0.2.0.
Sourcepub const fn extract(&self) -> bool
pub const fn extract(&self) -> bool
Bit 5: copying or extracting text and graphics is allowed.
Added in 0.2.0.
Sourcepub const fn annotate(&self) -> bool
pub const fn annotate(&self) -> bool
Bit 6: adding or modifying annotations (and filling fields) is allowed.
Added in 0.2.0.
Sourcepub const fn fill_forms(&self) -> bool
pub const fn fill_forms(&self) -> bool
Bit 6 or (R3+) bit 9: filling existing form fields is allowed. Table 22: bit 6 allows filling fields, and bit 9 allows it “even if bit 6 is clear”. (qpdf’s “modify forms” reports bit 9 alone for R3+.)
Added in 0.2.0.
Sourcepub const fn accessibility(&self) -> bool
pub const fn accessibility(&self) -> bool
Bit 10: extraction for accessibility is allowed. Under R2, bit 5. (PDF 2.0 deprecates the bit and asks readers to treat it as set; this reports what the file says.)
Added in 0.2.0.