test/src/util/test_util.cc
author Krista Bennett <krista@pep.foundation>
Wed, 06 Feb 2019 18:21:04 +0100
branchkrista-netpgp-sync
changeset 3276 c0b3430f1f1d
parent 3270 d8aea79654c3
permissions -rwxr-xr-x
ENGINE-511: fixed file uris for decrypt_in_pieces
roker@1656
     1
#include "pEpEngine_test.h"
krista@1812
     2
#include "pEpEngine.h"
krista@2444
     3
#include "pEp_internal.h"
krista@1812
     4
#include "message_api.h"
krista@2917
     5
#include "test_util.h"
krista@3276
     6
#include "TestConstants.h"
krista@2703
     7
roker@1656
     8
#include <fstream>
roker@1656
     9
#include <sstream>
roker@1656
    10
#include <stdexcept>
krista@2703
    11
#include <stdlib.h>
krista@2703
    12
#include <sys/stat.h>
krista@2703
    13
#include <errno.h>
krista@2703
    14
#include <stdlib.h>
krista@2703
    15
#include <unistd.h>
krista@2703
    16
#include <ftw.h>
roker@1656
    17
krista@2917
    18
PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname) {
krista@2917
    19
    const std::string key = slurp(fname);
krista@2917
    20
    PEP_STATUS status = (key.empty() ? PEP_KEY_NOT_FOUND : PEP_STATUS_OK);
krista@2917
    21
    if (status == PEP_STATUS_OK)
krista@2917
    22
        status = import_key(session, key.c_str(), key.size(), NULL);
krista@2917
    23
    return status;    
krista@2917
    24
}
krista@2917
    25
krista@2917
    26
PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session,
krista@2917
    27
                                     const char* key_fname,
krista@2917
    28
                                     const char* address,
krista@2917
    29
                                     const char* fpr,
krista@2917
    30
                                     const char* user_id,
krista@2917
    31
                                     const char* username,
krista@2917
    32
                                     pEp_identity** ret_ident,
krista@2917
    33
                                     bool is_priv) {
krista@2917
    34
    PEP_STATUS status = read_file_and_import_key(session,key_fname);
krista@3276
    35
    if (status != PEP_TEST_KEY_IMPORT_SUCCESS)
krista@2917
    36
        return status;
krista@3270
    37
    else
krista@3270
    38
        status = PEP_STATUS_OK;
krista@2917
    39
    
krista@2917
    40
    pEp_identity* ident = new_identity(address, fpr, user_id, username);
krista@2917
    41
    if (is_priv && fpr) {
krista@2917
    42
        status = set_own_key(session, ident, fpr);
krista@2917
    43
        if (status == PEP_STATUS_OK)
krista@2917
    44
            status = myself(session, ident);
krista@2917
    45
    }
krista@2917
    46
    else    
krista@2917
    47
        status = update_identity(session, ident);
krista@2917
    48
krista@2917
    49
    if (status != PEP_STATUS_OK)
krista@2917
    50
        goto pep_free;
krista@2917
    51
        
krista@2917
    52
    if (!ident || !ident->fpr) {
krista@2917
    53
        status = PEP_CANNOT_FIND_IDENTITY;
krista@2917
    54
        goto pep_free;
krista@2917
    55
    }
krista@2917
    56
    
krista@2917
    57
    if (ret_ident)
krista@2917
    58
        *ret_ident = ident;
krista@2917
    59
        
krista@2917
    60
pep_free:
krista@2917
    61
    if (!ret_ident)
krista@2917
    62
        free_identity(ident);
krista@2956
    63
    return status;    
krista@2917
    64
}
krista@2917
    65
krista@2917
    66
krista@2798
    67
bool file_exists(std::string filename) {
krista@2798
    68
    struct stat buffer;
krista@2798
    69
    return (stat(filename.c_str(), &buffer) == 0);
krista@2798
    70
}
krista@2798
    71
krista@2533
    72
char* str_to_lower(const char* str) {
krista@2533
    73
    if (!str)
krista@2533
    74
        return NULL;
krista@2533
    75
    int str_len = strlen(str);
krista@2533
    76
    if (str_len == 0)
krista@2533
    77
        return strdup("");
krista@2533
    78
    int i;
krista@2533
    79
    
krista@2533
    80
    char* retval = (char*) calloc(1, str_len + 1);
krista@2533
    81
    for (i = 0; i < str_len; i++) {
krista@2533
    82
        retval[i] = tolower(str[i]);
krista@2533
    83
    }    
krista@2533
    84
    return retval;
krista@2533
    85
}
krista@2533
    86
