pub struct Decryptor { /* private fields */ }Expand description
A configured Standard-handler decryptor for an opened document.
Implementations§
Source§impl Decryptor
impl Decryptor
Sourcepub fn from_standard(enc: &Dict, id0: &[u8]) -> Option<Decryptor>
pub fn from_standard(enc: &Dict, id0: &[u8]) -> Option<Decryptor>
Builds a decryptor from the resolved /Encrypt dictionary and the first
/ID element, assuming the empty user password. Returns None when the
handler or its parameters are unsupported, or the empty password does
not open the file (so the caller can report it as unsupported).
This is low-level: crate::Document configures decryption itself, and
a caller only reaches for this when driving object reads directly — as
the asynchronous API does.
use pdfboss_core::{Decryptor, Dict};
// An empty dictionary names no handler, so there is nothing to build.
assert!(Decryptor::from_standard(&Dict::default(), &[]).is_none());Sourcepub fn from_standard_with_password_str(
enc: &Dict,
id0: &[u8],
password: &str,
) -> Option<Decryptor>
pub fn from_standard_with_password_str( enc: &Dict, id0: &[u8], password: &str, ) -> Option<Decryptor>
Decryptor::from_standard_with_password for a text password: the
UTF-8 bytes are tried first and, when they differ and every char
fits, the Latin-1 bytes as well — the legacy revisions hash raw
bytes without naming an encoding, and real files use both.
Sourcepub fn from_standard_with_password(
enc: &Dict,
id0: &[u8],
password: &[u8],
) -> Option<Decryptor>
pub fn from_standard_with_password( enc: &Dict, id0: &[u8], password: &[u8], ) -> Option<Decryptor>
Decryptor::from_standard with a caller-supplied password, tried
first as the user password and then as the owner password (which
recovers the user-level key, ISO 32000 §7.6.3.4 Algorithm 7 for the
RC4/AES-128 revisions, §7.6.4.3.3 for AES-256). None when the
password opens nothing.
Sourcepub fn decrypt_object(&self, obj: &mut Object, num: u32, gen: u16)
pub fn decrypt_object(&self, obj: &mut Object, num: u32, gen: u16)
Decrypts one indirect object’s strings and stream data in place. Objects extracted from object streams are already plaintext and must not be passed here.
Low-level, like Decryptor::from_standard: crate::Document applies
this itself as it loads objects, and a caller only reaches for it when
driving object reads directly — as the asynchronous API does.
use pdfboss_core::{Decryptor, Object};
// Reachable from outside the crate; exercising it needs an encrypted
// document, so this only pins the signature and the visibility.
let apply: fn(&Decryptor, &mut Object, u32, u16) = Decryptor::decrypt_object;
let _ = apply;