Skip to main content

Permissions

Struct Permissions 

Source
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: bool

Bit 3 — print the document.

Revision 3 and above qualify this: with print_high_quality clear, printing is permitted only in a degraded form.

§modify: bool

Bit 4 — modify the contents by operations other than those controlled by bits 6, 9 and 11.

§copy: bool

Bit 5 — copy or otherwise extract text and graphics.

§annotate: bool

Bit 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: bool

Bit 9 — fill in interactive form fields, including signature fields, even when bit 6 is clear.

§extract: bool

Bit 10 — extract text and graphics for accessibility.

§assemble: bool

Bit 11 — assemble the document: insert, rotate or delete pages, and create bookmarks or thumbnails, even when bit 4 is clear.

§print_high_quality: bool

Bit 12 — print at high resolution rather than as a degraded image.

Implementations§

Source§

impl Permissions

Source

pub const ALL: Self

Every permission granted — an unencrypted document, and an owner-authenticated one.

Source

pub const NONE: Self

Nothing granted.

Source

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.

Source

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

Source§

fn clone(&self) -> Permissions

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: &Permissions) -> 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.