IOSAD-72 outgoingRatingForMessage -> NSNumber
authorDirk Zimmermann <dirk@pep-project.org>
Sat, 14 Apr 2018 14:19:03 +0200
changeset 573bc2c03efe133
parent 572 b58713ee0c59
child 574 03a019b2533b
IOSAD-72 outgoingRatingForMessage -> NSNumber
pEpObjCAdapter/NSNumber+PEPRating.h
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPSession.h
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCAdapter/NSNumber+PEPRating.h	Fri Apr 13 11:09:55 2018 +0200
     1.2 +++ b/pEpObjCAdapter/NSNumber+PEPRating.h	Sat Apr 14 14:19:03 2018 +0200
     1.3 @@ -11,12 +11,13 @@
     1.4  #import "message_api.h"
     1.5  
     1.6  /**
     1.7 - Extension for handling the engine's PEP_rating inside a NSNumber.
     1.8 + Extension for wrapping the engine's PEP_rating inside a NSNumber.
     1.9   */
    1.10  @interface NSNumber (Extension)
    1.11  
    1.12 +@property (nonatomic) PEP_rating pEpRating;
    1.13 +
    1.14  - initWithPEPRating:(PEP_rating)pEpRating;
    1.15 -- (PEP_rating)pEpRating;
    1.16  
    1.17  + (NSNumber *)numberWithPEPRating:(PEP_rating)pEpRating;
    1.18  
     2.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Fri Apr 13 11:09:55 2018 +0200
     2.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Sat Apr 14 14:19:03 2018 +0200
     2.3 @@ -18,6 +18,7 @@
     2.4  #import "PEPMessage.h"
     2.5  #import "NSError+PEP.h"
     2.6  #import "PEPAutoPointer.h"
     2.7 +#import "NSNumber+PEPRating.h"
     2.8  
     2.9  @implementation PEPInternalSession
    2.10  
    2.11 @@ -372,31 +373,29 @@
    2.12      return encrypted;
    2.13  }
    2.14  
    2.15 -- (BOOL)outgoingRating:(PEP_rating * _Nonnull)rating
    2.16 -        forMessageDict:(PEPDict * _Nonnull)messageDict
    2.17 -                 error:(NSError * _Nullable * _Nullable)error
    2.18 +- (NSNumber * _Nullable)outgoingRatingForMessageDict:(PEPDict * _Nonnull)messageDict
    2.19 +                                               error:(NSError * _Nullable * _Nullable)error
    2.20  {
    2.21      message *_msg = PEP_messageDictToStruct(messageDict);
    2.22 -    *rating = PEP_rating_undefined;
    2.23 +    PEP_rating rating = PEP_rating_b0rken;
    2.24  
    2.25      [self lockWrite];
    2.26 -    PEP_STATUS status = outgoing_message_rating(_session, _msg, rating);
    2.27 +    PEP_STATUS status = outgoing_message_rating(_session, _msg, &rating);
    2.28      [self unlockWrite];
    2.29  
    2.30      free_message(_msg);
    2.31  
    2.32      if ([NSError setError:error fromPEPStatus:status]) {
    2.33 -        return NO;
    2.34 +        return nil;
    2.35      }
    2.36  
    2.37 -    return YES;
    2.38 +    return [NSNumber numberWithPEPRating:rating];
    2.39  }
    2.40  
    2.41 -- (BOOL)outgoingRating:(PEP_rating * _Nonnull)rating
    2.42 -            forMessage:(PEPMessage * _Nonnull)message
    2.43 -                 error:(NSError * _Nullable * _Nullable)error
    2.44 +- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)message
    2.45 +                                           error:(NSError * _Nullable * _Nullable)error
    2.46  {
    2.47 -    return [self outgoingRating:rating forMessageDict:(NSDictionary *) message error:error];
    2.48 +    return [self outgoingRatingForMessageDict:(NSDictionary *) message error:error];
    2.49  }
    2.50  
    2.51  - (BOOL)rating:(PEP_rating * _Nonnull)rating
     3.1 --- a/pEpObjCAdapter/PEPSession.h	Fri Apr 13 11:09:55 2018 +0200
     3.2 +++ b/pEpObjCAdapter/PEPSession.h	Sat Apr 14 14:19:03 2018 +0200
     3.3 @@ -11,6 +11,8 @@
     3.4  #import "PEPSessionProtocol.h"
     3.5  #import "PEPMessageUtil.h"
     3.6  
     3.7 +#import "NSNumber+PEPRating.h"
     3.8 +
     3.9  /**
    3.10   Fake session to handle to the client.
    3.11  
     4.1 --- a/pEpObjCAdapter/PEPSession.m	Fri Apr 13 11:09:55 2018 +0200
     4.2 +++ b/pEpObjCAdapter/PEPSession.m	Sat Apr 14 14:19:03 2018 +0200
     4.3 @@ -138,12 +138,11 @@
     4.4              error:error];
     4.5  }
     4.6  
     4.7 -- (BOOL)outgoingRating:(PEP_rating * _Nonnull)rating
     4.8 -            forMessage:(PEPMessage * _Nonnull)message
     4.9 -                 error:(NSError * _Nullable * _Nullable)error
    4.10 +- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)message
    4.11 +                                           error:(NSError * _Nullable * _Nullable)error
    4.12  {
    4.13      PEPInternalSession *session = [PEPSessionProvider session];
    4.14 -    return [session outgoingRating:rating forMessage:message error:error];
    4.15 +    return [session outgoingRatingForMessage:message error:error];
    4.16  }
    4.17  
    4.18  - (BOOL)rating:(PEP_rating * _Nonnull)rating
     5.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Fri Apr 13 11:09:55 2018 +0200
     5.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Sat Apr 14 14:19:03 2018 +0200
     5.3 @@ -87,9 +87,8 @@
     5.4                                     error:(NSError * _Nullable * _Nullable)error;
     5.5  
     5.6  /** Determine the status color of a message to be sent */
     5.7 -- (BOOL)outgoingRating:(PEP_rating * _Nonnull)rating
     5.8 -            forMessage:(PEPMessage * _Nonnull)message
     5.9 -                 error:(NSError * _Nullable * _Nullable)error;
    5.10 +- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)message
    5.11 +                                           error:(NSError * _Nullable * _Nullable)error;
    5.12  
    5.13  /**
    5.14   Determine the rating of an identity.
     6.1 --- a/pEpObjCTests/PEPSessionTest.m	Fri Apr 13 11:09:55 2018 +0200
     6.2 +++ b/pEpObjCTests/PEPSessionTest.m	Sat Apr 14 14:19:03 2018 +0200
     6.3 @@ -12,7 +12,6 @@
     6.4  #import "NSDictionary+Extension.h"
     6.5  #import "PEPIdentity.h"
     6.6  #import "PEPMessage.h"
     6.7 -
     6.8  #import "PEPTestUtils.h"
     6.9  #import "PEPTestSyncDelegate.h"
    6.10  
    6.11 @@ -473,9 +472,10 @@
    6.12          NSError *error = nil;
    6.13  
    6.14          // Test with unknown Bob
    6.15 -        PEP_rating rating;
    6.16 -        XCTAssertTrue([session outgoingRating:&rating forMessage:msgGray error:&error]);
    6.17 -        XCTAssertEqual(rating, PEP_rating_unencrypted);
    6.18 +        NSNumber *numRating = [session outgoingRatingForMessage:msgGray error:&error];
    6.19 +        XCTAssertNotNil(numRating);
    6.20 +        XCTAssertNil(error);
    6.21 +        XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
    6.22      }
    6.23  
    6.24      PEPIdentity *identBob = [self
    6.25 @@ -496,12 +496,12 @@
    6.26      NSError *error = nil;
    6.27  
    6.28      // Should be yellow, since no handshake happened.
    6.29 -    PEP_rating rating;
    6.30 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
    6.31 +    NSNumber *numRating = [session outgoingRatingForMessage:msg error:&error];
    6.32 +    XCTAssertNotNil(numRating);
    6.33      XCTAssertNil(error);
    6.34 -    XCTAssertEqual(rating, PEP_rating_reliable);
    6.35 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
    6.36  
    6.37 -    rating = [self ratingForIdentity:identBob session:session];
    6.38 +    PEP_rating rating = [self ratingForIdentity:identBob session:session];
    6.39      XCTAssertEqual(rating, PEP_rating_reliable);
    6.40  
    6.41      // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
    6.42 @@ -509,8 +509,10 @@
    6.43      XCTAssertNil(error);
    6.44  
    6.45      // This time it should be green
    6.46 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
    6.47 -    XCTAssertEqual(rating, PEP_rating_trusted);
    6.48 +    numRating = [session outgoingRatingForMessage:msg error:&error];
    6.49 +    XCTAssertNotNil(numRating);
    6.50 +    XCTAssertNil(error);
    6.51 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted);
    6.52  
    6.53      rating = [self ratingForIdentity:identBob session:session];
    6.54      XCTAssertEqual(rating, PEP_rating_trusted);
    6.55 @@ -520,8 +522,10 @@
    6.56      XCTAssertNil(error);
    6.57  
    6.58      // Yellow ?
    6.59 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
    6.60 -    XCTAssertEqual(rating, PEP_rating_reliable);
    6.61 +    numRating = [session outgoingRatingForMessage:msg error:&error];
    6.62 +    XCTAssertNotNil(numRating);
    6.63 +    XCTAssertNil(error);
    6.64 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
    6.65  
    6.66      // mistrust Bob
    6.67      XCTAssertTrue([session keyMistrusted:identBob error:&error]);
    6.68 @@ -533,8 +537,10 @@
    6.69      XCTAssertNil(identBob.fingerPrint);
    6.70  
    6.71      // Gray == PEP_rating_unencrypted
    6.72 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
    6.73 -    XCTAssertEqual(rating, PEP_rating_unencrypted);
    6.74 +    numRating = [session outgoingRatingForMessage:msg error:&error];
    6.75 +    XCTAssertNotNil(numRating);
    6.76 +    XCTAssertNil(error);
    6.77 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
    6.78  
    6.79      // Undo
    6.80      XCTAssertTrue([session undoLastMistrustWithError:&error]);
    6.81 @@ -544,10 +550,12 @@
    6.82      XCTAssertNotNil(identBob.fingerPrint);
    6.83  
    6.84      // Back to yellow
    6.85 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
    6.86 +    numRating = [session outgoingRatingForMessage:msg error:&error];
    6.87 +    XCTAssertNotNil(numRating);
    6.88 +    XCTAssertNil(error);
    6.89  
    6.90      // After ENGINE-371 has been fixed, this should be just PEP_rating_reliable
    6.91 -    XCTAssertEqual(rating, PEP_rating_trusted);
    6.92 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted);
    6.93      XCTAssertEqual([self ratingForIdentity:identBob session:session], PEP_rating_trusted);
    6.94  
    6.95      // Trust again
    6.96 @@ -555,8 +563,10 @@
    6.97      XCTAssertNil(error);
    6.98  
    6.99      // Back to green
   6.100 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.101 -    XCTAssertEqual(rating, PEP_rating_trusted);
   6.102 +    numRating = [session outgoingRatingForMessage:msg error:&error];
   6.103 +    XCTAssertNotNil(numRating);
   6.104 +    XCTAssertNil(error);
   6.105 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted);
   6.106  
   6.107      // Now let see if it turns back yellow if we add an unconfirmed folk.
   6.108      // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
   6.109 @@ -575,8 +585,10 @@
   6.110      msg.cc = @[[PEPTestUtils foreignPepIdentityWithAddress:@"pep.test.john@pep-project.org"
   6.111                                                    userName:@"pEp Test John"]];
   6.112      // Yellow ?
   6.113 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.114 -    XCTAssertEqual(rating, PEP_rating_reliable);
   6.115 +    numRating = [session outgoingRatingForMessage:msg error:&error];
   6.116 +    XCTAssertNotNil(numRating);
   6.117 +    XCTAssertNil(error);
   6.118 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
   6.119  
   6.120      PEPMessage *encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
   6.121      XCTAssertNotNil(encMsg);
   6.122 @@ -617,8 +629,10 @@
   6.123  
   6.124      // Test with unknown Bob
   6.125      PEP_rating rating;
   6.126 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.127 -    XCTAssertEqual(rating, PEP_rating_unencrypted);
   6.128 +    NSNumber *numRating = [session outgoingRatingForMessage:msg error:&error];
   6.129 +    XCTAssertNotNil(numRating);
   6.130 +    XCTAssertNil(error);
   6.131 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
   6.132  
   6.133      // Now let see with bob's pubkey already known
   6.134      // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
   6.135 @@ -635,8 +649,10 @@
   6.136      XCTAssertNil(error);
   6.137  
   6.138      // Should be yellow, since no handshake happened.
   6.139 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.140 -    XCTAssertEqual(rating, PEP_rating_reliable);
   6.141 +    numRating = [session outgoingRatingForMessage:msg error:&error];
   6.142 +    XCTAssertNotNil(numRating);
   6.143 +    XCTAssertNil(error);
   6.144 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
   6.145  
   6.146      rating = [self ratingForIdentity:identBob session:session];
   6.147      XCTAssertEqual(rating, PEP_rating_reliable);
   6.148 @@ -646,8 +662,10 @@
   6.149      XCTAssertNil(error);
   6.150  
   6.151      // This time it should be green
   6.152 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.153 -    XCTAssertEqual(rating, PEP_rating_trusted);
   6.154 +    numRating = [session outgoingRatingForMessage:msg error:&error];
   6.155 +    XCTAssertNotNil(numRating);
   6.156 +    XCTAssertNil(error);
   6.157 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted);
   6.158  
   6.159      rating = [self ratingForIdentity:identBob session:session];
   6.160      XCTAssertEqual(rating, PEP_rating_trusted);
   6.161 @@ -670,15 +688,19 @@
   6.162                                                userID:@"101" userName:@"pEp Test John" isOwn:NO]];
   6.163  
   6.164      // Yellow ?
   6.165 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.166 -    XCTAssertEqual(rating, PEP_rating_reliable);
   6.167 +    numRating = [session outgoingRatingForMessage:msg error:&error];
   6.168 +    XCTAssertNotNil(numRating);
   6.169 +    XCTAssertNil(error);
   6.170 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
   6.171  
   6.172      XCTAssertTrue([session trustPersonalKey:identJohn error:&error]);
   6.173      XCTAssertNil(error);
   6.174  
   6.175      // This time it should be green
   6.176 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.177 -    XCTAssertEqual(rating, PEP_rating_trusted);
   6.178 +    numRating = [session outgoingRatingForMessage:msg error:&error];
   6.179 +    XCTAssertNotNil(numRating);
   6.180 +    XCTAssertNil(error);
   6.181 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted);
   6.182  
   6.183      rating = [self ratingForIdentity:identJohn session:session];
   6.184      XCTAssertEqual(rating, PEP_rating_trusted);
   6.185 @@ -730,9 +752,10 @@
   6.186      msg.direction = PEP_dir_outgoing;
   6.187  
   6.188      // Gray == PEP_rating_unencrypted
   6.189 -    PEP_rating rating;
   6.190 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.191 -    XCTAssertEqual(rating, PEP_rating_unencrypted);
   6.192 +    NSNumber *numRating = [session outgoingRatingForMessage:msg error:&error];
   6.193 +    XCTAssertNotNil(numRating);
   6.194 +    XCTAssertNil(error);
   6.195 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
   6.196  
   6.197      PEPMessage *encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
   6.198      XCTAssertNotNil(encMsg);
   6.199 @@ -805,9 +828,10 @@
   6.200      msg.longMessage = @"This is a text content";
   6.201      msg.direction = PEP_dir_outgoing;
   6.202  
   6.203 -    PEP_rating rating;
   6.204 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.205 -    XCTAssertEqual(rating, PEP_rating_trusted_and_anonymized);
   6.206 +    NSNumber *numRating = [session outgoingRatingForMessage:msg error:&error];
   6.207 +    XCTAssertNotNil(numRating);
   6.208 +    XCTAssertNil(error);
   6.209 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted_and_anonymized);
   6.210  
   6.211      PEPMessage *encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
   6.212      XCTAssertNotNil(encMsg);
   6.213 @@ -816,6 +840,7 @@
   6.214      NSArray *keys;
   6.215  
   6.216      error = nil;
   6.217 +    PEP_rating rating = PEP_rating_b0rken;
   6.218      PEPMessage *decmsg = [session
   6.219                            decryptMessage:encMsg
   6.220                            rating:&rating
   6.221 @@ -1032,9 +1057,10 @@
   6.222      msg.longMessage = @"Alice?";
   6.223      msg.direction = PEP_dir_outgoing;
   6.224  
   6.225 -    PEP_rating rating;
   6.226 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.227 -    XCTAssertEqual(rating, PEP_rating_unencrypted);
   6.228 +    NSNumber *numRating = [session outgoingRatingForMessage:msg error:&error];
   6.229 +    XCTAssertNotNil(numRating);
   6.230 +    XCTAssertNil(error);
   6.231 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
   6.232  
   6.233      PEPMessage *encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
   6.234      XCTAssertNotNil(encMsg);
   6.235 @@ -1370,9 +1396,10 @@
   6.236      msg.longMessage = @"Alice?";
   6.237      msg.direction = PEP_dir_outgoing;
   6.238  
   6.239 -    PEP_rating rating;
   6.240 -    XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   6.241 -    XCTAssertEqual(rating, PEP_rating_reliable);
   6.242 +    NSNumber *numRating = [session outgoingRatingForMessage:msg error:&error];
   6.243 +    XCTAssertNotNil(numRating);
   6.244 +    XCTAssertNil(error);
   6.245 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
   6.246  
   6.247      PEPMessage *encMsg;
   6.248