IOSAD-72 importKey error handling
authorDirk Zimmermann <dirk@pep-project.org>
Thu, 22 Mar 2018 15:38:12 +0100
changeset 5516b7914602bc6
parent 550 c6ac36a539f3
child 552 0f362cd2de6a
IOSAD-72 importKey error handling
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
pEpObjCTests/PEPSessionTest.m
pEpObjCTests/TestUtils/PEPTestUtils.m
     1.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 22 11:05:12 2018 +0100
     1.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 22 15:38:12 2018 +0100
     1.3 @@ -548,12 +548,17 @@
     1.4      return YES;
     1.5  }
     1.6  
     1.7 -- (void)importKey:(NSString *)keydata
     1.8 +- (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error
     1.9  {
    1.10      [self lockWrite];
    1.11 -    import_key(_session, [keydata UTF8String], [keydata length], NULL);
    1.12 +    PEP_STATUS status = import_key(_session, [keydata UTF8String], [keydata length], NULL);
    1.13      [self unlockWrite];
    1.14  
    1.15 +    if ([NSError setError:error fromPEPStatus:status]) {
    1.16 +        return NO;
    1.17 +    }
    1.18 +
    1.19 +    return YES;
    1.20  }
    1.21  
    1.22  - (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
     2.1 --- a/pEpObjCAdapter/PEPSession.m	Thu Mar 22 11:05:12 2018 +0100
     2.2 +++ b/pEpObjCAdapter/PEPSession.m	Thu Mar 22 15:38:12 2018 +0100
     2.3 @@ -191,9 +191,10 @@
     2.4  
     2.5  #pragma mark Internal API (testing etc.)
     2.6  
     2.7 -- (void)importKey:(NSString * _Nonnull)keydata
     2.8 +- (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error
     2.9  {
    2.10 -    [PEPSession importKey:keydata];
    2.11 +    PEPInternalSession *session = [PEPSessionProvider session];
    2.12 +    return [session importKey:keydata error:error];
    2.13  }
    2.14  
    2.15  - (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
    2.16 @@ -251,12 +252,6 @@
    2.17  
    2.18  #pragma mark Internal API (testing etc.)
    2.19  
    2.20 -+ (void)importKey:(NSString * _Nonnull)keydata
    2.21 -{
    2.22 -    PEPInternalSession *session = [PEPSessionProvider session];
    2.23 -    [session importKey:keydata];
    2.24 -}
    2.25 -
    2.26  + (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
    2.27       description:(NSString * _Nullable)description comment:(NSString * _Nullable)comment
    2.28  {
     3.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 22 11:05:12 2018 +0100
     3.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 22 15:38:12 2018 +0100
     3.3 @@ -162,7 +162,7 @@
     3.4  #pragma mark -- Internal API (testing etc.)
     3.5  
     3.6  /** For testing purpose, manual key import */
     3.7 -- (void)importKey:(NSString * _Nonnull)keydata;
     3.8 +- (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error;
     3.9  
    3.10  - (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
    3.11       description:(NSString * _Nullable)description comment:(NSString * _Nullable)comment;
     4.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Mar 22 11:05:12 2018 +0100
     4.2 +++ b/pEpObjCTests/PEPSessionTest.m	Thu Mar 22 15:38:12 2018 +0100
     4.3 @@ -878,7 +878,10 @@
     4.4                                                                     userName:@"Partner 1"];
     4.5      NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"];
     4.6      XCTAssertNotNil(pubKeyPartner1);
     4.7 -    [session importKey:pubKeyPartner1];
     4.8 +
     4.9 +    NSError *error = nil;
    4.10 +    XCTAssertTrue([session importKey:pubKeyPartner1 error:&error]);
    4.11 +    XCTAssertNil(error);
    4.12  
    4.13      PEP_rating color = [self ratingForIdentity:partner1Orig session:session];
    4.14      XCTAssertEqual(color, PEP_rating_reliable);
     5.1 --- a/pEpObjCTests/TestUtils/PEPTestUtils.m	Thu Mar 22 11:05:12 2018 +0100
     5.2 +++ b/pEpObjCTests/TestUtils/PEPTestUtils.m	Thu Mar 22 15:38:12 2018 +0100
     5.3 @@ -76,8 +76,7 @@
     5.4      if (!txtFileContents) {
     5.5          return NO;
     5.6      } else {
     5.7 -        [session importKey:txtFileContents];
     5.8 -        return YES;
     5.9 +        return [session importKey:txtFileContents error:nil];
    5.10      }
    5.11  }
    5.12