pub struct EncryptionHandler { /* private fields */ }Expand description
PDF Encryption Handler
Implementations§
Source§impl EncryptionHandler
impl EncryptionHandler
Sourcepub fn new(
encrypt_dict: &PdfDictionary,
file_id: Option<Vec<u8>>,
) -> ParseResult<Self>
pub fn new( encrypt_dict: &PdfDictionary, file_id: Option<Vec<u8>>, ) -> ParseResult<Self>
Create encryption handler from encryption dictionary
Sourcepub fn detect_encryption(trailer: &PdfDictionary) -> bool
pub fn detect_encryption(trailer: &PdfDictionary) -> bool
Check if PDF is encrypted by looking for Encrypt entry in trailer
Sourcepub fn unlock_with_user_password(&mut self, password: &str) -> ParseResult<bool>
pub fn unlock_with_user_password(&mut self, password: &str) -> ParseResult<bool>
Try to unlock PDF with user password
Sourcepub fn unlock_with_owner_password(
&mut self,
password: &str,
) -> ParseResult<bool>
pub fn unlock_with_owner_password( &mut self, password: &str, ) -> ParseResult<bool>
Try to unlock PDF with owner password
Owner password authentication works by:
- Deriving an RC4 key from the owner password
- Decrypting the O entry to recover the user password
- Using the recovered user password to compute the encryption key
Sourcepub fn try_empty_password(&mut self) -> ParseResult<bool>
pub fn try_empty_password(&mut self) -> ParseResult<bool>
Try to unlock with empty password (common case)
Sourcepub fn is_unlocked(&self) -> bool
pub fn is_unlocked(&self) -> bool
Check if the PDF is currently unlocked
Sourcepub fn encryption_key(&self) -> Option<&EncryptionKey>
pub fn encryption_key(&self) -> Option<&EncryptionKey>
Get the current encryption key (if unlocked)
Sourcepub fn decrypt_string(
&self,
data: &[u8],
obj_id: &ObjectId,
) -> ParseResult<Vec<u8>>
pub fn decrypt_string( &self, data: &[u8], obj_id: &ObjectId, ) -> ParseResult<Vec<u8>>
Decrypt a string object.
Uses the error-propagating try_* variant so an AES decryption failure
surfaces as an error rather than silently yielding empty content (#364).
Sourcepub fn decrypt_stream(
&self,
data: &[u8],
obj_id: &ObjectId,
) -> ParseResult<Vec<u8>>
pub fn decrypt_stream( &self, data: &[u8], obj_id: &ObjectId, ) -> ParseResult<Vec<u8>>
Decrypt a stream object.
Uses the error-propagating try_* variant so an AES decryption failure
surfaces as an error rather than silently yielding empty content (#364).
Sourcepub fn algorithm_info(&self) -> String
pub fn algorithm_info(&self) -> String
Get encryption algorithm information
Sourcepub fn permissions(&self) -> Permissions
pub fn permissions(&self) -> Permissions
Get permissions information
Sourcepub fn has_file_id(&self) -> bool
pub fn has_file_id(&self) -> bool
Check if file ID is available
Sourcepub fn encrypt_strings(&self) -> bool
pub fn encrypt_strings(&self) -> bool
Check if strings should be encrypted
Sourcepub fn encrypt_streams(&self) -> bool
pub fn encrypt_streams(&self) -> bool
Check if streams should be encrypted
Sourcepub fn encrypt_metadata(&self) -> bool
pub fn encrypt_metadata(&self) -> bool
Check if metadata should be encrypted (R4 only)