implementing PEP_rating_unencrypted_for_some
authorVolker Birk <vb@pep-project.org>
Wed, 02 Mar 2016 10:00:04 +0100
changeset 48682210e6ef7f7
parent 485 05643db87f77
child 487 8562a4a79856
implementing PEP_rating_unencrypted_for_some
src/message_api.c
src/message_api.h
     1.1 --- a/src/message_api.c	Wed Mar 02 09:26:45 2016 +0100
     1.2 +++ b/src/message_api.c	Wed Mar 02 10:00:04 2016 +0100
     1.3 @@ -588,6 +588,8 @@
     1.4          return "have_no_key";
     1.5      case PEP_rating_unencrypted:
     1.6          return "unencrypted";
     1.7 +    case PEP_rating_unencrypted_for_some:
     1.8 +        return "unencrypted_for_some";
     1.9      case PEP_rating_unreliable:
    1.10          return "unreliable";
    1.11      case PEP_rating_reliable:
    1.12 @@ -629,7 +631,7 @@
    1.13      }
    1.14  }
    1.15  
    1.16 -static PEP_color _rating(PEP_comm_type ct)
    1.17 +static PEP_color _rating(PEP_comm_type ct, PEP_color color)
    1.18  {
    1.19      if (ct == PEP_ct_unknown)
    1.20          return PEP_rating_undefined;
    1.21 @@ -640,7 +642,21 @@
    1.22      else if (ct == PEP_ct_mistrusted)
    1.23          return PEP_rating_mistrust;
    1.24      
    1.25 -    else if (ct >= PEP_ct_confirmed_enc_anon)
    1.26 +    if (color == PEP_rating_unencrypted_for_some)
    1.27 +        return PEP_rating_unencrypted_for_some;
    1.28 +
    1.29 +    if (ct == PEP_ct_no_encryption || ct == PEP_ct_no_encrypted_channel ||
    1.30 +            ct == PEP_ct_my_key_not_included) {
    1.31 +        if (color > PEP_rating_unencrypted_for_some)
    1.32 +            return PEP_rating_unencrypted_for_some;
    1.33 +        else
    1.34 +            return PEP_rating_unencrypted;
    1.35 +    }
    1.36 +
    1.37 +    if (color == PEP_rating_unencrypted)
    1.38 +        return PEP_rating_unencrypted_for_some;
    1.39 +
    1.40 +    if (ct >= PEP_ct_confirmed_enc_anon)
    1.41          return PEP_rating_trusted_and_anonymized;
    1.42  
    1.43      else if (ct >= PEP_ct_strong_encryption)
    1.44 @@ -649,10 +665,6 @@
    1.45      else if (ct >= PEP_ct_strong_but_unconfirmed && ct < PEP_ct_confirmed)
    1.46          return PEP_rating_reliable;
    1.47  
    1.48 -    else if (ct == PEP_ct_no_encryption || ct == PEP_ct_no_encrypted_channel ||
    1.49 -            ct == PEP_ct_my_key_not_included)
    1.50 -        return PEP_rating_unencrypted;
    1.51 -
    1.52      else
    1.53          return PEP_rating_unreliable;
    1.54  }
    1.55 @@ -750,7 +762,7 @@
    1.56      if (status != PEP_STATUS_OK)
    1.57          return PEP_rating_undefined;
    1.58  
    1.59 -    return _rating(comm_type);
    1.60 +    return _rating(comm_type, PEP_rating_undefined);
    1.61  }
    1.62  
    1.63  static PEP_color keylist_color(PEP_SESSION session, stringlist_t *keylist)
    1.64 @@ -759,25 +771,32 @@
    1.65  
    1.66      assert(keylist && keylist->value);
    1.67      if (keylist == NULL || keylist->value == NULL)
    1.68 -        return PEP_rating_unencrypted;
    1.69 +        return PEP_rating_undefined;
    1.70  
    1.71      stringlist_t *_kl;
    1.72      for (_kl = keylist; _kl && _kl->value; _kl = _kl->next) {
    1.73          PEP_comm_type ct;
    1.74          PEP_STATUS status;
    1.75  
    1.76 -        color = key_color(session, _kl->value);
    1.77 -        if (color <= PEP_rating_mistrust)
    1.78 -            return color;
    1.79 +        PEP_color _color = key_color(session, _kl->value);
    1.80 +        if (_color <= PEP_rating_mistrust)
    1.81 +            return _color;
    1.82  
    1.83 -        if (color >= PEP_rating_reliable) {
    1.84 +        if (color == PEP_rating_undefined)
    1.85 +            color = _color;
    1.86 +
    1.87 +        if (_color >= PEP_rating_reliable) {
    1.88              status = least_trust(session, _kl->value, &ct);
    1.89              if (status != PEP_STATUS_OK)
    1.90                  return PEP_rating_undefined;
    1.91              if (ct == PEP_ct_unknown)
    1.92 -                color = PEP_rating_unreliable;
    1.93 +                color = PEP_rating_unencrypted_for_some;
    1.94              else
    1.95 -                color = _rating(ct);
    1.96 +                color = _rating(ct, color);
    1.97 +        }
    1.98 +        else if (_color == PEP_rating_unencrypted) {
    1.99 +            if (color > PEP_rating_unencrypted_for_some)
   1.100 +                color = PEP_rating_unencrypted_for_some;
   1.101          }
   1.102      }
   1.103  
   1.104 @@ -1283,7 +1302,7 @@
   1.105                          goto enomem;
   1.106                      status = update_identity(session, _from);
   1.107                      if (_from->comm_type != PEP_ct_unknown)
   1.108 -                        *color = _rating(_from->comm_type);
   1.109 +                        *color = _rating(_from->comm_type, PEP_rating_undefined);
   1.110                      free_identity(_from);
   1.111                      if (status != PEP_STATUS_OK)
   1.112                          goto pep_error;
   1.113 @@ -1360,7 +1379,8 @@
   1.114      if (comm_type_determined == false)
   1.115          *color = PEP_rating_undefined;
   1.116      else
   1.117 -        *color = MAX(_rating(max_comm_type), PEP_rating_unencrypted);
   1.118 +        *color = MAX(_rating(max_comm_type, PEP_rating_undefined),
   1.119 +                PEP_rating_unencrypted);
   1.120  
   1.121      return PEP_STATUS_OK;
   1.122  }
   1.123 @@ -1386,7 +1406,7 @@
   1.124          status = update_identity(session, ident);
   1.125  
   1.126      if (status == PEP_STATUS_OK)
   1.127 -        *color = _rating(ident->comm_type);
   1.128 +        *color = _rating(ident->comm_type, PEP_rating_undefined);
   1.129  
   1.130      return status;
   1.131  }
     2.1 --- a/src/message_api.h	Wed Mar 02 09:26:45 2016 +0100
     2.2 +++ b/src/message_api.h	Wed Mar 02 10:00:04 2016 +0100
     2.3 @@ -49,6 +49,7 @@
     2.4      PEP_rating_cannot_decrypt,
     2.5      PEP_rating_have_no_key,
     2.6      PEP_rating_unencrypted,
     2.7 +    PEP_rating_unencrypted_for_some,
     2.8      PEP_rating_unreliable,
     2.9      PEP_rating_reliable,
    2.10      PEP_rating_yellow = PEP_rating_reliable,