krista@2533
    87
// Because annoyed
krista@2533
    88
bool _streq(const char* str1, const char* str2) {
krista@2533
    89
    if (!str1) {
krista@2533
    90
        if (str2)
krista@2533
    91
            return false;
krista@2533
    92
        return true;
krista@2533
    93
    }
krista@2533
    94
    if (!str2)
krista@2533
    95
        return false;
krista@2533
    96
        
krista@2533
    97
    return (strcmp(str1, str2) == 0);
krista@2533
    98
}
krista@2533
    99
krista@2533
   100
bool _strceq(const char* str1, const char* str2) {
krista@2533
   101
    char* str1_dup = str_to_lower(str1);
krista@2533
   102
    char* str2_dup = str_to_lower(str2);
krista@2533
   103
krista@2533
   104
    bool retval = _streq(str_to_lower(str1_dup), str_to_lower(str2_dup));
krista@2533
   105
    free(str1_dup);
krista@2533
   106
    free(str2_dup);
krista@2533
   107
    return retval;
krista@2533
   108
}
krista@2477
   109
krista@2477
   110
void test_init() {
krista@2477
   111
    unlink ("../test_home/.pEp_management.db");
krista@2477
   112
    unlink ("../test_home/.pEp_management.db-shm");
krista@2477
   113
    unlink ("../test_home/.pEp_management.db-wal");
krista@2477
   114
}
krista@2477
   115
roker@1656
   116
std::string slurp(const std::string& filename)
roker@1656
   117
{
roker@1656
   118
	std::ifstream input(filename.c_str());
roker@1656
   119
	if(!input)
roker@1656
   120
	{
roker@1656
   121
		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
roker@1656
   122
	}
roker@1656
   123
	
roker@1656
   124
	std::stringstream sstr;
roker@1656
   125
	sstr << input.rdbuf();
roker@1656
   126
	return sstr.str();
roker@1656
   127
}
krista@1812
   128
krista@2282
   129
void dump_out(const char* filename, const char* outdata)
krista@2282
   130
{
krista@2282
   131
	std::ofstream outfile(filename);
krista@2282
   132
	if(!outfile)
krista@2282
   133
	{
krista@2282
   134
		throw std::runtime_error("Cannot open output file!");
krista@2282
   135
	}
krista@2282
   136
	
krista@2282
   137
	outfile << outdata;
krista@2282
   138
    outfile.close();
krista@2282
   139
}
krista@2282
   140
krista@2444
   141
char* get_new_uuid() {
krista@2444
   142
    char* new_uuid = (char*)calloc(37, 1);
krista@2444
   143
    pEpUUID uuid;
krista@2444
   144
    uuid_generate_random(uuid);
krista@2444
   145
    uuid_unparse_upper(uuid, new_uuid);
krista@2444
   146
    return new_uuid;
krista@2444
   147
}
krista@2282
   148
krista@1812
   149
