Browse Source

IOS-1673 Remove PEPAsync* files

IOS-1673
Dirk Zimmermann 2 years ago
parent
commit
9d8f9e6b21
3 changed files with 0 additions and 1740 deletions
  1. +0
    -179
      PEPObjCAdapterFramework/PEPAsyncSession.h
  2. +0
    -590
      pEpObjCAdapter/PEPAsyncSession.m
  3. +0
    -971
      pEpObjCTests/PEPAsyncSessionTest.m

+ 0
- 179
PEPObjCAdapterFramework/PEPAsyncSession.h View File

@ -1,179 +0,0 @@
//
// PEPAsyncSession.h
// PEPObjCAdapterFramework
//
// Created by Dirk Zimmermann on 17.07.20.
// Copyright © 2020 pp. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PEPEngineTypes.h"
#import "PEPTypes.h"
@class PEPMessage;
@class PEPIdentity;
@class PEPLanguage;
NS_ASSUME_NONNULL_BEGIN
@interface PEPAsyncSession : NSObject
- (void)decryptMessage:(PEPMessage *)message
flags:(PEPDecryptFlags)flags
extraKeys:(PEPStringList * _Nullable)extraKeys
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *dstMessage,
PEPStringList *keyList,
PEPRating rating,
PEPDecryptFlags flags,
BOOL isFormerlyEncryptedReuploadedMessage))successCallback;
- (void)reEvaluateMessage:(PEPMessage *)message
xKeyList:(PEPStringList *_Nullable)xKeyList
originalRating:(PEPRating)originalRating
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPRating rating))successCallback;
/// Encrypt a message with explicit encryption format.
- (void)encryptMessage:(PEPMessage *)message
extraKeys:(PEPStringList * _Nullable)extraKeys
encFormat:(PEPEncFormat)encFormat
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *destMessage))successCallback;
/// Encrypt a message with the default encryption format.
- (void)encryptMessage:(PEPMessage *)message
extraKeys:(PEPStringList * _Nullable)extraKeys
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *destMessage))successCallback;
/// Encrypt a message to an own identity.
- (void)encryptMessage:(PEPMessage *)message
forSelf:(PEPIdentity *)ownIdentity
extraKeys:(PEPStringList * _Nullable)extraKeys
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *destMessage))successCallback;
/// Encrypt a message to a fingerprint.
- (void)encryptMessage:(PEPMessage *)message
toFpr:(NSString *)toFpr
encFormat:(PEPEncFormat)encFormat
flags:(PEPDecryptFlags)flags
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *destMessage))successCallback;
- (void)outgoingRatingForMessage:(PEPMessage *)theMessage
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPRating rating))successCallback;
- (void)ratingForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPRating rating))successCallback;
- (void)trustwordsForFingerprint:(NSString *)fingerprint
languageID:(NSString *)languageID
shortened:(BOOL)shortened
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSArray<NSString *> *trustwords))successCallback;
- (void)mySelf:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPIdentity *identity))successCallback;
- (void)updateIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPIdentity *identity))successCallback;
- (void)trustPersonalKey:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)keyMistrusted:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)keyResetTrust:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)enableSyncForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)disableSyncForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)queryKeySyncEnabledForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(BOOL enabled))successCallback;
- (void)importKey:(NSString *)keydata
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSArray<PEPIdentity *> *identities))successCallback;
- (void)logTitle:(NSString *)title
entity:(NSString *)entity
description:(NSString * _Nullable)description
comment:(NSString * _Nullable)comment
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)getLog:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSString *log))successCallback;
- (void)getTrustwordsIdentity1:(PEPIdentity *)identity1
identity2:(PEPIdentity *)identity2
language:(NSString * _Nullable)language
full:(BOOL)full
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSString *trustwords))successCallback;
- (void)getTrustwordsFpr1:(NSString *)fpr1
fpr2:(NSString *)fpr2
language:(NSString * _Nullable)language
full:(BOOL)full
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSString *trustwords))successCallback;
- (void)languageList:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSArray<PEPLanguage *> *languages))successCallback;
- (void)isPEPUser:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(BOOL enabled))successCallback;
- (void)setOwnKey:(PEPIdentity *)identity
fingerprint:(NSString *)fingerprint
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)deliverHandshakeResult:(PEPSyncHandshakeResult)result
identitiesSharing:(NSArray<PEPIdentity *> * _Nullable)identitiesSharing
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)trustOwnKeyIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)keyReset:(PEPIdentity *)identity
fingerprint:(NSString * _Nullable)fingerprint
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)leaveDeviceGroup:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)keyResetAllOwnKeys:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
@end
NS_ASSUME_NONNULL_END

