Documentation
¶
Overview ¶
Package crypt implements the PDF standard security handler (ISO 32000-2 7.6): revisions 2-4 (RC4 and AESV2) and 5-6 (AESV3). It authenticates the user and owner passwords, reproducing the status bits MuPDF's fz_authenticate_password returns, and decrypts strings and streams with per-object keys.
The COS layer installs it as a cos.Decryptor: New builds the handler from the /Encrypt dictionary and tries the empty password at once, and once a password authenticates, the file encryption key decrypts every object loaded after it. All primitives come from the Go standard library. Hostile input yields errors or pass-through data, never a panic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the standard security handler for one open document. It is safe to use only under the COS document's own serialization (the public API's single mutex); it is not independently concurrency-safe.
func New ¶
New builds the standard security handler from encDict (the resolved /Encrypt dictionary) using c for the trailer /ID and any indirectly stored entries, then tries the empty password so documents that need none are immediately usable. It returns an error for encryption schemes it does not implement; the caller then treats the document as encrypted-but-locked.
func (*Handler) Authenticate ¶
Authenticate tries password as both the user and the owner password, returning which matched. On success it records the file encryption key so subsequent decryption can proceed. The two booleans map directly onto the public API's UserAuthenticatedMask and OwnerAuthenticatedMask bits.
func (*Handler) DecryptStream ¶
DecryptStream decrypts a stream's raw payload (before its /Filter chain) belonging to object (num, gen), returning it unchanged when no key is yet available or the streams are not encrypted.
func (*Handler) DecryptString ¶
DecryptString decrypts a string belonging to object (num, gen), returning it unchanged when no key is yet available or the strings are not encrypted.
func (*Handler) EncryptsMetadata ¶ added in v0.2.0
EncryptsMetadata reports whether metadata streams are encrypted along with everything else, i.e. whether the encryption dictionary's /EncryptMetadata entry (default true) is set.
func (*Handler) NeedsPassword ¶
NeedsPassword reports whether a password is required to use the document: true unless the empty password (tried at open) already authenticated.