23 #include <interfaces/generator/digest.h>
24 #include <interfaces/generator/exceptions.h>
27 #include <openssl/evp.h>
29 #define FILE_STEP 1024
31 using namespace fawkes;
48 if ( ! EVP_DigestInit(&ctx, EVP_md5())) {
49 throw Exception(
"Could not initialize digest context");
52 FILE *f = fopen(config_filename.c_str(),
"r");
53 void *buf = malloc(FILE_STEP);
54 while ( ! feof(f) && ! ferror(f) ) {
56 if ((rb = fread(buf, 1, FILE_STEP, f)) > 0) {
57 if ( ! EVP_DigestUpdate(&ctx, buf, rb) ) {
59 throw Exception(
"Failed to update digest");
65 throw Exception(
"Failure while reading the file");
69 digest_size=EVP_MD_CTX_size(&ctx);
70 digest =
new unsigned char[digest_size];
72 if ( ! EVP_DigestFinal(&ctx, digest, NULL) ) {
75 throw Exception(
"Could not finalize digest");