+ 0
- 590
pEpObjCAdapter/PEPAsyncSession.m View File

@ -1,590 +0,0 @@
//
// PEPAsyncSession.m
// PEPObjCAdapterFramework
//
// Created by Dirk Zimmermann on 17.07.20.
// Copyright © 2020 pp. All rights reserved.
//
#import "PEPAsyncSession.h"
#import "PEPMessage.h"
#import "PEPEngineTypes.h"
#import "PEPSession.h"
#import "NSNumber+PEPRating.h"
#import "PEPIdentity.h"
static dispatch_queue_t queue;
@interface PEPAsyncSession ()
@end
@implementation PEPAsyncSession
+ (void)initialize
{
if (self == [PEPAsyncSession class]) {
queue = dispatch_queue_create("PEPAsyncSession.queue", DISPATCH_QUEUE_SERIAL); //DIRK: TODO: please set QOS to userInitiated
}
}
- (void)decryptMessage:(PEPMessage *)message //BUFF: done
flags:(PEPDecryptFlags)flags
extraKeys:(PEPStringList * _Nullable)extraKeys
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *dstMessage,
PEPStringList *keyList,
PEPRating rating,
PEPDecryptFlags flags,
BOOL isFormerlyEncryptedReuploadedMessage))successCallback
{
dispatch_async(queue, ^{
PEPMessage *theMessage = [[PEPMessage alloc] initWithMessage:message];
PEPDecryptFlags theFlags = flags;
PEPRating theRating;
PEPStringList *theExtraKeys = extraKeys;
PEPStatus status;
NSError *error = nil;
PEPMessage *newMessage = [[PEPSession new] decryptMessage:theMessage
flags:&theFlags
rating:&theRating
extraKeys:&theExtraKeys
status:&status
error:&error];
if (newMessage) {
// See IOS-2414 for details
BOOL isFormerlyEncryptedReuploadedMessage = (status == PEPStatusUnencrypted) && theRating >= PEPRatingUnreliable;
successCallback(theMessage, newMessage, theExtraKeys, theRating, theFlags, isFormerlyEncryptedReuploadedMessage);
} else {
errorCallback(error);
}
});
}
- (void)reEvaluateMessage:(PEPMessage *)message
xKeyList:(PEPStringList *_Nullable)xKeyList
originalRating:(PEPRating)originalRating
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPRating rating))successCallback
{
dispatch_async(queue, ^{
PEPRating theRating = originalRating;
NSError *error = nil;
BOOL result = [[PEPSession new]
reEvaluateMessage:message
xKeyList:xKeyList
rating:&theRating
status:nil
error:&error];
if (result) {
successCallback(theRating);
} else {
errorCallback(error);
}
});
}
- (void)encryptMessage:(PEPMessage *)message
extraKeys:(PEPStringList * _Nullable)extraKeys
encFormat:(PEPEncFormat)encFormat
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *destMessage))successCallback
{
dispatch_async(queue, ^{
PEPMessage *theMessage = [[PEPMessage alloc] initWithMessage:message];
NSError *error = nil;
PEPMessage *destMessage = [[PEPSession new]
encryptMessage:theMessage
extraKeys:extraKeys
encFormat:encFormat
status:nil
error:&error];
if (destMessage) {
successCallback(theMessage, destMessage);
} else {
errorCallback(error);
}
});
}
- (void)encryptMessage:(PEPMessage *)message
extraKeys:(PEPStringList * _Nullable)extraKeys
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *destMessage))successCallback
{
dispatch_async(queue, ^{
PEPMessage *theMessage = [[PEPMessage alloc] initWithMessage:message];
NSError *error = nil;
PEPMessage *destMessage = [[PEPSession new]
encryptMessage:theMessage
extraKeys:extraKeys
status:nil
error:&error];
if (destMessage) {
successCallback(theMessage, destMessage);
} else {
errorCallback(error);
}
});
}
- (void)encryptMessage:(PEPMessage *)message
forSelf:(PEPIdentity *)ownIdentity
extraKeys:(PEPStringList * _Nullable)extraKeys
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *destMessage))successCallback
{
dispatch_async(queue, ^{
PEPMessage *theMessage = [[PEPMessage alloc] initWithMessage:message];
NSError *error = nil;
PEPMessage *destMessage = [[PEPSession new]
encryptMessage:theMessage
forSelf:ownIdentity
extraKeys:extraKeys
status:nil
error:&error];
if (destMessage) {
successCallback(theMessage, destMessage);
} else {
errorCallback(error);
}
});
}
- (void)encryptMessage:(PEPMessage *)message //BUFF: unused. (done) //DIRK: rm?
toFpr:(NSString *)toFpr
encFormat:(PEPEncFormat)encFormat
flags:(PEPDecryptFlags)flags
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPMessage *srcMessage,
PEPMessage *destMessage))successCallback
{
dispatch_async(queue, ^{
PEPMessage *theMessage = [[PEPMessage alloc] initWithMessage:message];
NSError *error = nil;
PEPMessage *destMessage = [[PEPSession new]
encryptMessage:theMessage
toFpr:toFpr
encFormat:encFormat
flags:flags
status:nil
error:&error];
if (destMessage) {
successCallback(theMessage, destMessage);
} else {
errorCallback(error);
}
});
}
- (void)outgoingRatingForMessage:(PEPMessage *)theMessage
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPRating rating))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSNumber *ratingNum = [[PEPSession new] outgoingRatingForMessage:theMessage error:&error];
if (ratingNum) {
successCallback(ratingNum.pEpRating);
} else {
errorCallback(error);
}
});
}
- (void)ratingForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPRating rating))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSNumber *ratingNum = [[PEPSession new]
ratingForIdentity:identity
error:&error];
if (ratingNum) {
successCallback(ratingNum.pEpRating);
} else {
errorCallback(error);
}
});
}
- (void)trustwordsForFingerprint:(NSString *)fingerprint
languageID:(NSString *)languageID
shortened:(BOOL)shortened
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSArray<NSString *> *trustwords))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSArray *trustwords = [[PEPSession new]
trustwordsForFingerprint:fingerprint
languageID:languageID
shortened:shortened
error:&error];
if (!error) {
successCallback(trustwords);
} else {
errorCallback(error);
}
});
}
- (void)mySelf:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPIdentity *identity))successCallback
{
__block PEPIdentity *theIdentity = [[PEPIdentity alloc] initWithIdentity:identity];
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] mySelf:theIdentity error:&error];
if (success) {
successCallback(theIdentity);
} else {
errorCallback(error);
}
});
}
- (void)updateIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(PEPIdentity *identity))successCallback
{
__block PEPIdentity *theIdentity = [[PEPIdentity alloc] initWithIdentity:identity];
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] updateIdentity:theIdentity error:&error];
if (success) {
successCallback(theIdentity);
} else {
errorCallback(error);
}
});
}
- (void)trustPersonalKey:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] trustPersonalKey:identity error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)keyMistrusted:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] keyMistrusted:identity error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)keyResetTrust:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] keyResetTrust:identity error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)enableSyncForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] enableSyncForIdentity:identity error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)disableSyncForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] disableSyncForIdentity:identity error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)queryKeySyncEnabledForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(BOOL enabled))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSNumber *boolNum = [[PEPSession new] queryKeySyncEnabledForIdentity:identity
error:&error];
if (boolNum) {
successCallback(boolNum.boolValue);
} else {
errorCallback(error);
}
});
}
- (void)importKey:(NSString *)keydata
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSArray<PEPIdentity *> *identities))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSArray *identities = [[PEPSession new] importKey:keydata error:&error];
if (identities) {
successCallback(identities);
} else {
errorCallback(error);
}
});
}
- (void)logTitle:(NSString *)title // DZ: DONE (not used by app/MM) //DIRK: rm?
entity:(NSString *)entity
description:(NSString * _Nullable)description
comment:(NSString * _Nullable)comment
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] logTitle:title
entity:entity
description:description
comment:comment
error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)getLog:(void (^)(NSError *error))errorCallback // DZ: DONE (not used by app/MM) //DIRK: rm?
successCallback:(void (^)(NSString *log))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSString *log = [[PEPSession new] getLogWithError:&error];
if (log) {
successCallback(log);
} else {
errorCallback(error);
}
});
}
- (void)getTrustwordsIdentity1:(PEPIdentity *)identity1
identity2:(PEPIdentity *)identity2
language:(NSString * _Nullable)language
full:(BOOL)full
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSString *trustwords))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSString *trustwords = [[PEPSession new] getTrustwordsIdentity1:identity1
identity2:identity2
language:language
full:full
error:&error];
if (trustwords) {
successCallback(trustwords);
} else {
errorCallback(error);
}
});
}
- (void)getTrustwordsFpr1:(NSString *)fpr1
fpr2:(NSString *)fpr2
language:(NSString * _Nullable)language
full:(BOOL)full
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSString *trustwords))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSString *trustwords = [[PEPSession new] getTrustwordsFpr1:fpr1
fpr2:fpr2
language:language
full:full
error:&error];
if (trustwords) {
successCallback(trustwords);
} else {
errorCallback(error);
}
});
}
- (void)languageList:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSArray<PEPLanguage *> *languages))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSArray *languages = [[PEPSession new] languageListWithError:&error];
if (languages) {
successCallback(languages);
} else {
errorCallback(error);
}
});
}
- (void)isPEPUser:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(BOOL enabled))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSNumber *ispEpUserNum = [[PEPSession new] isPEPUser:identity error:&error];
if (ispEpUserNum) {
successCallback(ispEpUserNum.boolValue);
} else {
errorCallback(error);
}
});
}
- (void)setOwnKey:(PEPIdentity *)identity
fingerprint:(NSString *)fingerprint
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] setOwnKey:identity
fingerprint:fingerprint
error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)deliverHandshakeResult:(PEPSyncHandshakeResult)result
identitiesSharing:(NSArray<PEPIdentity *> * _Nullable)identitiesSharing
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] deliverHandshakeResult:result
identitiesSharing:identitiesSharing
error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)trustOwnKeyIdentity:(PEPIdentity *)identity // DZ: DONE (not used by app/MM) //DIRK: rm?
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] trustOwnKeyIdentity:identity error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)keyReset:(PEPIdentity *)identity
fingerprint:(NSString * _Nullable)fingerprint
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] keyReset:identity
fingerprint:fingerprint
error:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)leaveDeviceGroup:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] leaveDeviceGroup:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
- (void)keyResetAllOwnKeys:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
BOOL success = [[PEPSession new] keyResetAllOwnKeysError:&error];
if (success) {
successCallback();
} else {
errorCallback(error);
}
});
}
@end

