IOSAD-72 keyResetTrust error handling
authorDirk Zimmermann <dirk@pep-project.org>
Fri, 16 Mar 2018 15:10:01 +0100
changeset 5457217e3c844e0
parent 536 2c9ad397d261
child 546 725069619f4b
IOSAD-72 keyResetTrust error handling
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 15 08:04:36 2018 +0100
     1.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Fri Mar 16 15:10:01 2018 +0100
     1.3 @@ -527,17 +527,25 @@
     1.4      return YES;
     1.5  }
     1.6  
     1.7 -- (void)keyResetTrust:(PEPIdentity *)identity
     1.8 +- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
     1.9 +                error:(NSError * _Nullable * _Nullable)error
    1.10  {
    1.11      pEp_identity *ident = PEP_identityToStruct(identity);
    1.12  
    1.13      [self lockWrite];
    1.14 -    key_reset_trust(_session, ident);
    1.15 +    PEP_STATUS status = key_reset_trust(_session, ident);
    1.16      [self unlockWrite];
    1.17  
    1.18 +    if ([NSError setError:error fromPEPStatus:status]) {
    1.19 +        free_identity(ident);
    1.20 +        return NO;
    1.21 +    }
    1.22 +
    1.23      [identity reset];
    1.24      [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
    1.25      free_identity(ident);
    1.26 +
    1.27 +    return YES;
    1.28  }
    1.29  
    1.30  - (void)importKey:(NSString *)keydata
     2.1 --- a/pEpObjCAdapter/PEPSession.m	Thu Mar 15 08:04:36 2018 +0100
     2.2 +++ b/pEpObjCAdapter/PEPSession.m	Fri Mar 16 15:10:01 2018 +0100
     2.3 @@ -182,10 +182,11 @@
     2.4      return [session keyMistrusted:identity error:error];
     2.5  }
     2.6  
     2.7 -- (void)keyResetTrust:(PEPIdentity * _Nonnull)identity
     2.8 +- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
     2.9 +                error:(NSError * _Nullable * _Nullable)error
    2.10  {
    2.11      PEPInternalSession *session = [PEPSessionProvider session];
    2.12 -    [session keyResetTrust:identity];
    2.13 +    return [session keyResetTrust:identity error:error];
    2.14  }
    2.15  
    2.16  #pragma mark Internal API (testing etc.)
     3.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 15 08:04:36 2018 +0100
     3.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Fri Mar 16 15:10:01 2018 +0100
     3.3 @@ -156,7 +156,8 @@
     3.4   Use this to undo keyCompromized or trustPersonalKey
     3.5   See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
     3.6   */
     3.7 -- (void)keyResetTrust:(PEPIdentity * _Nonnull)identity;
     3.8 +- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
     3.9 +                error:(NSError * _Nullable * _Nullable)error;
    3.10  
    3.11  #pragma mark -- Internal API (testing etc.)
    3.12  
     4.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Mar 15 08:04:36 2018 +0100
     4.2 +++ b/pEpObjCTests/PEPSessionTest.m	Fri Mar 16 15:10:01 2018 +0100
     4.3 @@ -243,7 +243,8 @@
     4.4      XCTAssertNil(error);
     4.5      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
     4.6  
     4.7 -    [session keyResetTrust:alice];
     4.8 +    XCTAssertTrue([session keyResetTrust:alice error:&error]);
     4.9 +    XCTAssertNil(error);
    4.10      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
    4.11  
    4.12      XCTAssertTrue([session keyMistrusted:alice error:&error]);
    4.13 @@ -259,7 +260,8 @@
    4.14      XCTAssertNil(error);
    4.15      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.16  
    4.17 -    [session keyResetTrust:alice];
    4.18 +    XCTAssertTrue([session keyResetTrust:alice error:&error]);
    4.19 +    XCTAssertNil(error);
    4.20      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_have_no_key);
    4.21  }
    4.22  
    4.23 @@ -293,7 +295,8 @@
    4.24      XCTAssertNil(error);
    4.25      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.26  
    4.27 -    [session keyResetTrust:alice];
    4.28 +    XCTAssertTrue([session keyResetTrust:alice error:&error]);
    4.29 +    XCTAssertNil(error);
    4.30      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
    4.31  
    4.32      XCTAssertTrue([session keyMistrusted:alice error:&error]);
    4.33 @@ -306,7 +309,8 @@
    4.34      XCTAssertNil(error);
    4.35      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.36  
    4.37 -    [session keyResetTrust:alice];
    4.38 +    XCTAssertTrue([session keyResetTrust:alice error:&error]);
    4.39 +    XCTAssertNil(error);
    4.40      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_have_no_key);
    4.41  
    4.42      // This line provoked the crash
    4.43 @@ -369,7 +373,8 @@
    4.44      XCTAssertNil(error);
    4.45      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.46  
    4.47 -    [session keyResetTrust:alice];
    4.48 +    XCTAssertTrue([session keyResetTrust:alice error:&error]);
    4.49 +    XCTAssertNil(error);
    4.50      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
    4.51  
    4.52      XCTAssertTrue([session keyMistrusted:alice error:&error]);
    4.53 @@ -385,7 +390,8 @@
    4.54      XCTAssertNil(error);
    4.55      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.56  
    4.57 -    [session keyResetTrust:alice];
    4.58 +    XCTAssertTrue([session keyResetTrust:alice error:&error]);
    4.59 +    XCTAssertNil(error);
    4.60      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_have_no_key);
    4.61  
    4.62      dispatch_group_wait(backgroundGroup, DISPATCH_TIME_FOREVER);
    4.63 @@ -469,7 +475,8 @@
    4.64      XCTAssertEqual(rating, PEP_rating_trusted);
    4.65  
    4.66      // Let' say we undo handshake
    4.67 -    [session keyResetTrust:identBob];
    4.68 +    XCTAssertTrue([session keyResetTrust:identBob error:&error]);
    4.69 +    XCTAssertNil(error);
    4.70  
    4.71      // Yellow ?
    4.72      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);