const char* tl_status_string(PEP_STATUS status) {
krista@1812
   150
    switch (status) {
krista@1812
   151
        case PEP_STATUS_OK:
krista@1812
   152
            return "PEP_STATUS_OK";
krista@1812
   153
        case PEP_INIT_CANNOT_LOAD_GPGME:
krista@1812
   154
            return "PEP_INIT_CANNOT_LOAD_GPGME";
krista@1812
   155
        case PEP_INIT_GPGME_INIT_FAILED:
krista@1812
   156
            return "PEP_INIT_GPGME_INIT_FAILED";
krista@1812
   157
        case PEP_INIT_NO_GPG_HOME:
krista@1812
   158
            return "PEP_INIT_NO_GPG_HOME";
krista@1812
   159
        case PEP_INIT_NETPGP_INIT_FAILED:
krista@1812
   160
            return "PEP_INIT_NETPGP_INIT_FAILED";
krista@1812
   161
        case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
krista@1812
   162
            return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
krista@1812
   163
        case PEP_INIT_CANNOT_OPEN_DB:
krista@1812
   164
            return "PEP_INIT_CANNOT_OPEN_DB";
krista@1812
   165
        case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
krista@1812
   166
            return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
krista@1812
   167
        case PEP_KEY_NOT_FOUND:
krista@1812
   168
            return "PEP_KEY_NOT_FOUND";
krista@1812
   169
        case PEP_KEY_HAS_AMBIG_NAME:
krista@1812
   170
            return "PEP_KEY_HAS_AMBIG_NAME";
krista@1812
   171
        case PEP_GET_KEY_FAILED:
krista@1812
   172
            return "PEP_GET_KEY_FAILED";
krista@1812
   173
        case PEP_CANNOT_EXPORT_KEY:
krista@1812
   174
            return "PEP_CANNOT_EXPORT_KEY";
krista@1812
   175
        case PEP_CANNOT_EDIT_KEY:
krista@1812
   176
            return "PEP_CANNOT_EDIT_KEY";
krista@1812
   177
        case PEP_CANNOT_FIND_IDENTITY:
krista@1812
   178
            return "PEP_CANNOT_FIND_IDENTITY";
krista@1812
   179
        case PEP_CANNOT_SET_PERSON:
krista@1812
   180
            return "PEP_CANNOT_SET_PERSON";
krista@1812
   181
        case PEP_CANNOT_SET_PGP_KEYPAIR:
krista@1812
   182
            return "PEP_CANNOT_SET_PGP_KEYPAIR";
krista@1812
   183
        case PEP_CANNOT_SET_IDENTITY:
krista@1812
   184
            return "PEP_CANNOT_SET_IDENTITY";
krista@1812
   185
        case PEP_CANNOT_SET_TRUST:
krista@1812
   186
            return "PEP_CANNOT_SET_TRUST";
krista@1812
   187
        case PEP_KEY_BLACKLISTED:
krista@1812
   188
            return "PEP_KEY_BLACKLISTED";
krista@1812
   189
        case PEP_UNENCRYPTED:
krista@1812
   190
            return "PEP_UNENCRYPTED";
krista@1812
   191
        case PEP_VERIFIED:
krista@1812
   192
            return "PEP_VERIFIED";
krista@1812
   193
        case PEP_DECRYPTED:
krista@1812
   194
            return "PEP_DECRYPTED";
krista@1812
   195
        case PEP_DECRYPTED_AND_VERIFIED:
krista@1812
   196
            return "PEP_DECRYPTED_AND_VERIFIED";
krista@1812
   197
        case PEP_DECRYPT_WRONG_FORMAT:
krista@1812
   198
            return "PEP_DECRYPT_WRONG_FORMAT";
krista@1812
   199
        case PEP_DECRYPT_NO_KEY:
krista@1812
   200
            return "PEP_DECRYPT_NO_KEY";
krista@1812
   201
        case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
krista@1812
   202
            return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
krista@2703
   203
//        case PEP_DECRYPTED_BUT_UNSIGNED:
krista@2703
   204
//            return "PEP_DECRYPTED_BUT_UNSIGNED";
krista@2703
   205
//        case PEP_DECRYPT_MODIFICATION_DETECTED:
krista@2703
   206
//            return "PEP_DECRYPT_MODIFICATION_DETECTED";
krista@2703
   207
//        case PEP_DECRYPT_NO_KEY_FOR_SIGNER:
krista@2703
   208
//            return "PEP_DECRYPT_NO_KEY_FOR_SIGNER";
krista@1812
   209
        case PEP_VERIFY_NO_KEY:
krista@1812
   210
            return "PEP_VERIFY_NO_KEY";
krista@1812
   211
        case PEP_VERIFIED_AND_TRUSTED:
krista@1812
   212
            return "PEP_VERIFIED_AND_TRUSTED";
krista@1812
   213
        case PEP_CANNOT_DECRYPT_UNKNOWN:
krista@1812
   214
            return "PEP_CANNOT_DECRYPT_UNKNOWN";
krista@1812
   215
        case PEP_TRUSTWORD_NOT_FOUND:
krista@1812
   216
            return "PEP_TRUSTWORD_NOT_FOUND";
krista@1812
   217
        case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
krista@1812
   218
            return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
krista@1812
   219
        case PEP_CANNOT_CREATE_KEY:
krista@1812
   220
            return "PEP_CANNOT_CREATE_KEY";
krista@1812
   221
        case PEP_CANNOT_SEND_KEY:
krista@1812
   222
            return "PEP_CANNOT_SEND_KEY";
krista@1812
   223
        case PEP_PHRASE_NOT_FOUND:
krista@1812
   224
            return "PEP_PHRASE_NOT_FOUND";
krista@1812
   225
        case PEP_SEND_FUNCTION_NOT_REGISTERED:
krista@1812
   226
            return "PEP_SEND_FUNCTION_NOT_REGISTERED";
krista@1812
   227
        case PEP_CONTRAINTS_VIOLATED:
krista@1812
   228
            return "PEP_CONTRAINTS_VIOLATED";
krista@1812
   229
        case PEP_CANNOT_ENCODE:
krista@1812
   230
            return "PEP_CANNOT_ENCODE";
krista@1812
   231
        case PEP_SYNC_NO_NOTIFY_CALLBACK:
krista@1812
   232
            return "PEP_SYNC_NO_NOTIFY_CALLBACK";
krista@1812
   233
        case PEP_SYNC_ILLEGAL_MESSAGE:
krista@1812
   234
            return "PEP_SYNC_ILLEGAL_MESSAGE";
krista@1812
   235
        case PEP_SYNC_NO_INJECT_CALLBACK:
krista@1812
   236
            return "PEP_SYNC_NO_INJECT_CALLBACK";
krista@1812
   237
        case PEP_CANNOT_INCREASE_SEQUENCE:
krista@1812
   238
            return "PEP_CANNOT_INCREASE_SEQUENCE";
vb@2847
   239
        case PEP_STATEMACHINE_ERROR:
vb@2847
   240
            return "PEP_STATEMACHINE_ERROR";
vb@2847
   241
        case PEP_NO_TRUST:
vb@2847
   242
            return "PEP_NO_TRUST";
krista@1812
   243
        case PEP_STATEMACHINE_INVALID_STATE:
krista@1812
   244
            return "PEP_STATEMACHINE_INVALID_STATE";
krista@1812
   245
        case PEP_STATEMACHINE_INVALID_EVENT:
krista@1812
   246
            return "PEP_STATEMACHINE_INVALID_EVENT";
krista@1812
   247
        case PEP_STATEMACHINE_INVALID_CONDITION:
krista@1812
   248
            return "PEP_STATEMACHINE_INVALID_CONDITION";
krista@1812
   249
        case PEP_STATEMACHINE_INVALID_ACTION:
krista@1812
   250
            return "PEP_STATEMACHINE_INVALID_ACTION";
krista@1812
   251
        case PEP_STATEMACHINE_INHIBITED_EVENT:
krista@1812
   252
            return "PEP_STATEMACHINE_INHIBITED_EVENT";
krista@1812
   253
        case PEP_COMMIT_FAILED:
krista@1812
   254
            return "PEP_COMMIT_FAILED";
krista@1812
   255
        case PEP_MESSAGE_CONSUME:
krista@1812
   256
            return "PEP_MESSAGE_CONSUME";
krista@1812
   257
        case PEP_MESSAGE_IGNORE:
krista@1812
   258
            return "PEP_MESSAGE_IGNORE";
krista@1812
   259
        case PEP_RECORD_NOT_FOUND:
krista@1812
   260
            return "PEP_RECORD_NOT_FOUND";
krista@1812
   261
        case PEP_CANNOT_CREATE_TEMP_FILE:
krista@1812
   262
            return "PEP_CANNOT_CREATE_TEMP_FILE";
krista@1812
   263
        case PEP_ILLEGAL_VALUE:
krista@1812
   264
            return "PEP_ILLEGAL_VALUE";
krista@1812
   265
        case PEP_BUFFER_TOO_SMALL:
krista@1812
   266
            return "PEP_BUFFER_TOO_SMALL";
krista@1812
   267
        case PEP_OUT_OF_MEMORY:
krista@1812
   268
            return "PEP_OUT_OF_MEMORY";
krista@1812
   269
        case PEP_UNKNOWN_ERROR:
krista@2703
   270
            return "PEP_UNKNOWN_ERROR";    
krista@1812
   271
        default:
krista@2630
   272
 
krista@1812
   273
            return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
krista@1812
   274
    }
krista@1812
   275
}
krista@1812
   276
