IOSAD-72 isPEPUser error handling
authorDirk Zimmermann <dirk@pep-project.org>
Thu, 12 Apr 2018 10:05:06 +0200
changeset 567b9439926c09f
parent 566 1242b57ef5e6
child 568 d3c705c9c077
IOSAD-72 isPEPUser error handling
pEpObjCAdapter/PEPIdentity.h
pEpObjCAdapter/PEPIdentity.m
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCAdapter/PEPIdentity.h	Thu Apr 12 07:15:42 2018 +0200
     1.2 +++ b/pEpObjCAdapter/PEPIdentity.h	Thu Apr 12 10:05:06 2018 +0200
     1.3 @@ -97,7 +97,8 @@
     1.4  /**
     1.5   Is the given identity a pEp user, from the engine's point of view?
     1.6   */
     1.7 -- (BOOL)isPEPUser:(PEPSession * _Nullable)session;
     1.8 +- (NSNumber * _Nullable)isPEPUser:(PEPSession * _Nullable)session
     1.9 +                            error:(NSError * _Nullable * _Nullable)error;
    1.10  
    1.11  /**
    1.12   Puts all properties into a default/nil state.
     2.1 --- a/pEpObjCAdapter/PEPIdentity.m	Thu Apr 12 07:15:42 2018 +0200
     2.2 +++ b/pEpObjCAdapter/PEPIdentity.m	Thu Apr 12 10:05:06 2018 +0200
     2.3 @@ -92,12 +92,13 @@
     2.4      return (PEPMutableDict *) self;
     2.5  }
     2.6  
     2.7 -- (BOOL)isPEPUser:(PEPSession * _Nullable)session
     2.8 +- (NSNumber * _Nullable)isPEPUser:(PEPSession * _Nullable)session
     2.9 +                            error:(NSError * _Nullable * _Nullable)error
    2.10  {
    2.11      if (!session) {
    2.12          session = [PEPSession new];
    2.13      }
    2.14 -    return [session isPEPUser:self];
    2.15 +    return [session isPEPUser:self error:error];
    2.16  }
    2.17  
    2.18  - (BOOL)isConfirmed
     3.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Thu Apr 12 07:15:42 2018 +0200
     3.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Thu Apr 12 10:05:06 2018 +0200
     3.3 @@ -745,15 +745,17 @@
     3.4      }
     3.5  }
     3.6  
     3.7 -- (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
     3.8 +- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
     3.9 +                            error:(NSError * _Nullable * _Nullable)error
    3.10  {
    3.11      pEp_identity *ident = PEP_identityToStruct(identity);
    3.12      bool isPEP;
    3.13      PEP_STATUS status = is_pep_user(self.session, ident, &isPEP);
    3.14 -    if (status == PEP_STATUS_OK) {
    3.15 -        return isPEP;
    3.16 +
    3.17 +    if ([NSError setError:error fromPEPStatus:status]) {
    3.18 +        return nil;
    3.19      } else {
    3.20 -        return NO;
    3.21 +        return [NSNumber numberWithBool:isPEP];
    3.22      }
    3.23  }
    3.24  
     4.1 --- a/pEpObjCAdapter/PEPSession.m	Thu Apr 12 07:15:42 2018 +0200
     4.2 +++ b/pEpObjCAdapter/PEPSession.m	Thu Apr 12 10:05:06 2018 +0200
     4.3 @@ -268,9 +268,11 @@
     4.4      return [session stringFromRating:rating];
     4.5  }
     4.6  
     4.7 -- (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
     4.8 +- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
     4.9 +                            error:(NSError * _Nullable * _Nullable)error
    4.10  {
    4.11 -    return [PEPSession isPEPUser:identity];
    4.12 +    PEPInternalSession *session = [PEPSessionProvider session];
    4.13 +    return [session isPEPUser:identity error:error];
    4.14  }
    4.15  
    4.16  - (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
    4.17 @@ -281,12 +283,6 @@
    4.18  
    4.19  #pragma mark Internal API (testing etc.)
    4.20  
    4.21 -+ (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
    4.22 -{
    4.23 -    PEPInternalSession *session = [PEPSessionProvider session];
    4.24 -    return [session isPEPUser:identity];
    4.25 -}
    4.26 -
    4.27  + (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
    4.28              error:(NSError * _Nullable * _Nullable)error
    4.29  {
     5.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Thu Apr 12 07:15:42 2018 +0200
     5.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Thu Apr 12 10:05:06 2018 +0200
     5.3 @@ -209,7 +209,8 @@
     5.4   Is the given identity really a pEp user?
     5.5   If the engine indicates an error, or the identity is not a pEp user, returns false.
     5.6   */
     5.7 -- (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
     5.8 +- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
     5.9 +                            error:(NSError * _Nullable * _Nullable)error;
    5.10  
    5.11  /**
    5.12   When (manually) importing (secret) keys, associate them with the given own identity.
     6.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Apr 12 07:15:42 2018 +0200
     6.2 +++ b/pEpObjCTests/PEPSessionTest.m	Thu Apr 12 10:05:06 2018 +0200
     6.3 @@ -102,7 +102,7 @@
     6.4      XCTAssertNotNil(identMe.fingerPrint);
     6.5      XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
     6.6  
     6.7 -    XCTAssertTrue([identMe isPEPUser:session]);
     6.8 +    XCTAssertTrue([identMe isPEPUser:session error:&error]);
     6.9  }
    6.10  
    6.11  - (void)testMySelfCommType
    6.12 @@ -122,7 +122,7 @@
    6.13      XCTAssertNotNil(identMe.fingerPrint);
    6.14      XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
    6.15  
    6.16 -    XCTAssertTrue([identMe isPEPUser:session]);
    6.17 +    XCTAssertTrue([identMe isPEPUser:session error:&error]);
    6.18  
    6.19      dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0);
    6.20      dispatch_sync(queue, ^{
    6.21 @@ -141,7 +141,7 @@
    6.22          XCTAssertNil(innerError);
    6.23  
    6.24          XCTAssertNotNil(identMe2.fingerPrint);
    6.25 -        XCTAssertTrue([identMe2 isPEPUser:session]);
    6.26 +        XCTAssertTrue([identMe2 isPEPUser:session error:&innerError]);
    6.27          XCTAssertEqualObjects(identMe2.fingerPrint, identMe.fingerPrint);
    6.28  
    6.29          // Now pretend the app only knows kPepUsername and kPepAddress
    6.30 @@ -151,7 +151,7 @@
    6.31          XCTAssertNil(innerError);
    6.32  
    6.33          XCTAssertNotNil(identMe3.fingerPrint);
    6.34 -        XCTAssertTrue([identMe3 isPEPUser:session]);
    6.35 +        XCTAssertTrue([identMe3 isPEPUser:session error:&innerError]);
    6.36          XCTAssertEqualObjects(identMe3.fingerPrint, identMe.fingerPrint);
    6.37  
    6.38          XCTAssertEqualObjects(identMe.address, identMe2.address);
    6.39 @@ -990,7 +990,7 @@
    6.40      XCTAssertNotNil(identMe.fingerPrint);
    6.41  
    6.42      // PEP_CANNOT_FIND_PERSON == 902
    6.43 -    XCTAssertTrue([session isPEPUser:identMe]);
    6.44 +    XCTAssertTrue([session isPEPUser:identMe error:&error]);
    6.45  }
    6.46  
    6.47  - (void)testXEncStatusForOutgoingEncryptedMail