Pajdeg  0.2.2
Pajdeg
Files | Typedefs | Functions

Cryptography related functionality to deal with encrypted PDF content. More...

Files

file  pd_crypto.h
 

Typedefs

typedef struct pd_cryptopd_crypto
 

Functions

pd_crypto pd_crypto_create (PDDictionaryRef trailerDict, PDDictionaryRef options)
 
void pd_crypto_destroy (pd_crypto crypto)
 
PDInteger pd_crypto_unescape (char *str)
 
PDInteger pd_crypto_unescape_explicit_len (char *str, int len)
 
PDInteger pd_crypto_escape (char **dst, const char *src, PDInteger srcLen)
 
PDInteger pd_crypto_secure (char **dst, const char *src, PDInteger srcLen)
 
PDBool pd_crypto_authenticate_user (pd_crypto crypto, const char *password)
 
PDInteger pd_crypto_encrypt (pd_crypto crypto, PDInteger obid, PDInteger genid, char **dst, char *src, PDInteger len)
 
void pd_crypto_decrypt (pd_crypto crypto, PDInteger obid, PDInteger genid, char *data)
 
void pd_crypto_convert (pd_crypto crypto, PDInteger obid, PDInteger genid, char *data, PDInteger len)
 
PDStringRef pd_crypto_get_filter (pd_crypto crypto)
 
PDStringRef pd_crypto_get_subfilter (pd_crypto crypto)
 
PDInteger pd_crypto_get_version (pd_crypto crypto)
 
PDInteger pd_crypto_get_revision (pd_crypto crypto)
 
PDBool pd_crypto_get_encrypt_metadata_bool (pd_crypto crypto)
 
pd_crypto_method pd_crypto_get_method (pd_crypto crypto)
 
pd_auth_event pd_crypto_get_auth_event (pd_crypto crypto)
 

Detailed Description

Cryptography related functionality to deal with encrypted PDF content.

The pd_crypto object.

Typedef Documentation

typedef struct pd_crypto* pd_crypto

Cryptography module for PDF encryption/decryption.

Note
If PD_SUPPORT_CRYPTO is not set, this structure is a dummy object.

The pd_crypto object.

Function Documentation

PDBool pd_crypto_authenticate_user ( pd_crypto  crypto,
const char *  password 
)

Supply a user password.

Parameters
cryptoThe crypto object.
passwordThe user password.
Returns
true if the password was valid, false if not
void pd_crypto_convert ( pd_crypto  crypto,
PDInteger  obid,
PDInteger  genid,
char *  data,
PDInteger  len 
)

Convert data of length len owned by object obid with generation number genid to/from encrypted version.

This is the "low level" function used by the above two methods to encrypt/decrypt content. This version does not escape/unescape or add/remove parentheses, which the above ones do. This version is used directly for streams which aren't escaped.

Parameters
cryptoCrypto instance.
obidObject ID of owning object.
genidGeneration number of owning object.
dataData to convert.
lenLength of data.
pd_crypto pd_crypto_create ( PDDictionaryRef  trailerDict,
PDDictionaryRef  options 
)

Create crypto object with given configuration.

Parameters
trailerDictThe pd_dict of the Trailer dictionary of the given PDF. Needed to obtain the /ID key.
optionsThe pd_dict of the Encrypt dictionary of the given PDF.
Returns
Instance with given options or NULL if unsupported.
void pd_crypto_decrypt ( pd_crypto  crypto,
PDInteger  obid,
PDInteger  genid,
char *  data 
)

Decrypt, unescape and NUL-terminate the value of data in-place.

Parameters
cryptoCrypto instance.
obidThe object ID of the object whose content is being decrypted.
genidThe generation number of the object whose content is being decrypted.
dataThe data to decrypt. The content will be in-place replaced with the new data.
void pd_crypto_destroy ( pd_crypto  crypto)

Destroy crypto object, freeing up resources.

PDInteger pd_crypto_encrypt ( pd_crypto  crypto,
PDInteger  obid,
PDInteger  genid,
char **  dst,
char *  src,
PDInteger  len 
)

Encrypt the value of src of length len and store the value in dst, escaped and parenthesized.

Parameters
cryptoCrypto instance.
obidThe object ID of the object whose content is being encrypted.
genidThe generation number of the object whose content is being encrypted.
dstPointer to char buffer into which results will be stored. Should not be pre-allocated.
srcThe data to encrypt. The content will be in-place encrypted but escaped results go into *dst.
lenLength of data in bytes.
Returns
Length of encrypted string, including parentheses and escaping.
PDInteger pd_crypto_escape ( char **  dst,
const char *  src,
PDInteger  srcLen 
)

Escape a string. The result will be wrapped in parentheses.

Strings, in particular encrypted strings, are stored using escaping to prevent null termination in the middle of strings and PDF misinterpretations and other nastiness.

Escaping is done to control chars, such as ,
, , , and unreadable ascii characters using (s) (1, 2 or 3).

Parameters
dstPointer to destination string. Should not be pre-allocated.
srcString to escape.
srcLenLength of string.
Returns
The length of the escaped string.
PDInteger pd_crypto_secure ( char **  dst,
const char *  src,
PDInteger  srcLen 
)

Generate a secure string from a given input string.

The input string may optionally be wrapped in parentheses. The resulting string will be, regardless of input string.

This method is roughly the equivalent of doing len = pd_crypto_unescape_explicit_len(src, srcLen); pd_crypto_escape(dst, src, len);

Parameters
dstPointer to destination string. Should not be pre-allocated.
srcString to escape.
srcLenLength of string.
Returns
The length of the escaped string.
PDInteger pd_crypto_unescape ( char *  str)

Unescape a PDF string which may optionally be wrapped in parentheses. The result is not wrapped in parentheses. The string is unescaped in-place and NUL-terminated.

Strings, in particular encrypted strings, are stored using escaping to prevent null termination in the middle of strings and PDF misinterpretations and other nastiness.

Escaping is done to control chars, such as ,
, , , and unreadable ascii characters using (s) (1, 2 or 3).

Parameters
strThe string.
Returns
The length of the unescaped string.
PDInteger pd_crypto_unescape_explicit_len ( char *  str,
int  len 
)

Unescape a PDF string, explicitly defining the length of the string to allow for potential mid-NULs. May optionally be wrapped in parentheses. The result is not wrapped in parentheses. The string is unescaped in-place and NUL-terminated.

Strings, in particular encrypted strings, are stored using escaping to prevent null termination in the middle of strings and PDF misinterpretations and other nastiness.

Escaping is done to control chars, such as ,
, , , and unreadable ascii characters using (s) (1, 2 or 3).

Parameters
strThe string.
lenThe length of the string;
Returns
The length of the unescaped string.