Skip to main content

EncryptionConfig

Struct EncryptionConfig 

Source
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: u8

Revision — 2..=6. Implies length_bits, cfm, and which algorithm family (V≤4 vs V=5) to use.

§length_bits: usize

File-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: i32

32-bit signed permissions value (§7.6.3.2 Table 22).

§encrypt_metadata: bool

Whether the document metadata stream is encrypted (R≥4).

§method: CryptMethod

Per-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

Source

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.

Source

pub fn rc4_128(user_password: &[u8], file_id: &[u8]) -> Self

R=3 RC4-128 default.

Source

pub fn rc4_40(user_password: &[u8], file_id: &[u8]) -> Self

R=2 RC4-40 default.

Source

pub fn aes_256_r5(user_password: &[u8], file_id: &[u8]) -> Self

R=5 AES-256 default (Adobe extension level 3).

Source

pub fn aes_256_r6(user_password: &[u8], file_id: &[u8]) -> Self

R=6 AES-256 default (ISO 32000-2 PDF 2.0).

Source

pub fn with_owner_password(self, owner: &[u8]) -> Self

Apply an owner password.

Source

pub fn with_permissions(self, p: i32) -> Self

Override permissions.

Trait Implementations§

Source§

impl Clone for EncryptionConfig

Source§

fn clone(&self) -> EncryptionConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EncryptionConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V