Commit 0a209460 authored by Tomáš Stefan's avatar Tomáš Stefan

started Doxygen documentation

ERR_NO -> ERR_NONE
minor code fixes
parent 1ce8302e
# Output
build/
Makefile.deps
html
latex
# GENERAL
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/** @file
*
*/
#ifndef PDF_SIGIL_ACROFORM_H
#define PDF_SIGIL_ACROFORM_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_AUXILIARY_H
#define PDF_SIGIL_AUXILIARY_H
#include <stdio.h> // size_t, FILE
#include "types.h"
/** @brief Find minimum of two values
*
*/
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
/** @brief Find maximum of two values
*
*/
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
// Shouldn't be optimized out by the compiler
/** @brief Fills content with zeros, shouldn't be optimized out by the compiler
*
* @param a starting address
* @param bytes number of bytes
*/
void sigil_zeroize(void *a, size_t bytes);
/** @brief Decide whether the character is a digit
*
* @param c character provided for comparison
* @return 1 if true, 0 otherwise
*/
int is_digit(const char c);
/** @brief Decide whether the character is a whitespace according to PDF standard
*
* @param c character provided for comparison
* @return 1 if true, 0 otherwise
*/
int is_whitespace(const char c);
/** @brief Reads *size* bytes from PDF to *result* and adds a terminating null.
* Does move the position in PDF.
*
* @param sgl context
* @param size number of bytes
* @param result output buffer
* @param res_size output number of bytes read, doesn't include terminating null
* @return ERR_NONE if success
*/
sigil_err_t pdf_read(sigil_t *sgl, size_t size, char *result, size_t *res_size);
/** @brief Reads one character from PDF and moves the position in PDF.
*
* @param sgl context
* @param result output character
* @return ERR_NONE if success
*/
sigil_err_t pdf_get_char(sigil_t *sgl, char *result);
/** @brief Reads one character from PDF and **does not** move the position in PDF
*
* @param sgl context
* @param result output character
* @return ERR_NONE if success
*/
sigil_err_t pdf_peek_char(sigil_t *sgl, char *result);
/** @brief Moves position in the PDF relatively to the current position
*
* @param sgl context
* @param shift_bytes number of bytes (positive or negative)
* @return ERR_NONE if success
*/
sigil_err_t pdf_move_pos_rel(sigil_t *sgl, ssize_t shift_bytes);
/** @brief Moves position in the PDF to the specified value
*
* @param sgl context
* @param position final position in the PDF
* @return ERR_NONE if success
*/
sigil_err_t pdf_move_pos_abs(sigil_t *sgl, size_t position);
/** @brief Moves position to the object specified as an indirect reference.
* Skips leading object identifiers (X Y obj)
*
* @param sgl context
* @param ref object indirect reference
* @return ERR_NONE if success
*/
sigil_err_t pdf_goto_obj(sigil_t *sgl, reference_t *ref);
/** @brief Gets the current position inside the PDF
*
* @param sgl context
* @param result output - the current position in the PDF
* @return ERR_NONE if success
*/
sigil_err_t get_curr_position(sigil_t *sgl, size_t *result);
sigil_err_t skip_leading_whitespaces(sigil_t *sgl);
......
/** @file
*
*/
#ifndef PDF_SIGIL_CATALOG_DICT_H
#define PDF_SIGIL_CATALOG_DICT_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_CERT_H
#define PDF_SIGIL_CERT_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_CONFIG_H
#define PDF_SIGIL_CONFIG_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_CONSTANTS_H
#define PDF_SIGIL_CONSTANTS_H
......@@ -45,7 +49,7 @@
#define DEALLOCATE_FILE 0x01
#define DEALLOCATE_BUFFER 0x02
#define ERR_NO 0
#define ERR_NONE 0
#define ERR_ALLOCATION 1
#define ERR_PARAMETER 2
#define ERR_IO 3
......
/** @file
*
*/
#ifndef PDF_SIGIL_CONTENTS_H
#define PDF_SIGIL_CONTENTS_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_CRYPTOGRAPHY_H
#define PDF_SIGIL_CRYPTOGRAPHY_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_HEADER_H
#define PDF_SIGIL_HEADER_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_SIG_DICT_H
#define PDF_SIGIL_SIG_DICT_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_SIG_FIELD_H
#define PDF_SIGIL_SIG_FIELD_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_SIGIL_H
#define PDF_SIGIL_SIGIL_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_TRAILER_H
#define PDF_SIGIL_TRAILER_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_TYPES_H
#define PDF_SIGIL_TYPES_H
......
/** @file
*
*/
#ifndef PDF_SIGIL_XREF_H
#define PDF_SIGIL_XREF_H
......
......@@ -15,33 +15,33 @@ sigil_err_t process_acroform(sigil_t *sgl)
if (sgl->offset_acroform <= 0 && sgl->ref_acroform.object_num > 0) {
err = pdf_goto_obj(sgl, &(sgl->ref_acroform));
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
} else {
err = pdf_move_pos_abs(sgl, sgl->offset_acroform);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
}
err = parse_word(sgl, "<<");
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
while ((err = parse_dict_key(sgl, &dict_key)) == ERR_NO) {
while ((err = parse_dict_key(sgl, &dict_key)) == ERR_NONE) {
switch (dict_key) {
case DICT_KEY_Fields:
err = parse_ref_array(sgl, &(sgl->fields));
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
break;
case DICT_KEY_SigFlags:
err = parse_number(sgl, &(sgl->sig_flags));
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
break;
case DICT_KEY_UNKNOWN:
err = skip_dict_unknown_value(sgl);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
break;
default:
......@@ -50,7 +50,7 @@ sigil_err_t process_acroform(sigil_t *sgl)
}
if (err == ERR_END_OF_DICT)
return ERR_NO;
return ERR_NONE;
return err;
}
\ No newline at end of file
This diff is collapsed.
......@@ -21,43 +21,43 @@ sigil_err_t process_catalog_dictionary(sigil_t *sgl)
}
err = pdf_goto_obj(sgl, &(sgl->ref_catalog_dict));
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
err = parse_word(sgl, "<<");
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
while ((err = parse_dict_key(sgl, &dict_key)) == ERR_NO) {
while ((err = parse_dict_key(sgl, &dict_key)) == ERR_NONE) {
switch (dict_key) {
case DICT_KEY_AcroForm:
if ((err = skip_leading_whitespaces(sgl)) != ERR_NO)
if ((err = skip_leading_whitespaces(sgl)) != ERR_NONE)
return err;
if ((err = pdf_peek_char(sgl, &c)) != ERR_NO)
if ((err = pdf_peek_char(sgl, &c)) != ERR_NONE)
return err;
if (c == '<') {
if ((err = get_curr_position(sgl, &offset)) != ERR_NO)
if ((err = get_curr_position(sgl, &offset)) != ERR_NONE)
return err;
sgl->offset_acroform = offset;
if ((err = parse_word(sgl, "<<")) != ERR_NO)
if ((err = parse_word(sgl, "<<")) != ERR_NONE)
return err;
err = skip_dictionary(sgl);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
} else {
err = parse_indirect_reference(sgl, &(sgl->ref_acroform));
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
}
break;
case DICT_KEY_UNKNOWN:
err = skip_dict_unknown_value(sgl);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
break;
default:
......@@ -66,7 +66,7 @@ sigil_err_t process_catalog_dictionary(sigil_t *sgl)
}
if (err == ERR_END_OF_DICT)
return ERR_NO;
return ERR_NONE;
return err;
}
......@@ -23,7 +23,7 @@ sigil_err_t parse_one_cert(sigil_t *sgl, cert_t **result)
*result = NULL;
}
if ((err = parse_word(sgl, "<")) != ERR_NO)
if ((err = parse_word(sgl, "<")) != ERR_NONE)
return err;
*result = malloc(sizeof(**result));
......@@ -46,7 +46,7 @@ sigil_err_t parse_one_cert(sigil_t *sgl, cert_t **result)
position = 0;
while (1) {
if ((err = pdf_get_char(sgl, &c)) != ERR_NO)
if ((err = pdf_get_char(sgl, &c)) != ERR_NONE)
return err;
// not enough space, allocate double
......@@ -63,7 +63,7 @@ sigil_err_t parse_one_cert(sigil_t *sgl, cert_t **result)
if (c == '>') {
(*data)[position] = '\0';
return ERR_NO;
return ERR_NONE;
}
(*data)[position] = c;
......@@ -84,25 +84,25 @@ sigil_err_t parse_certs(sigil_t *sgl)
additional_certs = 0;
if ((err = skip_leading_whitespaces(sgl)) != ERR_NO)
if ((err = skip_leading_whitespaces(sgl)) != ERR_NONE)
return err;
if ((err = pdf_peek_char(sgl, &c)) != ERR_NO)
if ((err = pdf_peek_char(sgl, &c)) != ERR_NONE)
return err;
if (c == '[') // multiple certs
additional_certs = 1;
if ((err = pdf_move_pos_rel(sgl, 1)) != ERR_NO)
if ((err = pdf_move_pos_rel(sgl, 1)) != ERR_NONE)
return err;
// read signing certificate
err = parse_one_cert(sgl, &(sgl->certificates));
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
if (!additional_certs)
return ERR_NO;
return ERR_NONE;
next_cert = &(sgl->certificates);
......@@ -110,21 +110,21 @@ sigil_err_t parse_certs(sigil_t *sgl)
while (1) {
next_cert = &((*next_cert)->next);
if ((err = skip_leading_whitespaces(sgl)) != ERR_NO)
if ((err = skip_leading_whitespaces(sgl)) != ERR_NONE)
return err;
if ((err = pdf_peek_char(sgl, &c)) != ERR_NO)
if ((err = pdf_peek_char(sgl, &c)) != ERR_NONE)
return err;
if (c == ']') {
if ((err = pdf_move_pos_rel(sgl, 1)) != ERR_NO)
if ((err = pdf_move_pos_rel(sgl, 1)) != ERR_NONE)
return err;
return ERR_NO;
return ERR_NONE;
}
err = parse_one_cert(sgl, next_cert);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
}
}
\ No newline at end of file
......@@ -18,13 +18,13 @@ sigil_err_t parse_contents(sigil_t *sgl)
if (sgl == NULL)
return ERR_PARAMETER;
if ((err = skip_leading_whitespaces(sgl)) != ERR_NO)
if ((err = skip_leading_whitespaces(sgl)) != ERR_NONE)
return err;
if (sgl->contents != NULL)
contents_free(sgl);
if ((err = parse_word(sgl, "<")) != ERR_NO)
if ((err = parse_word(sgl, "<")) != ERR_NONE)
return err;
sgl->contents = malloc(sizeof(*(sgl->contents)));
......@@ -46,7 +46,7 @@ sigil_err_t parse_contents(sigil_t *sgl)
position = 0;
while (1) {
if ((err = pdf_get_char(sgl, &c)) != ERR_NO)
if ((err = pdf_get_char(sgl, &c)) != ERR_NONE)
return err;
// not enough space, allocate double
......@@ -63,7 +63,7 @@ sigil_err_t parse_contents(sigil_t *sgl)
if (c == '>') {
(*data)[position] = '\0';
return ERR_NO;
return ERR_NONE;
}
(*data)[position] = c;
......
......@@ -48,7 +48,7 @@ sigil_err_t hex_to_dec(const char *in, size_t in_len, unsigned char *out, size_t
out[*out_len] = '\0';
return ERR_NO;
return ERR_NONE;
}
//void print_computed_hash(sigil_t *sgl)
......@@ -121,7 +121,7 @@ sigil_err_t compute_digest_pkcs1(sigil_t *sgl)
while (range != NULL) {
err = pdf_move_pos_abs(sgl, range->start);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
bytes_left = range->length;
......@@ -130,7 +130,7 @@ sigil_err_t compute_digest_pkcs1(sigil_t *sgl)
current_length = MIN(HASH_UPDATE_SIZE, bytes_left);
err = pdf_read(sgl, current_length, update_data, &read_size);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
if (current_length != read_size)
return ERR_IO;
......@@ -158,7 +158,7 @@ sigil_err_t compute_digest_pkcs1(sigil_t *sgl)
goto end;
}
err = ERR_NO;
err = ERR_NONE;
end:
if (update_data != NULL)
......@@ -199,7 +199,7 @@ sigil_err_t load_certificates(sigil_t *sgl)
sizeof(*(certificate->cert_hex)) * ((cert_length + 1) / 2 + 1));
err = hex_to_dec(certificate->cert_hex, cert_length, tmp_cert, &tmp_cert_len);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
const_tmp = tmp_cert;
......@@ -215,7 +215,7 @@ sigil_err_t load_certificates(sigil_t *sgl)
certificate = certificate->next;
}
return ERR_NO;
return ERR_NONE;
}
sigil_err_t load_digest(sigil_t *sgl)
......@@ -252,7 +252,7 @@ sigil_err_t load_digest(sigil_t *sgl)
sigil_zeroize(tmp_contents, sizeof(*contents) * ((contents_len + 1) / 2 + 1));
err = hex_to_dec(contents, contents_len, tmp_contents, &tmp_contents_len);
if (err != ERR_NO)
if (err != ERR_NONE)
goto end;
const_tmp = tmp_contents;
......@@ -310,7 +310,7 @@ sigil_err_t load_digest(sigil_t *sgl)
sgl->digest_algorithm = X509_ALGOR_dup((X509_ALGOR *)tmp_alg);
sgl->digest_original = ASN1_OCTET_STRING_dup(tmp_hash);
err = ERR_NO;
err = ERR_NONE;
end:
if (tmp_contents != NULL)
......@@ -380,7 +380,7 @@ sigil_err_t verify_signing_certificate(sigil_t *sgl)
X509_STORE_CTX_free(ctx);
return ERR_NO;
return ERR_NONE;
}
sigil_err_t compare_digest(sigil_t *sgl)
......@@ -396,7 +396,7 @@ sigil_err_t compare_digest(sigil_t *sgl)
if (ASN1_STRING_cmp(sgl->digest_original, sgl->digest_computed) == 0)
sgl->result_digest_comparison = HASH_CMP_RESULT_MATCH;
return ERR_NO;
return ERR_NONE;
}
sigil_err_t verify_digest(sigil_t *sgl, int *result)
......@@ -409,7 +409,7 @@ sigil_err_t verify_digest(sigil_t *sgl, int *result)
*result = 1;
err = compute_digest_pkcs1(sgl);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
return compare_digest(sgl);
......
......@@ -20,11 +20,11 @@ sigil_err_t process_header(sigil_t *sgl)
for (offset = 0; offset < HEADER_SEARCH_OFFSET; offset++) {
err = pdf_move_pos_abs(sgl, offset);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
err = pdf_read(sgl, 5, tmp, &read_size);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
if (read_size != 5)
return ERR_PDF_CONTENT;
......@@ -32,15 +32,15 @@ sigil_err_t process_header(sigil_t *sgl)
if (strncmp(tmp, "\x25PDF-", 5) != 0)
continue;
if ((err = parse_number(sgl, &pdf_x)) != ERR_NO)
if ((err = parse_number(sgl, &pdf_x)) != ERR_NONE)
return err;
if ((err = pdf_get_char(sgl, &c)) != ERR_NO)
if ((err = pdf_get_char(sgl, &c)) != ERR_NONE)
return err;
if (c != '.')
return ERR_PDF_CONTENT;
if ((err = parse_number(sgl, &pdf_y)) != ERR_NO)
if ((err = parse_number(sgl, &pdf_y)) != ERR_NONE)
return err;
if ((pdf_x == 1 && pdf_y >= 0 && pdf_y <= 7) ||
......@@ -54,7 +54,7 @@ sigil_err_t process_header(sigil_t *sgl)
sgl->offset_pdf_start = offset;
return ERR_NO;
return ERR_NONE;
}
return ERR_PDF_CONTENT;
......@@ -75,7 +75,7 @@ int sigil_header_self_test(int verbosity)
if ((sgl = test_prepare_sgl_content(sstream_1, strlen(sstream_1) + 1)) == NULL)
goto failed;
if (process_header(sgl) != ERR_NO ||
if (process_header(sgl) != ERR_NONE ||
sgl->pdf_x != 1 ||
sgl->pdf_y != 1 ||
sgl->offset_pdf_start != 0)
......@@ -83,9 +83,9 @@ int sigil_header_self_test(int verbosity)
goto failed;
}
if (skip_leading_whitespaces(sgl) != ERR_NO)
if (skip_leading_whitespaces(sgl) != ERR_NONE)
goto failed;
if ((pdf_get_char(sgl, &c)) != ERR_NO || c != 'x')
if ((pdf_get_char(sgl, &c)) != ERR_NONE || c != 'x')
goto failed;
sigil_free(&sgl);
......@@ -98,7 +98,7 @@ int sigil_header_self_test(int verbosity)
if ((sgl = test_prepare_sgl_content(sstream_2, strlen(sstream_2) + 1)) == NULL)
goto failed;
if (process_header(sgl) != ERR_NO ||
if (process_header(sgl) != ERR_NONE ||
sgl->pdf_x != 1 ||
sgl->pdf_y != 2 ||
sgl->offset_pdf_start != 50)
......@@ -106,9 +106,9 @@ int sigil_header_self_test(int verbosity)
goto failed;
}
if (skip_leading_whitespaces(sgl) != ERR_NO)
if (skip_leading_whitespaces(sgl) != ERR_NONE)
goto failed;
if ((pdf_get_char(sgl, &c)) != ERR_NO || c != 'x')
if ((pdf_get_char(sgl, &c)) != ERR_NONE || c != 'x')
goto failed;
sigil_free(&sgl);
......
......@@ -24,10 +24,10 @@ static sigil_err_t parse_subfilter(sigil_t *sgl)
sigil_zeroize(tmp, SUBFILTER_MAX * sizeof(*tmp));
err = parse_word(sgl, "/");
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
while ((err = pdf_peek_char(sgl, &c)) == ERR_NO) {
while ((err = pdf_peek_char(sgl, &c)) == ERR_NONE) {
if (is_whitespace(c)) {
if (count <= 0)
return ERR_PDF_CONTENT;
......@@ -38,11 +38,11 @@ static sigil_err_t parse_subfilter(sigil_t *sgl)
tmp[count++] = c;
}
if ((err = pdf_move_pos_rel(sgl, 1)) != ERR_NO)
if ((err = pdf_move_pos_rel(sgl, 1)) != ERR_NONE)
return err;
}
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
if (strncmp(tmp, "adbe.x509.rsa_sha1", 18) == 0) {
......@@ -51,7 +51,7 @@ static sigil_err_t parse_subfilter(sigil_t *sgl)
sgl->subfilter_type = SUBFILTER_UNKNOWN;
}
return ERR_NO;
return ERR_NONE;
}
static sigil_err_t parse_byte_range(sigil_t *sgl)
......@@ -65,21 +65,21 @@ static sigil_err_t parse_byte_range(sigil_t *sgl)
return ERR_PARAMETER;
err = parse_word(sgl, "[");
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
byte_range = &(sgl->byte_range);
while (1) {
if (parse_word(sgl, "]") == ERR_NO)
return ERR_NO;
if (parse_word(sgl, "]") == ERR_NONE)
return ERR_NONE;
err = parse_number(sgl, &start);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
err = parse_number(sgl, &length);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
if (start + length > sgl->pdf_data.size)
......@@ -109,45 +109,45 @@ sigil_err_t process_sig_dict(sigil_t *sgl)
if (sgl->offset_sig_dict <= 0 && sgl->ref_sig_dict.object_num > 0) {
err = pdf_goto_obj(sgl, &(sgl->ref_sig_dict));
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
} else {
err = pdf_move_pos_abs(sgl, sgl->offset_sig_dict);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
}
err = parse_word(sgl, "<<");
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
while ((err = parse_dict_key(sgl, &dict_key)) == ERR_NO) {
while ((err = parse_dict_key(sgl, &dict_key)) == ERR_NONE) {
switch (dict_key) {
case DICT_KEY_SubFilter:
if ((err = parse_subfilter(sgl)) != ERR_NO)
if ((err = parse_subfilter(sgl)) != ERR_NONE)
return err;
break;
case DICT_KEY_Cert:
err = parse_certs(sgl);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
break;
case DICT_KEY_Contents:
err = parse_contents(sgl);
if (err != ERR_NO)
if (err != ERR_NONE)
return err;
break;
case DICT_KEY_ByteRange:
if ((err = parse_byte_range(sgl)) != ERR_NO)
if ((err = parse_byte_range(sgl)) != ERR_NONE)