23 #include <interfaces/generator/digest.h> 24 #include <interfaces/generator/exceptions.h> 27 #include <openssl/evp.h> 29 #define FILE_STEP 1024 47 EVP_MD_CTX *ctx = EVP_MD_CTX_create();
48 if ( ! EVP_DigestInit(ctx, EVP_md5())) {
49 EVP_MD_CTX_destroy(ctx);
50 throw Exception(
"Could not initialize digest context");
53 FILE *f = fopen(config_filename.c_str(),
"r");
54 void *buf = malloc(FILE_STEP);
55 while ( ! feof(f) && ! ferror(f) ) {
57 if ((rb = fread(buf, 1, FILE_STEP, f)) > 0) {
58 if ( ! EVP_DigestUpdate(ctx, buf, rb) ) {
60 EVP_MD_CTX_destroy(ctx);
61 throw Exception(
"Failed to update digest");
67 EVP_MD_CTX_destroy(ctx);
68 throw Exception(
"Failure while reading the file");
72 digest_size=EVP_MD_CTX_size(ctx);
73 digest =
new unsigned char[digest_size];
75 if ( ! EVP_DigestFinal(ctx, digest, NULL) ) {
78 EVP_MD_CTX_destroy(ctx);
79 throw Exception(
"Could not finalize digest");
81 EVP_MD_CTX_destroy(ctx);
Fawkes library namespace.
const unsigned char * get_hash()
Get hash.
Base class for exceptions in Fawkes.
size_t get_hash_size()
Get hash size.
~InterfaceDigest()
Destructor.
InterfaceDigest(std::string config_filename)
Constructor.