Skip to main content

SecurityHandler

Struct SecurityHandler 

Source
pub struct SecurityHandler { /* private fields */ }
Expand description

PDF Standard Security Handler — holds the derived encryption key and methods for decrypting strings and streams.

Implementations§

Source§

impl SecurityHandler

Source

pub fn from_encrypt_dict<S: PdfSource>( encrypt_dict: &HashMap<Name, Object>, store: &ObjectStore<S>, password: &str, file_id: &[u8], ) -> Result<Self, SecurityError>

Build a SecurityHandler from the /Encrypt dictionary, verifying the password against the stored owner/user hashes.

encrypt_dict is the resolved encryption dictionary. file_id is the first element of the trailer /ID array.

Source

pub fn permissions(&self) -> Permissions

Return the document access permissions stored in the /P entry.

Source

pub fn get_permissions(&self) -> Permissions

Upstream-aligned alias for Self::permissions().

Corresponds to CPDF_SecurityHandler::GetPermissions() in PDFium.

Source

pub fn encoded_password(&self) -> &[u8]

Returns the successfully-verified encoded password bytes.

For R2–R4, this is the Latin-1 encoded user password (or the recovered user password when authenticated as owner). For R5/R6, this is the UTF-8 encoded password. Useful for incremental save with the same password.

Corresponds to CPDF_SecurityHandler::GetEncodedPassword() in PDFium.

Source

pub fn get_encoded_password(&self) -> &[u8]

ADR-019 alias for encoded_password().

Corresponds to CPDF_SecurityHandler::GetEncodedPassword() in PDFium.

Source

pub fn decrypt_string(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8>

Decrypt a string value belonging to the given object.

Source

pub fn decrypt_stream(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8>

Decrypt stream data belonging to the given object.

Source

pub fn is_metadata_encrypted(&self) -> bool

Returns true if metadata streams are encrypted.

Corresponds to CPDF_SecurityHandler::IsMetadataEncrypted() in PDFium.

Source

pub fn revision(&self) -> u32

The encryption revision number.

Source

pub fn crypt_filter_method(&self) -> CryptFilterMethod

The crypt filter method in use (returns stream filter for backwards compat).

Source

pub fn key_length_bytes(&self) -> usize

The encryption key length in bytes.

Source

pub fn encryption_key(&self) -> &[u8]

The raw encryption key.

Source

pub fn stream_crypt_filter(&self) -> CryptFilterMethod

The stream crypt filter method.

Source

pub fn string_crypt_filter(&self) -> CryptFilterMethod

The string crypt filter method.

Source

pub fn o_value(&self) -> &[u8]

The /O value (owner hash) from the encrypt dictionary.

Source

pub fn u_value(&self) -> &[u8]

The /U value (user hash) from the encrypt dictionary.

Source

pub fn version(&self) -> u32

The encryption version number (V value).

Derived from the revision: R2→V1, R3/R4→V2..V4, R5/R6→V5.

Source

pub fn encrypt_string(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8>

Encrypt a string value belonging to the given object.

RC4 is symmetric (encrypt = decrypt). For AES, a zero IV is used and prepended to the ciphertext (matching PDF convention where the first 16 bytes of the encrypted data are the IV).

Source

pub fn encrypt_stream(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8>

Encrypt stream data belonging to the given object.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more