decrypt_message now returns PEP_STATUS_OK if no error (and not decrypt_status in some rare cases, rating is here for that). re_evaluate_message_rating avoids returning ILLEGAL_VALUE if X-EncStatus is present but has 'undefined' value
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 07 Jun 2017 16:12:56 +0200
changeset 183293c627c7f709
parent 1827 277a39ed449b
child 1833 d6eaa3ebdf42
child 1835 ca0126bfcd52
child 1839 db1a28b13887
decrypt_message now returns PEP_STATUS_OK if no error (and not decrypt_status in some rare cases, rating is here for that). re_evaluate_message_rating avoids returning ILLEGAL_VALUE if X-EncStatus is present but has 'undefined' value
src/message_api.c
test/encrypt_for_identity_test.cc
     1.1 --- a/src/message_api.c	Tue Jun 06 18:11:09 2017 +0200
     1.2 +++ b/src/message_api.c	Wed Jun 07 16:12:56 2017 +0200
     1.3 @@ -2089,7 +2089,7 @@
     1.4      *dst = msg;
     1.5      *keylist = _keylist;
     1.6  
     1.7 -    return ERROR(status);
     1.8 +    return PEP_STATUS_OK;
     1.9  
    1.10  enomem:
    1.11      status = PEP_OUT_OF_MEMORY;
    1.12 @@ -2722,6 +2722,7 @@
    1.13      PEP_STATUS status = PEP_STATUS_OK;
    1.14      stringlist_t *_keylist = x_keylist;
    1.15      bool must_free_keylist = false;
    1.16 +    PEP_rating _rating;
    1.17  
    1.18      assert(session);
    1.19      assert(msg);
    1.20 @@ -2736,13 +2737,15 @@
    1.21          for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
    1.22              if (strcasecmp(i->value->key, "X-EncStatus") == 0){
    1.23                  x_enc_status = string_to_rating(i->value->value);
    1.24 -                break;
    1.25 +                goto got_rating;
    1.26              }
    1.27          }
    1.28 +        return ERROR(PEP_ILLEGAL_VALUE);
    1.29      }
    1.30 -    if (x_enc_status == PEP_rating_undefined)
    1.31 -        return ERROR(PEP_ILLEGAL_VALUE);
    1.32 -
    1.33 +
    1.34 +got_rating:
    1.35 +
    1.36 +    _rating = x_enc_status;
    1.37  
    1.38      if (_keylist == NULL){
    1.39          for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
    1.40 @@ -2751,14 +2754,12 @@
    1.41                  if (status != PEP_STATUS_OK)
    1.42                      GOTO(pep_error);
    1.43                  must_free_keylist = true;
    1.44 -                break;
    1.45 +                goto got_keylist;
    1.46              }
    1.47          }
    1.48 +        return ERROR(PEP_ILLEGAL_VALUE);
    1.49      }
    1.50 -    if (_keylist == NULL)
    1.51 -        return ERROR(PEP_ILLEGAL_VALUE);
    1.52 -
    1.53 -    PEP_rating _rating = x_enc_status;
    1.54 +got_keylist:
    1.55  
    1.56      status = amend_rating_according_to_sender_and_recipients(session,
    1.57                                                               &_rating,
     2.1 --- a/test/encrypt_for_identity_test.cc	Tue Jun 06 18:11:09 2017 +0200
     2.2 +++ b/test/encrypt_for_identity_test.cc	Wed Jun 07 16:12:56 2017 +0200
     2.3 @@ -94,7 +94,7 @@
     2.4      assert(decrypted_msg);
     2.5      assert(keylist_used);
     2.6      assert(rating);
     2.7 -    assert(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
     2.8 +    assert(status == PEP_STATUS_OK && rating == PEP_rating_unreliable);
     2.9      PEP_comm_type ct = encrypted_msg->from->comm_type;
    2.10      assert(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
    2.11  
    2.12 @@ -164,7 +164,7 @@
    2.13      assert(keylist_used);
    2.14      assert(mimerating);
    2.15                               
    2.16 -    assert(status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable);
    2.17 +    assert(status == PEP_STATUS_OK && mimerating == PEP_rating_unreliable);
    2.18  
    2.19      cout << "Decrypted message:" << endl;
    2.20      cout << decrypted_mimetext << endl;