more const, more variable initializations
authorRoker <roker@pep-project.org>
Tue, 21 Jun 2016 18:08:05 +0200
changeset 7529c53a8bc555d
parent 751 78a762326f20
child 753 dd21cdff7492
more const, more variable initializations
test/pEpEngineTest.cc
     1.1 --- a/test/pEpEngineTest.cc	Tue Jun 21 17:52:03 2016 +0200
     1.2 +++ b/test/pEpEngineTest.cc	Tue Jun 21 18:08:05 2016 +0200
     1.3 @@ -103,17 +103,14 @@
     1.4      const char** kf = kflist;
     1.5      while(*kf){
     1.6          const Buffer k_user_buffer =  ReadFileIntoMem(*kf);
     1.7 -        const size_t k_user_length = k_user_buffer.size();
     1.8          cout << "import_key(" << *kf << ")\n";
     1.9 -        PEP_STATUS import_status = import_key(session, k_user_buffer.data(), k_user_length, NULL);
    1.10 +        PEP_STATUS import_status = import_key(session, k_user_buffer.data(), k_user_buffer.size(), NULL);
    1.11          assert(import_status == PEP_STATUS_OK);
    1.12          cout << "successfully imported key\n";
    1.13          kf++;
    1.14      }
    1.15  
    1.16 -    Buffer cipher_buffer = ReadFileIntoMem("msg.asc");
    1.17 -    const size_t cipher_length = cipher_buffer.size();
    1.18 -
    1.19 +    const Buffer cipher_buffer = ReadFileIntoMem("msg.asc");
    1.20      cout << "\n" << cipher_buffer.data();
    1.21  
    1.22      char *buf_text = NULL;
    1.23 @@ -121,7 +118,7 @@
    1.24      stringlist_t *keylist;
    1.25  
    1.26      cout << "calling decrypt_and_verify()\n";
    1.27 -    PEP_STATUS decrypt_result = decrypt_and_verify(session, cipher_buffer.data(), cipher_length, &buf_text, &buf_size, &keylist);
    1.28 +    PEP_STATUS decrypt_result = decrypt_and_verify(session, cipher_buffer.data(), cipher_buffer.size(), &buf_text, &buf_size, &keylist);
    1.29  
    1.30      cout << "returning from decrypt_and_verify() with result == 0x" << std::hex << decrypt_result << "\n";
    1.31      assert(decrypt_result == PEP_DECRYPTED_AND_VERIFIED);
    1.32 @@ -135,29 +132,25 @@
    1.33  
    1.34      free_stringlist(keylist);
    1.35      buf_text[buf_size] = 0;
    1.36 -    string plain(buf_text);
    1.37 +    const string plain(buf_text);
    1.38      pEp_free(buf_text);
    1.39      cout << "\n" << plain;
    1.40  
    1.41 -    Buffer t1_buffer = ReadFileIntoMem("t1.txt");
    1.42 -    const size_t t1_length = t1_buffer.size();
    1.43 -
    1.44 -    Buffer sig_buffer = ReadFileIntoMem("signature.asc");
    1.45 -    const size_t sig_length = sig_buffer.size();
    1.46 +    const Buffer t1_buffer = ReadFileIntoMem("t1.txt");
    1.47 +    const Buffer sig_buffer = ReadFileIntoMem("signature.asc");
    1.48  
    1.49      cout << "\ncalling verify_text()\n";
    1.50 -    PEP_STATUS verify_result = verify_text(session, t1_buffer.data(), t1_length, sig_buffer.data(), sig_length, &keylist);
    1.51 +    PEP_STATUS verify_result = verify_text(session, t1_buffer.data(), t1_buffer.size(), sig_buffer.data(), sig_buffer.size(), &keylist);
    1.52      cout << "returning from verify_text() with result == " << verify_result << "\n";
    1.53      assert(verify_result == PEP_VERIFIED || verify_result == PEP_VERIFIED_AND_TRUSTED);
    1.54      assert(keylist->value);
    1.55      cout << "signed with " << keylist->value << "\n";
    1.56      free_stringlist(keylist);
    1.57  
    1.58 -    Buffer t2_buffer = ReadFileIntoMem("t2.txt");
    1.59 -    size_t t2_length = t2_buffer.size();
    1.60 +    const Buffer t2_buffer = ReadFileIntoMem("t2.txt");
    1.61  
    1.62      cout << "\ncalling verify_text()\n";
    1.63 -    verify_result = verify_text(session, t2_buffer.data(), t2_length, sig_buffer.data(), sig_length, &keylist);
    1.64 +    verify_result = verify_text(session, t2_buffer.data(), t2_buffer.size(), sig_buffer.data(), sig_buffer.size(), &keylist);
    1.65      assert(verify_result == PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
    1.66      free_stringlist(keylist);
    1.67  
    1.68 @@ -174,21 +167,21 @@
    1.69      assert(encrypt_result == PEP_STATUS_OK);
    1.70      free_stringlist(keylist);
    1.71  
    1.72 -    buf_text[buf_size] = 0;
    1.73 -    string cipher2(buf_text);
    1.74 +    buf_text[buf_size] = '\0';
    1.75 +    const string cipher2(buf_text);
    1.76      cout << "\n" << cipher2;
    1.77      pEp_free(buf_text);
    1.78  
    1.79      cout << "\nfinding English trustword for 2342...\n";
    1.80 -    char * word;
    1.81 +    char * word = NULL;
    1.82      size_t wsize;
    1.83      trustword(session, 2342, "en", &word, &wsize);
    1.84      assert(word);
    1.85      cout << "the trustword for 2342 is " << word << "\n";
    1.86      pEp_free(word);
    1.87  
    1.88 -    string fingerprint = "4942 2235 FC99 585B 891C  6653 0C7B 109B FA72 61F7";
    1.89 -    char * words;
    1.90 +    const string fingerprint = "4942 2235 FC99 585B 891C  6653 0C7B 109B FA72 61F7";
    1.91 +    char * words = NULL;
    1.92  
    1.93      cout << "\nfinding German trustwords for " << fingerprint << "...\n";
    1.94      trustwords(session, fingerprint.c_str(), "de", &words, &wsize, 5);
    1.95 @@ -232,11 +225,11 @@
    1.96      assert(generate_status == PEP_STATUS_OK);
    1.97      cout << "generated key is " << identity->fpr << "\n";
    1.98  
    1.99 -    string key(identity->fpr);
   1.100 +    const string key(identity->fpr);
   1.101      free_identity(identity);
   1.102  
   1.103 -    char *key_data;
   1.104 -    size_t size;
   1.105 +    char *key_data = NULL;
   1.106 +    size_t size = 0;
   1.107  
   1.108      cout << "export_key()\n\n";
   1.109      PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
   1.110 @@ -255,6 +248,7 @@
   1.111      cout << "successfully imported key\n";
   1.112  
   1.113      pEp_free(key_data);
   1.114 +    key_data=NULL;
   1.115  
   1.116      cout << "deleting key " << key.c_str() << " again\n";
   1.117      delete_status = delete_keypair(session, key.c_str());