Example use of custom interface callbacks for document signing.
#include "tools.h"
void print_sign_custom_help() {
printf("Usage: sign_custom -s [source file] -d [destination file] -l [license file]");
}
typedef struct {
} SignatureData;
SignatureData* signature_data = (SignatureData*) user_data;
const char SAMPLE_DATA[] = "Hello world!";
UNUSED(algorithm);
RETURN_ERROR_IF_NOT_SUCCESS(Buffer_Create(&signature_data->data));
RETURN_ERROR_IF_NOT_SUCCESS(Buffer_SetData(signature_data->data, SAMPLE_DATA, sizeof(SAMPLE_DATA)));
}
SignatureData* signature_data = (SignatureData*) user_data;
RETURN_ERROR_IF_NOT_SUCCESS(Buffer_GetData(data, &buffer_data, &buffer_size));
UNUSED(signature_data);
}
SignatureData* signature_data = (SignatureData*) user_data;
*result = signature_data->data;
}
SignatureData* signature_data = (SignatureData*) user_data;
RETURN_ERROR_IF_NOT_SUCCESS(Buffer_Release(signature_data->data));
}
int process_sign_custom(int argc, char *argv[]) {
SignatureData user_data = {0};
for (i = 0; i < argc; ++i) {
if (strcmp(argv[i], "-s") == 0 && (i + 1 < argc)) {
source_document_path = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-d") == 0 && (i + 1 < argc)) {
destination_file_path = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-l") == 0 && (i + 1 < argc)) {
license_file = argv[i + 1];
i++;
} else {
print_sign_custom_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
}
if (source_document_path == NULL || destination_file_path == NULL) {
print_sign_custom_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
if (license_file != NULL) {
RETURN_ERROR_IF_NOT_SUCCESS(LicenseInfo_SetLicenseFile(license_file));
}
RETURN_ERROR_IF_NOT_SUCCESS(SigningKey_CreateCustom(&sign_init, &sign_update, &sign_final, &sign_cleanup, &user_data, &signing_key));
RETURN_ERROR_IF_NOT_SUCCESS(DocumentSignatureSettings_Create(&signature_settings));
RETURN_ERROR_IF_NOT_SUCCESS(DocumentSignatureSettings_SetSigningKey(signature_settings, signing_key));
RETURN_ERROR_IF_NOT_SUCCESS(File_Create(destination_file_path, &destination_file));
RETURN_ERROR_IF_NOT_SUCCESS(Document_Open(source_document_path, &source_document));
RETURN_ERROR_IF_NOT_SUCCESS(Document_Sign(source_document, destination_file, signature_settings));
RETURN_ERROR_IF_NOT_SUCCESS(Document_Release(source_document));
RETURN_ERROR_IF_NOT_SUCCESS(File_Release(destination_file));
RETURN_ERROR_IF_NOT_SUCCESS(DocumentSignatureSettings_Release(signature_settings));
RETURN_ERROR_IF_NOT_SUCCESS(SigningKey_Release(signing_key));
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}
Represents memory stored data.
Represents high-level file access handle.
Group of settings controlling document's digital signature.
Represents low-level file access handle.
Used for document signing.
const error_type VANILLAPDF_ERROR_SUCCESS
Indicates that the operation completed successfully.
uint32_t error_type
This is return value type of all API functions.
Definition c_types.h:25
int32_t integer_type
32-bit signed integer
Definition c_types.h:51
uint32_t size_type
Size type defined in standard library.
Definition c_types.h:62
const char * string_type
C-Style string.
Definition c_types.h:82
MessageDigestAlgorithmType
Supported digest algorithms used as hash functions.
Definition c_message_digest_algorithm.h:22
@ MessageDigestAlgorithmType_SHA256
SHA-2 (Secure Hash Algorithm 2) is a set of cryptographic hash functions designed by the United State...
Definition c_message_digest_algorithm.h:62