const char* tl_rating_string(PEP_rating rating) {
krista@1812
   277
    switch (rating) {
krista@1812
   278
        case PEP_rating_undefined:
krista@1812
   279
            return "PEP_rating_undefined";
krista@1812
   280
        case PEP_rating_cannot_decrypt:
krista@1812
   281
            return "PEP_rating_cannot_decrypt";
krista@1812
   282
        case PEP_rating_have_no_key:
krista@1812
   283
            return "PEP_rating_have_no_key";
krista@1812
   284
        case PEP_rating_unencrypted:
krista@1812
   285
            return "PEP_rating_unencrypted";
krista@1812
   286
        case PEP_rating_unencrypted_for_some:
krista@1812
   287
            return "PEP_rating_unencrypted_for_some";
krista@1812
   288
        case PEP_rating_unreliable:
krista@1812
   289
            return "PEP_rating_unreliable";
krista@1812
   290
        case PEP_rating_reliable:
krista@1812
   291
            return "PEP_rating_reliable";
krista@1812
   292
        case PEP_rating_trusted:
krista@1812
   293
            return "PEP_rating_trusted";
krista@1812
   294
        case PEP_rating_trusted_and_anonymized:
krista@1812
   295
            return "PEP_rating_trusted_and_anonymized";
krista@1812
   296
        case PEP_rating_fully_anonymous:
krista@1812
   297
            return "PEP_rating_fully_anonymous";
krista@1812
   298
        case PEP_rating_mistrust:
krista@1812
   299
            return "PEP_rating_mistrust";
krista@1812
   300
        case PEP_rating_b0rken:
krista@1812
   301
            return "PEP_rating_b0rken";
krista@1812
   302
        case PEP_rating_under_attack:
krista@1812
   303
            return "PEP_rating_under_attack";
krista@1812
   304
        default:
krista@1812
   305
            return "PEP_rating_OMGWTFBBQ - in other words, INVALID RATING VALUE!!!\n\nSomething bad is going on here, or a new rating value has been added to the enum and not the test function.";
krista@1812
   306
    }
krista@1812
   307
}
krista@1812
   308
