pub struct EncryptionConfig {Show 15 fields
pub revision: u8,
pub length_bits: usize,
pub user_password: Vec<u8>,
pub owner_password: Vec<u8>,
pub p: i32,
pub encrypt_metadata: bool,
pub method: CryptMethod,
pub file_id: Vec<u8>,
pub u_salt_validate: [u8; 8],
pub u_salt_key: [u8; 8],
pub o_salt_validate: [u8; 8],
pub o_salt_key: [u8; 8],
pub file_key_v5: Option<[u8; 32]>,
pub perms_padding: [u8; 4],
pub aes_iv: [u8; 16],
}Expand description
Writer-side configuration: what kind of encryption to apply, what the user / owner passwords are, the permissions, and the (optional) IVs / salts to feed into the AES paths so output stays deterministic for tests.
Fields§
§revision: u8Revision — 2..=6. Implies length_bits, cfm, and which
algorithm family (V≤4 vs V=5) to use.
length_bits: usizeFile-key length in bits. R=2: 40. R=3 / R=4: typically 128. R=5 / R=6: always 256.
user_password: Vec<u8>User password (raw bytes — V=5 truncates to 127, V≤4 pads to 32).
owner_password: Vec<u8>Owner password — Algorithm 3 falls back to user password when
empty.
p: i3232-bit signed permissions value (§7.6.3.2 Table 22).
encrypt_metadata: boolWhether the document metadata stream is encrypted (R≥4).
method: CryptMethodPer-stream / per-string crypt method. RC4 / AES-128 / AES-256.
file_id: Vec<u8>Permanent file identifier — placed in /ID[0] and fed into the
V≤4 file-key derivation. Use ≥16 bytes of random data per the
spec; tests pin it for determinism.
u_salt_validate: [u8; 8]V=5 user-validation salt (8 bytes).
u_salt_key: [u8; 8]V=5 user-key salt (8 bytes).
o_salt_validate: [u8; 8]V=5 owner-validation salt (8 bytes).
o_salt_key: [u8; 8]V=5 owner-key salt (8 bytes).
file_key_v5: Option<[u8; 32]>V=5 file encryption key (32 bytes) — random for production, caller-pinned for tests. None defaults to a deterministic-but- non-reused-across-callers value.
perms_padding: [u8; 4]V=5 Algorithm 10 padding bytes (12..16).
aes_iv: [u8; 16]IV for AES per-object encryption (16 bytes). Tests pin; production callers should override per-object.
Implementations§
Source§impl EncryptionConfig
impl EncryptionConfig
Sourcepub fn aes_128(user_password: &[u8], file_id: &[u8]) -> Self
pub fn aes_128(user_password: &[u8], file_id: &[u8]) -> Self
Sensible R=4 (AES-128) default — empty owner password, no metadata encryption opt-out, full permissions.
Sourcepub fn aes_256_r5(user_password: &[u8], file_id: &[u8]) -> Self
pub fn aes_256_r5(user_password: &[u8], file_id: &[u8]) -> Self
R=5 AES-256 default (Adobe extension level 3).
Sourcepub fn aes_256_r6(user_password: &[u8], file_id: &[u8]) -> Self
pub fn aes_256_r6(user_password: &[u8], file_id: &[u8]) -> Self
R=6 AES-256 default (ISO 32000-2 PDF 2.0).
Sourcepub fn with_owner_password(self, owner: &[u8]) -> Self
pub fn with_owner_password(self, owner: &[u8]) -> Self
Apply an owner password.
Sourcepub fn with_permissions(self, p: i32) -> Self
pub fn with_permissions(self, p: i32) -> Self
Override permissions.
Trait Implementations§
Source§impl Clone for EncryptionConfig
impl Clone for EncryptionConfig
Source§fn clone(&self) -> EncryptionConfig
fn clone(&self) -> EncryptionConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more