Expand description
Standard security handler decryption (ISO 32000-2 §7.6; ISO 32000-1 §7.6.3 for R2–R4): password authentication for revisions 2–6 and string/stream decryption with RC4, AES-128-CBC and AES-256-CBC.
Read only. RC4 and MD5 are broken primitives that Lamina PDF only ever reads: nothing here encrypts. Writing encrypted files is full-editor E11 (AES-256 / R6 only).
The file structure layer (laminapdf-cos) parses /Encrypt, fills a StandardSecurity,
calls authenticate and then decrypts each string and stream with the
FileKey it gets back.
use laminapdf_syntax::crypt::{Cipher, decrypt, FileKey};
// `/Identity` passes data through unchanged.
let key = FileKey::from_bytes(vec![0; 16]);
let out = decrypt(Cipher::Identity, &key, 1, 0, b"plain");
assert_eq!((out.data.as_slice(), out.well_formed), (&b"plain"[..], true));Sources: research ch. 04 §7 (docs/research/pdf/04-interactive-security.md), the spec
sections named on each item.
Structs§
- Authenticated
- A successful
authenticate. - Decrypted
- Decrypted data and whether the input was well-formed for its cipher.
- FileKey
- The file encryption key. Its bytes are never printed.
- Grant
- What a new handler lets a user without the owner password do: the controls of the Protect
dialog, mapped to
/PbyGrant::p. Bit 10 (accessibility) is not a field: it is always set, so a protected file stays readable by assistive technology. - Handler
- A written R6 handler: the
/Encryptentries and the file key. - NewHandler
- What a new R6 handler is made from.
- Permissions
- The user access permissions of an encrypted document, from
/P(ISO 32000-2 Table 22). - Seeded
Entropy - An
Entropythat expands a 32-byte seed with SHA-256 in counter mode (the construction of NIST SP 800-90A’sHash_df): the same seed gives the same stream, and the stream reveals nothing about the seed. - Standard
Security - The values of a standard security handler’s
/Encryptdictionary that authentication needs (ISO 32000-2 Table 21). The caller extracts them; byte strings are taken as stored.
Enums§
- Cipher
- A crypt filter method (
/CFM, ISO 32000-2 Table 25) or the pre-V4 implicit cipher. - Password
Kind - Which password authenticated the document.
- Print
Right - How much of printing a new document allows (Table 22 bits 3 and 12).
Traits§
- Entropy
- A source of random bytes, injected by the host (core reads no clock and no OS source).
Functions§
- authenticate
- Authenticates
passwordas the user then the owner password for R2–R4, owner first for R5/R6 (ISO 32000-1 Algorithms 6–7 for R2–R4; ISO 32000-2 Algorithms 11–12 with 2.A/2.B for R6; the single SHA-256 of Adobe Extension Level 3 for R5, which was never standardised and is read only). - authenticate_
owner - Authenticates
passwordas the owner password only (ISO 32000-1 Algorithm 7, ISO 32000-2 Algorithm 12): for a password given as the permissions password. Unlikeauthenticate, a password that is also the user password is found to be the owner’s at R2–R4 too, whose user-first order would report it as the user’s. - decrypt
- Decrypts the string or stream data of object
num gen(ISO 32000-1 §7.6.2 Algorithm 1 for the per-object keys of RC4 and AES-128; AES-256 uses the file key itself). - encrypt
- Encrypts the string or stream data of object
num gen(ISO 32000-2 §7.6.3, the inverse ofdecrypt): AES gets a fresh 16-byte IV fromentropyin front of the PKCS#5-padded ciphertext, RC4 is the same keystream,Cipher::Identitycopies.Nonewhen the key has the wrong length for the cipher: the data is never returned as it was, so a caller that can’t encrypt has to say so. - new_
handler - Algorithm 8 (
/U,/UE), Algorithm 9 (/O,/OE) and Algorithm 10 (/Perms).