IOSAD-61 (void)updateIdentity:(nonnull PEPIdentity *)identity IOSAD-61
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 06 Nov 2017 15:55:56 +0100
branchIOSAD-61
changeset 349db3e0a301fba
parent 348 1d887142880f
child 350 353c277a346b
IOSAD-61 (void)updateIdentity:(nonnull PEPIdentity *)identity
pEpObjCAdapter/PEPIdentity.h
pEpObjCAdapter/PEPIdentity.m
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
pEpObjCTests/iOSTests.m
     1.1 --- a/pEpObjCAdapter/PEPIdentity.h	Mon Nov 06 12:46:00 2017 +0100
     1.2 +++ b/pEpObjCAdapter/PEPIdentity.h	Mon Nov 06 15:55:56 2017 +0100
     1.3 @@ -77,6 +77,12 @@
     1.4  - (PEPDict * _Nonnull)dictionary;
     1.5  
     1.6  /**
     1.7 + This method should be removed once the adapter fully supports objects for identity
     1.8 + and message types insead of dictionaries.
     1.9 + */
    1.10 +- (PEPMutableDict * _Nonnull)mutableDictionary;
    1.11 +
    1.12 +/**
    1.13   Does this identity contain a PGP comm type? This can be used for determining
    1.14   if a communication partner is a pEp user or not.
    1.15   */
     2.1 --- a/pEpObjCAdapter/PEPIdentity.m	Mon Nov 06 12:46:00 2017 +0100
     2.2 +++ b/pEpObjCAdapter/PEPIdentity.m	Mon Nov 06 15:55:56 2017 +0100
     2.3 @@ -75,6 +75,12 @@
     2.4      return (PEPDict *) self;
     2.5  }
     2.6  
     2.7 +- (PEPMutableDict * _Nonnull)mutableDictionary
     2.8 +{
     2.9 +    // most adapter use should be ok.
    2.10 +    return (PEPMutableDict *) self;
    2.11 +}
    2.12 +
    2.13  - (BOOL)containsPGPCommType
    2.14  {
    2.15      PEP_comm_type val = (PEP_comm_type) self.commType;
     3.1 --- a/pEpObjCAdapter/PEPSession.m	Mon Nov 06 12:46:00 2017 +0100
     3.2 +++ b/pEpObjCAdapter/PEPSession.m	Mon Nov 06 15:55:56 2017 +0100
     3.3 @@ -69,9 +69,9 @@
     3.4      [PEPSession mySelf:identity];
     3.5  }
     3.6  
     3.7 -- (void)updateIdentity:(nonnull PEPMutableDict *)identity
     3.8 +- (void)updateIdentity:(nonnull PEPIdentity *)identity
     3.9  {
    3.10 -    if ([identity[kPepIsOwnIdentity] boolValue]) {
    3.11 +    if (identity.isOwn) {
    3.12          [PEPSession mySelf:identity];
    3.13      } else {
    3.14          [PEPSession updateIdentity:identity];
    3.15 @@ -204,7 +204,7 @@
    3.16      [session mySelf:identity];
    3.17  }
    3.18  
    3.19 -+ (void)updateIdentity:(nonnull PEPMutableDict *)identity
    3.20 ++ (void)updateIdentity:(nonnull PEPIdentity *)identity
    3.21  {
    3.22      PEPInternalSession *session = [PEPSessionProvider session];
    3.23      [session updateIdentity:identity];
     4.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Mon Nov 06 12:46:00 2017 +0100
     4.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Mon Nov 06 15:55:56 2017 +0100
     4.3 @@ -76,7 +76,7 @@
     4.4   Supplement missing information for an arbitrary identity (used for communication partners).
     4.5   See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
     4.6   */
     4.7 -- (void)updateIdentity:(nonnull PEPMutableDict *)identity;
     4.8 +- (void)updateIdentity:(nonnull PEPIdentity *)identity;
     4.9  
    4.10  /**
    4.11   Mark a key as trusted with a person.
     5.1 --- a/pEpObjCTests/iOSTests.m	Mon Nov 06 12:46:00 2017 +0100
     5.2 +++ b/pEpObjCTests/iOSTests.m	Mon Nov 06 15:55:56 2017 +0100
     5.3 @@ -273,11 +273,9 @@
     5.4      [self pEpSetUp];
     5.5      [PEPObjCAdapter startKeyserverLookup];
     5.6      
     5.7 -    NSMutableDictionary *ident = [NSMutableDictionary dictionaryWithObjectsAndKeys:
     5.8 -                                    @"pEpDontAssert", kPepUsername,
     5.9 -                                    @"vb@ulm.ccc.de", kPepAddress,
    5.10 -                                    @"SsI6H9", kPepUserID,
    5.11 -                                    nil];
    5.12 +    PEPIdentity *ident = [[PEPIdentity alloc] initWithAddress:@"vb@ulm.ccc.de"
    5.13 +                                                          userID:@"SsI6H9"
    5.14 +                                                        userName:@"pEpDontAssert"];
    5.15      
    5.16      [session updateIdentity:ident];
    5.17      
    5.18 @@ -286,7 +284,7 @@
    5.19      // FIXME: updateIdentity should not assert if username is not provided
    5.20      [session updateIdentity:ident];
    5.21      
    5.22 -    XCTAssert(ident[kPepFingerprint]);
    5.23 +    XCTAssert(ident.fingerPrint);
    5.24      
    5.25      [PEPObjCAdapter stopKeyserverLookup];
    5.26      [self pEpCleanUp];
    5.27 @@ -441,12 +439,10 @@
    5.28      // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
    5.29      [self importBundledKey:@"0xC9C2EE39.asc"];
    5.30      
    5.31 -    NSMutableDictionary *identBob = [NSMutableDictionary dictionaryWithObjectsAndKeys:
    5.32 -                                     @"pEp Test Bob", kPepUsername,
    5.33 -                                     @"pep.test.bob@pep-project.org", kPepAddress,
    5.34 -                                     @"42", kPepUserID,
    5.35 -                                     @"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",kPepFingerprint,
    5.36 -                                     nil];
    5.37 +    PEPIdentity *identBob = [[PEPIdentity alloc]
    5.38 +                             initWithAddress:@"pep.test.bob@pep-project.org"
    5.39 +                             userID:@"42" userName:@"pEp Test Bob"
    5.40 +                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
    5.41      
    5.42      [session updateIdentity:identBob];
    5.43  
    5.44 @@ -454,42 +450,42 @@
    5.45      clr = [session outgoingMessageColor:msg];
    5.46      XCTAssert( clr == PEP_rating_reliable);
    5.47  
    5.48 -    clr = [session identityRating:identBob];
    5.49 +    clr = [session identityRating:identBob.dictionary];
    5.50      XCTAssert( clr == PEP_rating_reliable);
    5.51      
    5.52      // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
    5.53 -    [session trustPersonalKey:identBob];
    5.54 +    [session trustPersonalKey:identBob.mutableDictionary];
    5.55  
    5.56      // This time it should be green
    5.57      clr = [session outgoingMessageColor:msg];
    5.58      XCTAssert( clr == PEP_rating_trusted);
    5.59  
    5.60 -    clr = [session identityRating:identBob];
    5.61 +    clr = [session identityRating:identBob.dictionary];
    5.62      XCTAssert( clr == PEP_rating_trusted);
    5.63  
    5.64      // Let' say we undo handshake
    5.65 -    [session keyResetTrust:identBob];
    5.66 +    [session keyResetTrust:identBob.mutableDictionary];
    5.67      
    5.68      // Yellow ?
    5.69      clr = [session outgoingMessageColor:msg];
    5.70      XCTAssert( clr == PEP_rating_reliable);
    5.71  
    5.72      // mistrust Bob
    5.73 -    [session keyMistrusted:identBob];
    5.74 +    [session keyMistrusted:identBob.mutableDictionary];
    5.75      
    5.76      // Gray == PEP_rating_unencrypted
    5.77      clr = [session outgoingMessageColor:msg];
    5.78      XCTAssert( clr == PEP_rating_unencrypted);
    5.79      
    5.80      // Forget
    5.81 -    [session keyResetTrust:identBob];
    5.82 +    [session keyResetTrust:identBob.mutableDictionary];
    5.83      
    5.84      // Back to yellow
    5.85      clr = [session outgoingMessageColor:msg];
    5.86      XCTAssert( clr == PEP_rating_reliable);
    5.87  
    5.88      // Trust again
    5.89 -    [session trustPersonalKey:identBob];
    5.90 +    [session trustPersonalKey:identBob.mutableDictionary];
    5.91      
    5.92      // Back to green
    5.93      clr = [session outgoingMessageColor:msg];
    5.94 @@ -500,13 +496,11 @@
    5.95      // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575
    5.96      [self importBundledKey:@"0x70DCF575.asc"];
    5.97      
    5.98 -    NSMutableDictionary *identJohn = [NSMutableDictionary dictionaryWithObjectsAndKeys:
    5.99 -                                      @"pEp Test John", kPepUsername,
   5.100 -                                      @"pep.test.john@pep-project.org", kPepAddress,
   5.101 -                                      @"101", kPepUserID,
   5.102 -                                      @"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575",kPepFingerprint,
   5.103 -                                      nil];
   5.104 -    
   5.105 +    PEPIdentity *identJohn = [[PEPIdentity alloc]
   5.106 +                             initWithAddress:@"pep.test.john@pep-project.org"
   5.107 +                             userID:@"101" userName:@"pEp Test John"
   5.108 +                             fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
   5.109 +
   5.110      [session updateIdentity:identJohn];
   5.111  
   5.112      [msg setObject:[NSMutableArray arrayWithObjects:
   5.113 @@ -568,30 +562,28 @@
   5.114      // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
   5.115      [self importBundledKey:@"0xC9C2EE39.asc"];
   5.116      
   5.117 -    NSMutableDictionary *identBob = [NSMutableDictionary dictionaryWithObjectsAndKeys:
   5.118 -                                     @"pEp Test Bob", kPepUsername,
   5.119 -                                     @"pep.test.bob@pep-project.org", kPepAddress,
   5.120 -                                     @"42", kPepUserID,
   5.121 -                                     @"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",kPepFingerprint,
   5.122 -                                     nil];
   5.123 -    
   5.124 +    PEPIdentity *identBob = [[PEPIdentity alloc]
   5.125 +                             initWithAddress:@"pep.test.bob@pep-project.org"
   5.126 +                             userID:@"42" userName:@"pEp Test Bob"
   5.127 +                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
   5.128 +
   5.129      [session updateIdentity:identBob];
   5.130      
   5.131      // Should be yellow, since no handshake happened.
   5.132      clr = [session outgoingMessageColor:msg];
   5.133      XCTAssert( clr == PEP_rating_reliable);
   5.134      
   5.135 -    clr = [session identityRating:identBob];
   5.136 +    clr = [session identityRating:identBob.mutableDictionary];
   5.137      XCTAssert( clr == PEP_rating_reliable);
   5.138      
   5.139      // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
   5.140 -    [session trustPersonalKey:identBob];
   5.141 +    [session trustPersonalKey:identBob.mutableDictionary];
   5.142      
   5.143      // This time it should be green
   5.144      clr = [session outgoingMessageColor:msg];
   5.145      XCTAssert( clr == PEP_rating_trusted);
   5.146      
   5.147 -    clr = [session identityRating:identBob];
   5.148 +    clr = [session identityRating:identBob.mutableDictionary];
   5.149      XCTAssert( clr == PEP_rating_trusted);
   5.150  
   5.151      // Now let see if it turns back yellow if we add an unconfirmed folk.
   5.152 @@ -599,13 +591,11 @@
   5.153      // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575
   5.154      [self importBundledKey:@"0x70DCF575.asc"];
   5.155      
   5.156 -    NSMutableDictionary *identJohn = [NSMutableDictionary dictionaryWithObjectsAndKeys:
   5.157 -                                      @"pEp Test John", kPepUsername,
   5.158 -                                      @"pep.test.john@pep-project.org", kPepAddress,
   5.159 -                                      @"101", kPepUserID,
   5.160 -                                      @"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575",kPepFingerprint,
   5.161 -                                      nil];
   5.162 -    
   5.163 +    PEPIdentity *identJohn = [[PEPIdentity alloc]
   5.164 +                              initWithAddress:@"pep.test.john@pep-project.org"
   5.165 +                              userID:@"101" userName:@"pEp Test John"
   5.166 +                              fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
   5.167 +
   5.168      [session updateIdentity:identJohn];
   5.169      
   5.170      [msg setObject:[NSMutableArray arrayWithObjects:
   5.171 @@ -619,13 +609,13 @@
   5.172      clr = [session outgoingMessageColor:msg];
   5.173      XCTAssert( clr == PEP_rating_reliable);
   5.174      
   5.175 -    [session trustPersonalKey:identJohn];
   5.176 +    [session trustPersonalKey:identJohn.mutableDictionary];
   5.177      
   5.178      // This time it should be green
   5.179      clr = [session outgoingMessageColor:msg];
   5.180      XCTAssert( clr == PEP_rating_trusted);
   5.181      
   5.182 -    clr = [session identityRating:identJohn];
   5.183 +    clr = [session identityRating:identJohn.mutableDictionary];
   5.184      XCTAssert( clr == PEP_rating_trusted);
   5.185  
   5.186      /* 
   5.187 @@ -661,17 +651,15 @@
   5.188      // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
   5.189      [self importBundledKey:@"0xC9C2EE39.asc"];
   5.190      
   5.191 -    NSMutableDictionary *identBob = [NSMutableDictionary dictionaryWithObjectsAndKeys:
   5.192 -                                     @"pEp Test Bob", kPepUsername,
   5.193 -                                     @"pep.test.bob@pep-project.org", kPepAddress,
   5.194 -                                     @"42", kPepUserID,
   5.195 -                                     @"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",kPepFingerprint,
   5.196 -                                     nil];
   5.197 -    
   5.198 +    PEPIdentity *identBob = [[PEPIdentity alloc]
   5.199 +                             initWithAddress:@"pep.test.bob@pep-project.org"
   5.200 +                             userID:@"42" userName:@"pEp Test Bob"
   5.201 +                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
   5.202 +
   5.203      [session updateIdentity:identBob];
   5.204  
   5.205      // mistrust Bob
   5.206 -    [session keyMistrusted:identBob];
   5.207 +    [session keyMistrusted:identBob.mutableDictionary];
   5.208      
   5.209      NSMutableDictionary *msg = [NSMutableDictionary dictionaryWithObjectsAndKeys:
   5.210                                  identAlice, kPepFrom,
   5.211 @@ -710,16 +698,14 @@
   5.212      // pEp Test Hector (old test key don't use) <pep.test.hector@pep-project.org>
   5.213      [self importBundledKey:@"5CB2C182_sec.asc"];
   5.214      
   5.215 -    NSMutableDictionary *identHector = [NSMutableDictionary dictionaryWithObjectsAndKeys:
   5.216 -                                       @"pEp Test Hector", kPepUsername,
   5.217 -                                       @"pep.test.hector@pep-project.org", kPepAddress,
   5.218 -                                       @"fc2d33", kPepUserID,
   5.219 -                                       @"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182",kPepFingerprint,
   5.220 -                                       nil];
   5.221 -    
   5.222 +    PEPIdentity *identHector = [[PEPIdentity alloc]
   5.223 +                             initWithAddress:@"pep.test.hector@pep-project.org"
   5.224 +                             userID:@"fc2d33" userName:@"pEp Test Hector"
   5.225 +                             fingerPrint:@"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182"];
   5.226 +
   5.227      // Check that this key is indeed expired
   5.228      [session updateIdentity:identHector];
   5.229 -    XCTAssertEqual(PEP_ct_key_expired, [identHector[kPepCommType] integerValue]);
   5.230 +    XCTAssertEqual(PEP_ct_key_expired, identHector.commType);
   5.231  
   5.232      PEPIdentity *identHectorOwn = [[PEPIdentity alloc]
   5.233                                             initWithAddress:@"pep.test.hector@pep-project.org"
   5.234 @@ -735,15 +721,13 @@
   5.235      
   5.236      [self pEpSetUp:@"Bob"];
   5.237      
   5.238 -    NSMutableDictionary *_identHector = [NSMutableDictionary dictionaryWithObjectsAndKeys:
   5.239 -                                         @"pEp Test Hector", kPepUsername,
   5.240 -                                         @"pep.test.hector@pep-project.org", kPepAddress,
   5.241 -                                         @"khkhkh", kPepUserID,
   5.242 -                                         @"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182",kPepFingerprint,
   5.243 -                                         nil];
   5.244 -    
   5.245 +    PEPIdentity *_identHector = [[PEPIdentity alloc]
   5.246 +                                initWithAddress:@"pep.test.hector@pep-project.org"
   5.247 +                                userID:@"khkhkh" userName:@"pEp Test Hector"
   5.248 +                                fingerPrint:@"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182"];
   5.249 +
   5.250      [session updateIdentity:_identHector];
   5.251 -    XCTAssertEqual(PEP_ct_OpenPGP_unconfirmed, [_identHector[kPepCommType] integerValue]);
   5.252 +    XCTAssertEqual(PEP_ct_OpenPGP_unconfirmed, _identHector.commType);
   5.253      
   5.254      [self pEpCleanUp];
   5.255  }
   5.256 @@ -1063,7 +1047,7 @@
   5.257          XCTAssertEqual(secondclr, PEP_rating_reliable);
   5.258  
   5.259          // Check Miro is in DB
   5.260 -        [session updateIdentity:(NSMutableDictionary *) identMiroAtPetra];
   5.261 +        [session updateIdentity:identMiroAtPetra];
   5.262          
   5.263          XCTAssertNotNil(identMiroAtPetra.fingerPrint);
   5.264          
   5.265 @@ -1254,7 +1238,7 @@
   5.266          XCTAssertNotNil(partner1.fingerPrint);
   5.267          XCTAssertEqualObjects(partner1.fingerPrint, partner1Orig[kPepFingerprint]);
   5.268  
   5.269 -        NSMutableDictionary *me = meOrig.mutableCopy;
   5.270 +        PEPIdentity *me = [[PEPIdentity alloc] initWithDictionary:meOrig];
   5.271          [session updateIdentity:me];
   5.272  
   5.273          NSMutableDictionary *pepDecryptedMail;
   5.274 @@ -1507,13 +1491,14 @@
   5.275      XCTAssertNotNil(keys);
   5.276      XCTAssert(keys.count > 0);
   5.277  
   5.278 -    NSMutableDictionary *receiver = [decryptedDict[kPepTo][0] mutableCopy];
   5.279 +    PEPIdentity *receiver = [[PEPIdentity alloc]
   5.280 +                             initWithDictionary:decryptedDict[kPepTo][0]];
   5.281      [session updateIdentity:receiver];
   5.282      XCTAssertNotNil(receiver);
   5.283      PEP_STATUS trustwordsStatus;
   5.284  
   5.285      NSString *trustwords = [session getTrustwordsMessageDict:decryptedDict
   5.286 -                                                receiverDict:receiver
   5.287 +                                                receiverDict:receiver.mutableDictionary
   5.288                                                     keysArray:keys language:@"en"
   5.289                                                          full:YES
   5.290                                               resultingStatus: &trustwordsStatus];