krista@1812
   309
const char* tl_ct_string(PEP_comm_type ct) {
krista@1812
   310
    switch (ct) {
krista@1812
   311
        case PEP_ct_unknown:
krista@1812
   312
            return "PEP_ct_unknown";
krista@1812
   313
        case PEP_ct_no_encryption:
krista@1812
   314
            return "PEP_ct_no_encryption";
krista@1812
   315
        case PEP_ct_no_encrypted_channel:
krista@1812
   316
            return "PEP_ct_no_encrypted_channel";
krista@1812
   317
        case PEP_ct_key_not_found:
krista@1812
   318
            return "PEP_ct_key_not_found";
krista@1812
   319
        case PEP_ct_key_expired:
krista@1812
   320
            return "PEP_ct_key_expired";
krista@1812
   321
        case PEP_ct_key_revoked:
krista@1812
   322
            return "PEP_ct_key_revoked";
krista@1812
   323
        case PEP_ct_key_b0rken:
krista@1812
   324
            return "PEP_ct_key_b0rken";
krista@1812
   325
        case PEP_ct_my_key_not_included:
krista@1812
   326
            return "PEP_ct_my_key_not_included";
krista@1812
   327
        case PEP_ct_security_by_obscurity:
krista@1812
   328
            return "PEP_ct_security_by_obscurity";
krista@1812
   329
        case PEP_ct_b0rken_crypto:
krista@1812
   330
            return "PEP_ct_b0rken_crypto";
krista@1812
   331
        case PEP_ct_key_too_short:
krista@1812
   332
            return "PEP_ct_key_too_short";
krista@2593
   333
        case PEP_ct_compromised:
krista@2593
   334
            return "PEP_ct_compromised";
krista@1812
   335
        case PEP_ct_mistrusted:
krista@1812
   336
            return "PEP_ct_mistrusted";
krista@1812
   337
        case PEP_ct_unconfirmed_encryption:
krista@1812
   338
            return "PEP_ct_unconfirmed_encryption";
krista@1812
   339
        case PEP_ct_OpenPGP_weak_unconfirmed:
krista@1812
   340
            return "PEP_ct_OpenPGP_weak_unconfirmed";
krista@1812
   341
        case PEP_ct_to_be_checked:
krista@1812
   342
            return "PEP_ct_to_be_checked";
krista@1812
   343
        case PEP_ct_SMIME_unconfirmed:
krista@1812
   344
            return "PEP_ct_SMIME_unconfirmed";
krista@1812
   345
        case PEP_ct_CMS_unconfirmed:
krista@1812
   346
            return "PEP_ct_CMS_unconfirmed";
krista@1812
   347
        case PEP_ct_strong_but_unconfirmed:
krista@1812
   348
            return "PEP_ct_strong_but_unconfirmed";
krista@1812
   349
        case PEP_ct_OpenPGP_unconfirmed:
krista@1812
   350
            return "PEP_ct_OpenPGP_unconfirmed";
krista@1812
   351
        case PEP_ct_OTR_unconfirmed:
krista@1812
   352
            return "PEP_ct_OTR_unconfirmed";
krista@1812
   353
        case PEP_ct_unconfirmed_enc_anon:
krista@1812
   354
            return "PEP_ct_unconfirmed_enc_anon";
krista@1812
   355
        case PEP_ct_pEp_unconfirmed:
krista@1812
   356
            return "PEP_ct_pEp_unconfirmed";
krista@1812
   357
        case PEP_ct_confirmed:
krista@1812
   358
            return "PEP_ct_pEp_confirmed";
krista@1812
   359
        case PEP_ct_confirmed_encryption:
krista@1812
   360
            return "PEP_ct_confirmed_encryption";
krista@1812
   361
        case PEP_ct_OpenPGP_weak:
krista@1812
   362
            return "PEP_ct_OpenPGP_weak";
krista@1812
   363
        case PEP_ct_to_be_checked_confirmed:
krista@1812
   364
            return "PEP_ct_to_be_checked_confirmed";
krista@1812
   365
        case PEP_ct_SMIME:
krista@1812
   366
            return "PEP_ct_SMIME";
krista@1812
   367
        case PEP_ct_CMS:
krista@1812
   368
            return "PEP_ct_CMS";
krista@1812
   369
        case PEP_ct_strong_encryption:
krista@1812
   370
            return "PEP_ct_strong_encryption";
krista@1812
   371
        case PEP_ct_OpenPGP:
krista@1812
   372
            return "PEP_ct_OpenPGP";
krista@1812
   373
        case PEP_ct_OTR:
krista@1812
   374
            return "PEP_ct_OTR";
krista@1812
   375
        case PEP_ct_confirmed_enc_anon:
krista@1812
   376
            return "PEP_ct_confirmed_enc_anon";
krista@1812
   377
        case PEP_ct_pEp:
krista@1812
   378
            return "PEP_ct_pEp";
krista@1812
   379
        default:
krista@1812
   380
            return "PEP_ct_OMGWTFBBQ\n\nIn other words, comm type is invalid. Either something's corrupt or a new ct value has been added to the enum but not to the test function.";
krista@1812
   381
    }
krista@1812
   382
}
krista@2703
   383
