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
impl SecurityHandler
Sourcepub fn from_encrypt_dict<S: PdfSource>(
encrypt_dict: &HashMap<Name, Object>,
store: &ObjectStore<S>,
password: &str,
file_id: &[u8],
) -> Result<Self, SecurityError>
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.
Sourcepub fn permissions(&self) -> Permissions
pub fn permissions(&self) -> Permissions
Return the document access permissions stored in the /P entry.
Sourcepub fn get_permissions(&self) -> Permissions
pub fn get_permissions(&self) -> Permissions
Upstream-aligned alias for Self::permissions().
Corresponds to CPDF_SecurityHandler::GetPermissions() in PDFium.
Sourcepub fn encoded_password(&self) -> &[u8] ⓘ
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.
Sourcepub fn get_encoded_password(&self) -> &[u8] ⓘ
pub fn get_encoded_password(&self) -> &[u8] ⓘ
ADR-019 alias for encoded_password().
Corresponds to CPDF_SecurityHandler::GetEncodedPassword() in PDFium.
Sourcepub fn decrypt_string(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8> ⓘ
pub fn decrypt_string(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8> ⓘ
Decrypt a string value belonging to the given object.
Sourcepub fn decrypt_stream(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8> ⓘ
pub fn decrypt_stream(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8> ⓘ
Decrypt stream data belonging to the given object.
Sourcepub fn is_metadata_encrypted(&self) -> bool
pub fn is_metadata_encrypted(&self) -> bool
Returns true if metadata streams are encrypted.
Corresponds to CPDF_SecurityHandler::IsMetadataEncrypted() in PDFium.
Sourcepub fn crypt_filter_method(&self) -> CryptFilterMethod
pub fn crypt_filter_method(&self) -> CryptFilterMethod
The crypt filter method in use (returns stream filter for backwards compat).
Sourcepub fn key_length_bytes(&self) -> usize
pub fn key_length_bytes(&self) -> usize
The encryption key length in bytes.
Sourcepub fn encryption_key(&self) -> &[u8] ⓘ
pub fn encryption_key(&self) -> &[u8] ⓘ
The raw encryption key.
Sourcepub fn stream_crypt_filter(&self) -> CryptFilterMethod
pub fn stream_crypt_filter(&self) -> CryptFilterMethod
The stream crypt filter method.
Sourcepub fn string_crypt_filter(&self) -> CryptFilterMethod
pub fn string_crypt_filter(&self) -> CryptFilterMethod
The string crypt filter method.
Sourcepub fn version(&self) -> u32
pub fn version(&self) -> u32
The encryption version number (V value).
Derived from the revision: R2→V1, R3/R4→V2..V4, R5/R6→V5.
Sourcepub fn encrypt_string(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8> ⓘ
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).