Skip to main content

Permissions

Struct Permissions 

Source
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

Source

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.

Source

pub const fn raw(&self) -> u32

The /P bits as an unsigned 32-bit value, unmasked.

Added in 0.2.0.

Source

pub const fn bits(&self) -> u32

The defined bits only: 3–6, plus 9–12 from revision 3 on.

Added in 0.2.0.

Source

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.

Source

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.

Source

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.

Source

pub const fn extract(&self) -> bool

Bit 5: copying or extracting text and graphics is allowed.

Added in 0.2.0.

Source

pub const fn annotate(&self) -> bool

Bit 6: adding or modifying annotations (and filling fields) is allowed.

Added in 0.2.0.

Source

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.

Source

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.

Source

pub const fn assemble(&self) -> bool

Bit 11 (R3+): assembling the document is allowed, “even if bit 4 is clear” (Table 22); bit 4 itself excludes assembly from R3 on. Under R2 assembly falls under bit 4.

Added in 0.2.0.

Trait Implementations§

Source§

impl Clone for Permissions

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 Permissions

Source§

impl Debug for Permissions

Source§

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

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

impl Eq for Permissions

Source§

impl Hash for Permissions

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Permissions

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 Permissions

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.