+ 0
- 971
pEpObjCTests/PEPAsyncSessionTest.m View File

@ -1,971 +0,0 @@
//
// PEPSessionTest.m
// pEpObjCAdapterTests
//
// Created by Dirk Zimmermann on 18.07.20.
// Copyright © 2020 pp. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "PEPObjCAdapterFramework.h"
#import "PEPTestUtils.h"
#import "PEPSessionProvider.h"
#import "PEPInternalSession.h"
@interface PEPSessionTest : XCTestCase
@end
@implementation PEPSessionTest
- (void)setUp
{
[super setUp];
[self pEpCleanUp];
[PEPObjCAdapter setUnEncryptedSubjectEnabled:NO];
NSError *error = nil;
XCTAssertTrue([PEPObjCAdapter configurePassphraseForNewKeys:nil error:&error]);
XCTAssertNil(error);
}
- (void)tearDown
{
[self pEpCleanUp];
[super tearDown];
}
- (void)pEpCleanUp
{
[PEPTestUtils cleanUp];
}
- (void)testMailToMyself
{
// Our test user:
// pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
// 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
XCTAssertTrue([self importBundledKey:@"6FF00E97_sec.asc"]);
PEPIdentity *identAlice = [[PEPIdentity alloc]
initWithAddress:@"pep.test.alice@pep-project.org"
userID:ownUserId
userName:@"pEp Test Alice"
isOwn:YES
fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
PEPSession *asyncSession = [PEPSession new];
NSError *error = nil;
PEPIdentity *identAliceMyselfed = [self mySelf:identAlice error:&error];
XCTAssertNotNil(identAliceMyselfed);
XCTAssertNil(error);
PEPMessage *msg = [PEPMessage new];
msg.from = identAlice;
msg.to = @[identAlice];
msg.shortMessage = @"Mail to Myself";
msg.longMessage = @"This is a text content";
msg.direction = PEPMsgDirectionOutgoing;
error = nil;
NSNumber *numRating = [self testOutgoingRatingForMessage:msg error:&error];
XCTAssertNotNil(numRating);
XCTAssertNil(error);
XCTAssertEqual(numRating.pEpRating, PEPRatingTrustedAndAnonymized);
for (NSNumber *boolNumWithEncFormat in @[@YES, @NO]) {
error = nil;
PEPMessage *encryptedMessage = [PEPMessage new];
if (boolNumWithEncFormat.boolValue) {
encryptedMessage = [self
encryptMessage:msg
extraKeys:nil
encFormat:PEPEncFormatPEP
status:nil
error:&error];
XCTAssertNotNil(encryptedMessage);
XCTAssertNil(error);
} else {
encryptedMessage = [self encryptMessage:msg extraKeys:nil status:nil error:&error];
XCTAssertNotNil(encryptedMessage);
XCTAssertNil(error);
}
XCTestExpectation *expectationDec = [self expectationWithDescription:@"expectationDec"];
[asyncSession
decryptMessage:encryptedMessage
flags:0
extraKeys:nil
errorCallback:^(NSError *error) {
XCTFail();
[expectationDec fulfill];
}
successCallback:^(PEPMessage * srcMessage,
PEPMessage * dstMessage,
PEPStringList * keyList,
PEPRating rating,
PEPDecryptFlags flags,
BOOL isFormerlyEncryptedReuploadedMessage) {
XCTAssertNotNil(dstMessage);
XCTAssertEqual(rating, PEPRatingTrustedAndAnonymized);
[expectationDec fulfill];
}];
[self waitForExpectations:@[expectationDec] timeout:PEPTestInternalSyncTimeout];
}
}
- (void)testEncryptToSelf
{
// Write mail to yourself ...
PEPMessage *encMessage = [self mailWrittenToMySelf];
// ... and assert subject is encrypted
XCTAssertEqualObjects(encMessage.shortMessage, @"pp");
}
- (void)testEncryptAndAttachPrivateKeyIllegalValue
{
PEPIdentity *identMe = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i@pep-project.org"
userID:@"me-myself-and-i"
userName:@"pEp Me"
isOwn:YES];
NSError *error = nil;
identMe = [self mySelf:identMe error:&error];
XCTAssertNotNil(identMe);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
NSString *fprAlice = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
PEPIdentity *identAlice = [self
checkImportingKeyFilePath:@"6FF00E97_sec.asc"
address:@"pep.test.alice@pep-project.org"
userID:@"alice_user_id"
fingerPrint:fprAlice];
XCTAssertNotNil(identAlice);
XCTAssertEqualObjects(identAlice.fingerPrint, fprAlice);
NSString *shortMessage = @"whatever it may be";
NSString *longMessage = [NSString stringWithFormat:@"%@ %@", shortMessage, shortMessage];
PEPMessage *message = [PEPMessage new];
message.from = identMe;
message.to = @[identAlice];
message.shortMessage = shortMessage;
message.longMessage = longMessage;
XCTestExpectation *expectationEnc = [self expectationWithDescription:@"expectationEnc"];
PEPSession *asyncSession = [PEPSession new];
[asyncSession
encryptMessage:message
toFpr:fprAlice
encFormat:PEPEncFormatPEP
flags:0
errorCallback:^(NSError * _Nonnull error) {
[expectationEnc fulfill];
} successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
XCTFail();
[expectationEnc fulfill];
}];
[self waitForExpectations:@[expectationEnc] timeout:PEPTestInternalSyncTimeout];
}
- (void)testRatingForIdentity
{
PEPIdentity *me = [self
checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc"
address:@"pep.test.alice@pep-project.org"
userID:@"Alice_User_ID"
fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
XCTAssertNotNil(me);
XCTAssertEqual([self ratingForIdentity:me], PEPRatingTrustedAndAnonymized);
PEPIdentity *alice = [self
checkImportingKeyFilePath:@"6FF00E97_sec.asc"
address:@"pep.test.alice@pep-project.org"
userID:@"This Is Alice"
fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
XCTAssertNotNil(alice);
XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable);
}
- (void)testTrustWords
{
NSError *error = nil;
NSArray *trustwords = [self
trustwordsForFingerprint:@"DB47DB47DB47DB47DB47DB47DB47DB47DB47DB47"
languageID:@"en"
shortened:false
error:&error];
XCTAssertNil(error);
XCTAssertEqual([trustwords count], 10);
for(id word in trustwords) {
XCTAssertEqualObjects(word, @"BAPTISMAL");
}
}
- (void)testIdentityRatingTrustResetMistrustUndo
{
PEPIdentity *me = [[PEPIdentity alloc]
initWithAddress:@"me@example.org"
userID:@"me_myself"
userName:@"Me Me"
isOwn:YES];
NSError *error = nil;
me = [self mySelf:me error:&error];
XCTAssertNotNil(me);
XCTAssertNil(error);
XCTAssertNotNil(me.fingerPrint);
XCTAssertEqual([self ratingForIdentity:me], PEPRatingTrustedAndAnonymized);
PEPIdentity *alice = [self
checkImportingKeyFilePath:@"6FF00E97_sec.asc"
address:@"pep.test.alice@pep-project.org"
userID:@"This Is Alice"
fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
XCTAssertNotNil(alice);
XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable);
XCTAssertTrue([self trustPersonalKey:alice error:&error]);
XCTAssertNil(error);
XCTAssertEqual([self ratingForIdentity:alice], PEPRatingTrusted);
XCTAssertTrue([self keyResetTrust:alice error:&error]);
XCTAssertNil(error);
XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable);
XCTAssertTrue([self keyMistrusted:alice error:&error]);
XCTAssertNil(error);
XCTAssertEqual([self ratingForIdentity:alice], PEPRatingHaveNoKey);
}
- (void)testQueryKeySyncOnOwnIdentityInALoop
{
PEPIdentity *identMe = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i@pep-project.org"
userID:@"me-myself-and-i"
userName:@"pEp Me"
isOwn:YES];
NSError *error = nil;
identMe = [self mySelf:identMe error:&error];
XCTAssertNotNil(identMe);
XCTAssertNil(error);
for (NSNumber *numBool in @[@YES, @NO]) {
error = nil;
if ([numBool boolValue]) {
XCTAssertTrue([self enableSyncForIdentity:identMe error:&error]);
} else {
XCTAssertTrue([self disableSyncForIdentity:identMe error:&error]);
}
XCTAssertNil(error);
for (int i = 0; i < 10; ++i) {
NSNumber *numQuery = [self queryKeySyncEnabledForIdentity:identMe error:&error];
XCTAssertNotNil(numQuery);
XCTAssertEqualObjects(numBool, numQuery);
XCTAssertNil(error);
}
}
}
- (void)testGetLogWithError
{
NSError *error = nil;
NSString *log = [self getLogWithError:&error];
XCTAssertGreaterThan(log.length, 0);
XCTAssertNotNil(log);
XCTAssertNil(error);
}
- (void)testGetTrustwords
{
PEPIdentity *partner1Orig = [[PEPIdentity alloc]
initWithAddress:@"partner1@dontcare.me" userID:@"partner1"
userName:@"partner1"
isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"];
PEPIdentity *meOrig = [[PEPIdentity alloc]
initWithAddress:@"me@dontcare.me" userID:@"me"
userName:@"me"
isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"];
NSError *error = nil;
NSString *trustwordsFull = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig
language:@"en" full:YES error:&error];
XCTAssertNil(error);
XCTAssertEqualObjects(trustwordsFull,
@"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD");
NSString *trustwordsUndefined = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig
language:@"ZZ" full:YES error:&error];
XCTAssertNotNil(error);
XCTAssertNil(trustwordsUndefined);
}
- (void)testGenKey
{
PEPIdentity *identMe = [[PEPIdentity alloc]
initWithAddress:@"pep.test.iosgenkey@pep-project.org"
userID:@"Me"
userName:@"pEp Test iOS GenKey"
isOwn:YES];
NSError *error = nil;
identMe = [self mySelf:identMe error:&error];
XCTAssertNotNil(identMe);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
XCTAssertNotEqual(identMe.commType, PEPCommTypeUnknown);
NSNumber *boolNum = [self isPEPUser:identMe error:&error];
XCTAssertNil(error);
XCTAssertNotNil(boolNum);
XCTAssertTrue(boolNum.boolValue);
}
- (void)testTrustOwnKey
{
PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
userName:@"userName"];
NSError *error = nil;
me = [self mySelf:me error:&error];
XCTAssertNotNil(me);
XCTAssertNil(error);
XCTAssertTrue([self trustOwnKeyIdentity:me error:&error]);
XCTAssertNil(error);
}
- (void)testKeyResetIdentityOnOwnKeyIsIllegal
{
PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
userName:@"userName"];
NSError *error = nil;
me = [self mySelf:me error:&error];
XCTAssertNotNil(me);
XCTAssertNil(error);
NSString *fprOriginal = me.fingerPrint;
XCTAssertNotNil(fprOriginal);
// Cannot reset all _own_ keys with this method, as documented
XCTAssertFalse([self keyReset:me fingerprint:nil error:&error]);
XCTAssertNotNil(error);
me = [self mySelf:me error:&error];
XCTAssertNotNil(me);
XCTAssertNil(error);
NSString *fprAfterReset = me.fingerPrint;
XCTAssertNotNil(fprAfterReset);
XCTAssertNotEqual(fprOriginal, fprAfterReset);
}
#pragma mark - Helpers
- (PEPMessage *)mailWrittenToMySelf
{
// Write a e-mail to yourself ...
PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
userName:@"userName"];
NSError *error = nil;
me = [self mySelf:me error:&error];
XCTAssertNotNil(me);
XCTAssertNil(error);
NSString *shortMessage = @"Subject";
NSString *longMessage = @"Oh, this is a long body text!";
PEPMessage *mail = [PEPTestUtils mailFrom:me
toIdent:me
shortMessage:shortMessage
longMessage:longMessage
outgoing:YES];
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *expectationEnc = [self expectationWithDescription:@"expectationEnc"];
__block PEPMessage *encryptedMessage = [PEPMessage new];
[asyncSession
encryptMessage:mail
forSelf:me
extraKeys:nil
errorCallback:^(NSError * _Nonnull error) {
XCTFail();
[expectationEnc fulfill];
} successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
encryptedMessage = destMessage;
[expectationEnc fulfill];
}];
[self waitForExpectations:@[expectationEnc] timeout:PEPTestInternalSyncTimeout];
return encryptedMessage;
}
- (NSNumber * _Nullable)testOutgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
error:(NSError * _Nullable * _Nullable)error
{
NSError *theError = nil;
NSNumber *ratingOriginal = [self outgoingRatingForMessage:theMessage error:&theError];
XCTAssertNotNil(ratingOriginal);
XCTAssertNil(theError);
if (ratingOriginal == nil) {
return nil;
}
NSNumber *ratingPreview = [[PEPSessionProvider session]
outgoingRatingPreviewForMessage:theMessage
error:error];
XCTAssertEqual(ratingOriginal, ratingPreview);
return ratingOriginal;
}
- (PEPIdentity *)checkImportingKeyFilePath:(NSString *)filePath address:(NSString *)address
userID:(NSString *)userID
fingerPrint:(NSString *)fingerPrint
{
BOOL success = [self importBundledKey:filePath];
XCTAssertTrue(success);
if (success) {
// Our test user:
PEPIdentity *identTest = [[PEPIdentity alloc]
initWithAddress:address
userID:userID
userName:[NSString stringWithFormat:@"Some User Name %@", userID]
isOwn:NO];
NSError *error = nil;
PEPIdentity *identTestUpdated = [self updateIdentity:identTest error:&error];
XCTAssertNil(error);
XCTAssertNotNil(identTestUpdated);
XCTAssertNotNil(identTestUpdated.fingerPrint);
XCTAssertEqualObjects(identTestUpdated.fingerPrint, fingerPrint);
return identTestUpdated;
} else {
return nil;
}
}
- (BOOL)importBundledKey:(NSString *)item
{
PEPSession *asyncSession = [PEPSession new];
NSString *txtFileContents = [PEPTestUtils loadStringFromFileName:item];
if (!txtFileContents) {
XCTFail();
}
__block BOOL success = YES;
XCTestExpectation *expImport = [self expectationWithDescription:@"expImport"];
[asyncSession importKey:txtFileContents
errorCallback:^(NSError * _Nonnull error) {
XCTFail();
success = NO;
[expImport fulfill];
} successCallback:^(NSArray<PEPIdentity *> * _Nonnull identities) {
[expImport fulfill];
success = YES;
}];
[self waitForExpectations:@[expImport] timeout:PEPTestInternalSyncTimeout];
return success;
}
- (PEPIdentity * _Nullable)checkMySelfImportingKeyFilePath:(NSString *)filePath
address:(NSString *)address
userID:(NSString *)userID
fingerPrint:(NSString *)fingerPrint
{
PEPSession *asyncSession = [PEPSession new];
XCTAssertTrue([self importBundledKey:filePath]);
// Our test user:
PEPIdentity *identTest = [[PEPIdentity alloc]
initWithAddress:address
userID:userID
userName:[NSString stringWithFormat:@"Some User Name %@", userID]
isOwn:YES
fingerPrint: fingerPrint];
__block BOOL success = NO;
XCTestExpectation *expSetOwnKey = [self expectationWithDescription:@"expSetOwnKey"];
[asyncSession setOwnKey:identTest
fingerprint:fingerPrint
errorCallback:^(NSError * _Nonnull error) {
XCTFail();
success = NO;
[expSetOwnKey fulfill];
} successCallback:^{
success = YES;
[expSetOwnKey fulfill];
}];
[self waitForExpectations:@[expSetOwnKey] timeout:PEPTestInternalSyncTimeout];
if (success) {
return identTest;
} else {
return nil;
}
}
#pragma mark - Normal session to async
- (PEPRating)ratingForIdentity:(PEPIdentity *)identity
{
PEPSession *asyncSession = [PEPSession new];
__block PEPRating resultingRating = PEPRatingB0rken;
XCTestExpectation *expRated = [self expectationWithDescription:@"expRated"];
[asyncSession ratingForIdentity:identity
errorCallback:^(NSError * _Nonnull error) {
XCTFail();
[expRated fulfill];
} successCallback:^(PEPRating rating) {
resultingRating = rating;
[expRated fulfill];
}];
[self waitForExpectations:@[expRated] timeout:PEPTestInternalSyncTimeout];
return resultingRating;
}
- (PEPIdentity * _Nullable)mySelf:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *expMyself = [self expectationWithDescription:@"expMyself"];
__block PEPIdentity *identityMyselfed = nil;
__block NSError *errorMyself = nil;
[asyncSession mySelf:identity
errorCallback:^(NSError * _Nonnull theError) {
errorMyself = theError;
[expMyself fulfill];
} successCallback:^(PEPIdentity * _Nonnull identity) {
identityMyselfed = identity;
[expMyself fulfill];
}];
[self waitForExpectations:@[expMyself] timeout:PEPTestInternalSyncTimeout];
*error = errorMyself;
XCTAssertNotNil(identityMyselfed);
if (error) {
*error = errorMyself;
}
return identityMyselfed;
}
- (NSArray<NSString *> * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
languageID:(NSString * _Nonnull)languageID
shortened:(BOOL)shortened
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block NSArray<NSString *> *result = nil;
__block NSError *theError = nil;
[asyncSession trustwordsForFingerprint:fingerprint
languageID:languageID
shortened:shortened
errorCallback:^(NSError * _Nonnull error) {
theError = error;
[exp fulfill];
} successCallback:^(NSArray<NSString *> * _Nonnull trustwords) {
[exp fulfill];
result = trustwords;
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (PEPIdentity * _Nullable)updateIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *expUpdateIdent = [self expectationWithDescription:@"expUpdateIdent"];
__block PEPIdentity *identTestUpdated = nil;
__block NSError *theError = nil;
[asyncSession updateIdentity:identity
errorCallback:^(NSError * _Nonnull error) {
theError = error;
[expUpdateIdent fulfill];
} successCallback:^(PEPIdentity * _Nonnull identity) {
identTestUpdated = identity;
[expUpdateIdent fulfill];
}];
[self waitForExpectations:@[expUpdateIdent] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return identTestUpdated;
}
- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block NSNumber *result = nil;
__block NSError *theError = nil;
[asyncSession outgoingRatingForMessage:theMessage
errorCallback:^(NSError * _Nonnull error) {
theError = error;
[exp fulfill];
} successCallback:^(PEPRating rating) {
result = [NSNumber numberWithPEPRating:rating];
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
extraKeys:(PEPStringList * _Nullable)extraKeys
encFormat:(PEPEncFormat)encFormat
status:(PEPStatus * _Nullable)status
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block PEPMessage *result = nil;
__block NSError *theError = nil;
[asyncSession encryptMessage:message
extraKeys:extraKeys
encFormat:encFormat
errorCallback:^(NSError * _Nonnull error) {
theError = error;
[exp fulfill];
} successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
result = destMessage;
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
extraKeys:(PEPStringList * _Nullable)extraKeys
status:(PEPStatus * _Nullable)status
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block PEPMessage *result = nil;
__block NSError *theError = nil;
[asyncSession encryptMessage:message
extraKeys:extraKeys
errorCallback:^(NSError * _Nonnull error) {
theError = error;
[exp fulfill];
} successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
result = destMessage;
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block BOOL result = NO;
__block NSError *theError = nil;
[asyncSession trustPersonalKey:identity
errorCallback:^(NSError * _Nonnull error) {
result = NO;
theError = error;
[exp fulfill];
} successCallback:^{
result = YES;
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block BOOL result = NO;
__block NSError *theError = nil;
[asyncSession keyResetTrust:identity
errorCallback:^(NSError * _Nonnull error) {
result = NO;
theError = error;
[exp fulfill];
} successCallback:^{
result = YES;
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (BOOL)keyMistrusted:(PEPIdentity *)identity error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block BOOL result = NO;
__block NSError *theError = nil;
[asyncSession keyMistrusted:identity
errorCallback:^(NSError * _Nonnull error) {
result = NO;
theError = error;
[exp fulfill];
} successCallback:^{
result = YES;
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (BOOL)enableSyncForIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block BOOL result = NO;
__block NSError *theError = nil;
[asyncSession enableSyncForIdentity:identity
errorCallback:^(NSError * _Nonnull error) {
result = NO;
theError = error;
[exp fulfill];
} successCallback:^{
result = YES;
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (NSNumber * _Nullable)queryKeySyncEnabledForIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block NSNumber *result = nil;
__block NSError *theError = nil;
[asyncSession queryKeySyncEnabledForIdentity:identity
errorCallback:^(NSError * _Nonnull error) {
result = nil;
theError = error;
[exp fulfill];
} successCallback:^(BOOL enabled) {
result = [NSNumber numberWithBool:enabled];
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (BOOL)disableSyncForIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
<