IOS-1675 Subsequent decryption shows if the secret key is usable. IOS-1675
authorDirk Zimmermann <dz@pep.security>
Fri, 09 Aug 2019 16:29:40 +0200
branchIOS-1675
changeset 11610cdb303d08f1
parent 1160 7e0a148f9c25
child 1162 fecbd977693a
IOS-1675 Subsequent decryption shows if the secret key is usable.
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Fri Aug 09 16:29:40 2019 +0200
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Fri Aug 09 16:29:40 2019 +0200
     1.3 @@ -1176,22 +1176,42 @@
     1.4  
     1.5      error = nil;
     1.6  
     1.7 -    PEPMessage *msg = [PEPMessage new];
     1.8 -    msg.from = ownIdentity;
     1.9 -    msg.to = @[ownIdentity];
    1.10 -    msg.shortMessage = @"Some message";
    1.11 -    msg.longMessage = @"Not really";
    1.12 -    msg.direction = PEPMsgDirectionOutgoing;
    1.13 +    PEPMessage *originalMsg = [PEPMessage new];
    1.14 +    originalMsg.from = ownIdentity;
    1.15 +    originalMsg.to = @[ownIdentity];
    1.16 +    originalMsg.shortMessage = @"Some message";
    1.17 +    originalMsg.longMessage = @"Not really";
    1.18 +    originalMsg.direction = PEPMsgDirectionOutgoing;
    1.19  
    1.20 -    PEPStatus status;
    1.21 +    PEPStatus encryptionStatus;
    1.22      PEPMessage *encryptedMsg = [session
    1.23 -                                encryptMessage:msg
    1.24 +                                encryptMessage:originalMsg
    1.25                                  forSelf:ownIdentity
    1.26                                  extraKeys:@[]
    1.27 -                                status:&status
    1.28 +                                status:&encryptionStatus
    1.29                                  error:&error];
    1.30      XCTAssertNotNil(encryptedMsg);
    1.31      XCTAssertNil(error);
    1.32 +    XCTAssertEqual(encryptionStatus, PEPStatusOK);
    1.33 +
    1.34 +    error = nil;
    1.35 +
    1.36 +    NSArray *extraKeys = @[];
    1.37 +    PEPRating decryptionRating;
    1.38 +    PEPStatus decryptionStatus;
    1.39 +    PEPMessage *decryptedMsg = [session
    1.40 +                                decryptMessage:encryptedMsg
    1.41 +                                flags:nil
    1.42 +                                rating:&decryptionRating
    1.43 +                                extraKeys:&extraKeys
    1.44 +                                status:&decryptionStatus
    1.45 +                                error:&error];
    1.46 +    XCTAssertNotNil(decryptedMsg);
    1.47 +    XCTAssertNil(error);
    1.48 +    XCTAssertEqual(decryptionStatus, PEPStatusOK);
    1.49 +
    1.50 +    XCTAssertEqualObjects(originalMsg.shortMessage, decryptedMsg.shortMessage);
    1.51 +    XCTAssertEqualObjects(originalMsg.longMessage, decryptedMsg.longMessage);
    1.52  }
    1.53  
    1.54  #pragma mark - configUnencryptedSubject