View Source Pdf.Reader.Encryption (ExPDF v1.0.1)

Facade module for PDF Standard Security Handler authentication and decryption.

Dispatches to the appropriate version-specific module (V1V2, V4, V5) based on the /V field of the parsed %StandardHandler{} struct.

This module does NOT parse the Encrypt dict — that is handled by Pdf.Reader.Encryption.StandardHandler.parse/2. This module only:

  1. Dispatches unlock/3 to the correct version module.
  2. Returns the handler with :file_key populated on success.

Authentication flow

  1. Try user password via authenticate_user/2 for the detected version.
  2. If that fails (:error), try owner password via authenticate_owner/2.
  3. Return {:ok, %StandardHandler{file_key: key}} or :error.

Supported versions

/VModuleRevision
1V1V2R=2
2V1V2R=3/4
4V4R=4
5V5R=6 only

V5/R5 (deprecated Acrobat X beta) is rejected by V5.authenticate_user/2 with {:error, :encrypted_unsupported_handler} per R-ENC25.

Spec references

Summary

Functions

Attempts to unlock an encrypted PDF handler with the given password.

Functions

Link to this function

unlock(password, handler, doc)

View Source
@spec unlock(binary(), Pdf.Reader.Encryption.StandardHandler.t(), map()) ::
  {:ok, Pdf.Reader.Encryption.StandardHandler.t()}
  | :error
  | {:error, :encrypted_unsupported_handler}

Attempts to unlock an encrypted PDF handler with the given password.

Tries the password as user, then as owner. Returns the handler with :file_key populated on success.

Parameters

  • password — the plaintext password string.
  • handler — a %StandardHandler{} parsed from the Encrypt dict (:file_key is nil).
  • _doc — reserved for future use (e.g., doc reference); ignored for now.

Returns

  • {:ok, %StandardHandler{file_key: key}} — authenticated; key is populated.
  • :error — wrong password (tried as both user and owner).
  • {:error, :encrypted_unsupported_handler} — version unsupported or RC4 unavailable.