IOSAD-72 let decryptMessage return messages
authorDirk Zimmermann <dirk@pep-project.org>
Thu, 08 Mar 2018 15:05:41 +0100
changeset 517510fa8a4ff7f
parent 516 00b69bd275b0
child 518 bea5f452316d
IOSAD-72 let decryptMessage return messages
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 08 13:54:06 2018 +0100
     1.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 08 15:05:41 2018 +0100
     1.3 @@ -96,11 +96,10 @@
     1.4  
     1.5  #pragma mark - PEPSessionProtocol
     1.6  
     1.7 -- (BOOL)decryptMessageDict:(nonnull PEPDict *)src
     1.8 -                      dest:(PEPDict * _Nullable * _Nullable)dst
     1.9 -                    rating:(PEP_rating * _Nullable)rating
    1.10 -                      keys:(PEPStringList * _Nullable * _Nullable)keys
    1.11 -                     error:(NSError * _Nullable * _Nullable)error
    1.12 +- (PEPDict * _Nullable)decryptMessageDict:(nonnull PEPDict *)src
    1.13 +                                   rating:(PEP_rating * _Nullable)rating
    1.14 +                                     keys:(PEPStringList * _Nullable * _Nullable)keys
    1.15 +                                    error:(NSError * _Nullable * _Nullable)error
    1.16  {
    1.17      if (rating) {
    1.18          *rating = PEP_rating_undefined;
    1.19 @@ -118,7 +117,7 @@
    1.20      [self unlockWrite];
    1.21  
    1.22      if ([NSError setError:error fromPEPStatus:status]) {
    1.23 -        return NO;
    1.24 +        return nil;
    1.25      }
    1.26  
    1.27      NSDictionary *dst_;
    1.28 @@ -137,10 +136,6 @@
    1.29      free_message(_dst);
    1.30      free_stringlist(_keys);
    1.31  
    1.32 -    if (dst) {
    1.33 -        *dst = dst_;
    1.34 -    }
    1.35 -
    1.36      if (keys) {
    1.37          *keys = keys_;
    1.38      }
    1.39 @@ -149,32 +144,26 @@
    1.40          *rating = internalRating;
    1.41      }
    1.42  
    1.43 -    return YES;
    1.44 +    return dst_;
    1.45  }
    1.46  
    1.47 -- (BOOL)decryptMessage:(nonnull PEPMessage *)src
    1.48 -                  dest:(PEPMessage * _Nullable * _Nullable)dst
    1.49 -                rating:(PEP_rating * _Nullable)rating
    1.50 -                  keys:(PEPStringList * _Nullable * _Nullable)keys
    1.51 -                 error:(NSError * _Nullable * _Nullable)error
    1.52 +- (PEPMessage * _Nullable)decryptMessage:(nonnull PEPMessage *)src
    1.53 +                                  rating:(PEP_rating * _Nullable)rating
    1.54 +                                    keys:(PEPStringList * _Nullable * _Nullable)keys
    1.55 +                                   error:(NSError * _Nullable * _Nullable)error
    1.56  {
    1.57 -    PEPDict *destDict;
    1.58 +    PEPDict *destDict = [self decryptMessageDict:(PEPDict *)src
    1.59 +                                          rating:rating
    1.60 +                                            keys:keys
    1.61 +                                           error:error];
    1.62  
    1.63 -    if (![self decryptMessageDict:(PEPDict *)src
    1.64 -                             dest:&destDict
    1.65 -                           rating:rating
    1.66 -                             keys:keys
    1.67 -                            error:error]) {
    1.68 -        return NO;
    1.69 -    }
    1.70 -
    1.71 -    if (dst) {
    1.72 +    if (!destDict) {
    1.73 +        return nil;
    1.74 +    } else {
    1.75          PEPMessage *msg = [PEPMessage new];
    1.76          [msg setValuesForKeysWithDictionary:destDict];
    1.77 -        *dst = msg;
    1.78 +        return msg;
    1.79      }
    1.80 -
    1.81 -    return YES;
    1.82  }
    1.83  
    1.84  - (BOOL)reEvaluateMessageDict:(nonnull PEPDict *)messageDict
     2.1 --- a/pEpObjCAdapter/PEPSession.m	Thu Mar 08 13:54:06 2018 +0100
     2.2 +++ b/pEpObjCAdapter/PEPSession.m	Thu Mar 08 15:05:41 2018 +0100
     2.3 @@ -21,22 +21,20 @@
     2.4      [PEPSessionProvider cleanup];
     2.5  }
     2.6  
     2.7 -- (BOOL)decryptMessageDict:(nonnull PEPDict *)src
     2.8 -                      dest:(PEPDict * _Nullable * _Nullable)dst
     2.9 -                    rating:(PEP_rating * _Nullable)rating
    2.10 -                      keys:(PEPStringList * _Nullable * _Nullable)keys
    2.11 -                     error:(NSError * _Nullable * _Nullable)error
    2.12 +- (PEPDict * _Nullable)decryptMessageDict:(nonnull PEPDict *)src
    2.13 +                                   rating:(PEP_rating * _Nullable)rating
    2.14 +                                     keys:(PEPStringList * _Nullable * _Nullable)keys
    2.15 +                                    error:(NSError * _Nullable * _Nullable)error
    2.16  {
    2.17 -    return [PEPSession decryptMessageDict:src dest:dst rating:rating keys:keys error:error];
    2.18 +    return [PEPSession decryptMessageDict:src rating:rating keys:keys error:error];
    2.19  }
    2.20  
    2.21 -- (BOOL)decryptMessage:(nonnull PEPMessage *)src
    2.22 -                  dest:(PEPMessage * _Nullable * _Nullable)dst
    2.23 -                rating:(PEP_rating * _Nullable)rating
    2.24 -                  keys:(PEPStringList * _Nullable * _Nullable)keys
    2.25 -                 error:(NSError * _Nullable * _Nullable)error
    2.26 +- (PEPMessage * _Nullable)decryptMessage:(nonnull PEPMessage *)src
    2.27 +                                  rating:(PEP_rating * _Nullable)rating
    2.28 +                                    keys:(PEPStringList * _Nullable * _Nullable)keys
    2.29 +                                   error:(NSError * _Nullable * _Nullable)error
    2.30  {
    2.31 -    return [PEPSession decryptMessage:src dest:dst rating:rating keys:keys error:error];
    2.32 +    return [PEPSession decryptMessage:src rating:rating keys:keys error:error];
    2.33  }
    2.34  
    2.35  - (BOOL)reEvaluateMessageDict:(nonnull PEPDict *)messageDict
    2.36 @@ -197,24 +195,22 @@
    2.37  
    2.38  #pragma mark - Static
    2.39  
    2.40 -+ (BOOL)decryptMessageDict:(nonnull PEPDict *)src
    2.41 -                      dest:(PEPDict * _Nullable * _Nullable)dst
    2.42 -                    rating:(PEP_rating * _Nullable)rating
    2.43 -                      keys:(PEPStringList * _Nullable * _Nullable)keys
    2.44 -                     error:(NSError * _Nullable * _Nullable)error __deprecated
    2.45 ++ (PEPDict * _Nullable)decryptMessageDict:(nonnull PEPDict *)src
    2.46 +                                   rating:(PEP_rating * _Nullable)rating
    2.47 +                                     keys:(PEPStringList * _Nullable * _Nullable)keys
    2.48 +                                    error:(NSError * _Nullable * _Nullable)error __deprecated
    2.49  {
    2.50      PEPInternalSession *session = [PEPSessionProvider session];
    2.51 -    return [session decryptMessageDict:src dest:dst rating:rating keys:keys error:error];
    2.52 +    return [session decryptMessageDict:src rating:rating keys:keys error:error];
    2.53  }
    2.54  
    2.55 -+ (BOOL)decryptMessage:(nonnull PEPMessage *)src
    2.56 -                  dest:(PEPMessage * _Nullable * _Nullable)dst
    2.57 -                rating:(PEP_rating * _Nullable)rating
    2.58 -                  keys:(PEPStringList * _Nullable * _Nullable)keys
    2.59 -                 error:(NSError * _Nullable * _Nullable)error
    2.60 ++ (PEPMessage * _Nullable)decryptMessage:(nonnull PEPMessage *)src
    2.61 +                                  rating:(PEP_rating * _Nullable)rating
    2.62 +                                    keys:(PEPStringList * _Nullable * _Nullable)keys
    2.63 +                                   error:(NSError * _Nullable * _Nullable)error
    2.64  {
    2.65      PEPInternalSession *session = [PEPSessionProvider session];
    2.66 -    return [session decryptMessage:src dest:dst rating:rating keys:keys error:error];
    2.67 +    return [session decryptMessage:src rating:rating keys:keys error:error];
    2.68  }
    2.69  
    2.70  + (BOOL)reEvaluateMessageDict:(nonnull PEPDict *)messageDict
     3.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 08 13:54:06 2018 +0100
     3.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 08 15:05:41 2018 +0100
     3.3 @@ -21,18 +21,16 @@
     3.4  @protocol PEPSessionProtocol <NSObject>
     3.5  
     3.6  /** Decrypt a message */
     3.7 -- (BOOL)decryptMessageDict:(nonnull PEPDict *)src
     3.8 -                      dest:(PEPDict * _Nullable * _Nullable)dst
     3.9 -                    rating:(PEP_rating * _Nullable)rating
    3.10 -                      keys:(PEPStringList * _Nullable * _Nullable)keys
    3.11 -                     error:(NSError * _Nullable * _Nullable)error __deprecated;
    3.12 +- (PEPDict * _Nullable)decryptMessageDict:(nonnull PEPDict *)src
    3.13 +                                   rating:(PEP_rating * _Nullable)rating
    3.14 +                                     keys:(PEPStringList * _Nullable * _Nullable)keys
    3.15 +                                    error:(NSError * _Nullable * _Nullable)error __deprecated;
    3.16  
    3.17  /** Decrypt a message */
    3.18 -- (BOOL)decryptMessage:(nonnull PEPMessage *)src
    3.19 -                  dest:(PEPMessage * _Nullable * _Nullable)dst
    3.20 -                rating:(PEP_rating * _Nullable)rating
    3.21 -                  keys:(PEPStringList * _Nullable * _Nullable)keys
    3.22 -                 error:(NSError * _Nullable * _Nullable)error;
    3.23 +- (PEPMessage * _Nullable)decryptMessage:(nonnull PEPMessage *)src
    3.24 +                                  rating:(PEP_rating * _Nullable)rating
    3.25 +                                    keys:(PEPStringList * _Nullable * _Nullable)keys
    3.26 +                                   error:(NSError * _Nullable * _Nullable)error;
    3.27  
    3.28  /** Re-evaluate rating of decrypted message */
    3.29  - (BOOL)reEvaluateMessageDict:(nonnull PEPDict *)messageDict
     4.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Mar 08 13:54:06 2018 +0100
     4.2 +++ b/pEpObjCTests/PEPSessionTest.m	Thu Mar 08 15:05:41 2018 +0100
     4.3 @@ -684,10 +684,14 @@
     4.4      XCTAssertEqual(status, PEP_STATUS_OK);
     4.5  
     4.6      NSArray* keys;
     4.7 -    PEPMessage *decmsg;
     4.8  
     4.9      NSError *error;
    4.10 -    XCTAssertTrue([session decryptMessage:encmsg dest:&decmsg rating:&clr keys:&keys error:&error]);
    4.11 +    PEPMessage *decmsg = [session
    4.12 +                          decryptMessage:encmsg
    4.13 +                          rating:&clr
    4.14 +                          keys:&keys
    4.15 +                          error:&error];
    4.16 +    XCTAssertNotNil(decmsg);
    4.17      XCTAssertNil(error);
    4.18      XCTAssertEqual(clr, PEP_rating_trusted_and_anonymized);
    4.19  }
    4.20 @@ -723,12 +727,15 @@
    4.21      NSArray* keys;
    4.22      PEPMessage *msg = [PEPMessage new];
    4.23      [msg setValuesForKeysWithDictionary:msgDict];
    4.24 -    PEPMessage *pepDecryptedMail;
    4.25  
    4.26      // Technically, the mail is encrypted, but the signatures don't match
    4.27      NSError *error;
    4.28 -    XCTAssertTrue([session decryptMessage:msg dest:&pepDecryptedMail rating:nil keys:&keys
    4.29 -                                    error:&error]);
    4.30 +    PEPMessage *pepDecryptedMail = [session
    4.31 +                                    decryptMessage:msg
    4.32 +                                    rating:nil
    4.33 +                                    keys:&keys
    4.34 +                                    error:&error];
    4.35 +    XCTAssertNotNil(pepDecryptedMail);
    4.36      XCTAssertNil(error);
    4.37  
    4.38      XCTAssertNotNil(pepDecryptedMail.longMessage);
    4.39 @@ -889,13 +896,15 @@
    4.40  
    4.41      XCTAssertNotNil(encMsg);
    4.42  
    4.43 -    PEPMessage *decMsg;
    4.44      PEPStringList *keys;
    4.45 -
    4.46      PEP_rating pEpRating;
    4.47      NSError *error;
    4.48 -    XCTAssertTrue([session decryptMessage:encMsg dest:&decMsg rating:&pEpRating keys:&keys
    4.49 -                                    error:&error]);
    4.50 +    PEPMessage *decMsg = [session
    4.51 +                          decryptMessage:encMsg
    4.52 +                          rating:&pEpRating
    4.53 +                          keys:&keys
    4.54 +                          error:&error];
    4.55 +    XCTAssertNotNil(decMsg);
    4.56      XCTAssertNil(error);
    4.57  
    4.58      XCTAssertEqual(pEpRating, PEP_rating_unencrypted);
    4.59 @@ -1112,12 +1121,14 @@
    4.60      XCTAssertEqual(status, 0);
    4.61      XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p");
    4.62  
    4.63 -    PEPMessage *unencDict;
    4.64 -
    4.65      PEP_rating rating;
    4.66      NSError *error;
    4.67 -    XCTAssertTrue([session decryptMessage:encMessage dest:&unencDict rating:&rating keys:keys
    4.68 -                                    error:&error]);
    4.69 +    PEPMessage *unencDict = [session
    4.70 +                             decryptMessage:encMessage
    4.71 +                             rating:&rating
    4.72 +                             keys:keys
    4.73 +                             error:&error];
    4.74 +    XCTAssertNotNil(unencDict);
    4.75      XCTAssertNil(error);
    4.76  
    4.77      XCTAssertGreaterThanOrEqual(rating, PEP_rating_reliable);
    4.78 @@ -1182,16 +1193,18 @@
    4.79  
    4.80      XCTAssertNotNil(encMsg);
    4.81  
    4.82 -    PEPMessage *decMsg;
    4.83      PEPStringList *keys;
    4.84      PEP_rating pEpRating;
    4.85      NSError *error;
    4.86 -    XCTAssertTrue([session decryptMessage:encMsg dest:&decMsg rating:&pEpRating keys:&keys
    4.87 -                                    error:&error]);
    4.88 +    PEPMessage *decMsg = [session
    4.89 +                          decryptMessage:encMsg
    4.90 +                          rating:&pEpRating
    4.91 +                          keys:&keys
    4.92 +                          error:&error];
    4.93      XCTAssertNil(error);
    4.94 +    XCTAssertNotNil(decMsg);
    4.95  
    4.96      XCTAssertEqual(pEpRating, expectedRating);
    4.97 -    XCTAssertNotNil(decMsg);
    4.98  
    4.99      NSArray * encStatusField = nil;
   4.100      for (NSArray *field in decMsg.optionalFields) {