krista@2995
   384
bool slurp_and_import_key(PEP_SESSION session, const char* key_filename) {
krista@2995
   385
    std::string keyfile = slurp(key_filename);
krista@3276
   386
    if (import_key(session, keyfile.c_str(), keyfile.size(), NULL) != PEP_TEST_KEY_IMPORT_SUCCESS)
krista@2995
   387
        return false;
krista@2995
   388
    return true;
krista@2995
   389
}
krista@2995
   390
krista@2703
   391
bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename) {
krista@2995
   392
    bool ok = true;
krista@2703
   393
    message = slurp(message_fname);
krista@2995
   394
    if (key_filename)
krista@2995
   395
        ok = slurp_and_import_key(session, key_filename);
krista@2995
   396
    return ok;
krista@2703
   397
}
krista@2703
   398
krista@2703
   399
krista@2703
   400
krista@2703
   401
int util_delete_filepath(const char *filepath, 
krista@2703
   402
                         const struct stat *file_stat, 
krista@2703
   403
                         int ftw_info, 
krista@2703
   404
                         struct FTW * ftw_struct) {
krista@2703
   405
    int retval = 0;
krista@2703
   406
    switch (ftw_info) {
krista@2703
   407
        case FTW_DP:
krista@2703
   408
            retval = rmdir(filepath);
krista@2703
   409
            break;
krista@2703
   410
        case FTW_F:
krista@2703
   411
        case FTW_SLN:
krista@2703
   412
            retval = unlink(filepath);
krista@2703
   413
            break;    
krista@2703
   414
        default:
krista@2703
   415
            retval = -1;
krista@2703
   416
    }
krista@2703
   417
    
krista@2703
   418
    return retval;
krista@2703
   419
}