//
|
|
// PEPObjCAdapterXPCApi.m
|
|
// foundation.pEp.adapter.macOS
|
|
//
|
|
// Created by David Alarcon on 9/2/21.
|
|
// Copyright © 2021 p≡p foundation. All rights reserved.
|
|
//
|
|
|
|
#import "PEPObjCAdapterXPCApi.h"
|
|
|
|
#import "PEPSession.h"
|
|
#import "PEPIdentity.h"
|
|
#import "PEPObjCAdapterXpcApiResult.h"
|
|
#import "PEPObjcAdapter.h"
|
|
|
|
@implementation PEPObjCAdapterXPCApi
|
|
|
|
- (void)myself:(PEPIdentity *)identity resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
|
|
|
|
PEPSession *session = [PEPSession new];
|
|
[session mySelf:identity errorCallback:^(NSError * _Nonnull error) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc] initWithResult:nil error:error];
|
|
resultCallback(result);
|
|
} successCallback:^(PEPIdentity * _Nonnull identity) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc] initWithResult:@[identity] error:nil];
|
|
resultCallback(result);
|
|
}];
|
|
}
|
|
|
|
- (void)encryptMessage:(PEPMessage *)message
|
|
extraKeys:(PEPStringList * _Nullable)extraKeys
|
|
encFormat:(PEPEncFormat)encFormat
|
|
resultBlock:(void (^)(PEPObjCAdapterXpcApiResult *))resultCallback {
|
|
NSLog(@"%s", __PRETTY_FUNCTION__);
|
|
PEPSession *session = [PEPSession new];
|
|
[session encryptMessage:message extraKeys:extraKeys encFormat:encFormat
|
|
errorCallback:^(NSError * _Nonnull error) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:nil
|
|
error:error];
|
|
resultCallback(result);
|
|
} successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:@[srcMessage, destMessage]
|
|
error:nil];
|
|
resultCallback(result);
|
|
}];
|
|
}
|
|
|
|
- (void)outgoingRatingForMessage:(PEPMessage *)theMessage
|
|
resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
|
|
NSLog(@"%s", __PRETTY_FUNCTION__);
|
|
PEPSession *session = [PEPSession new];
|
|
[session outgoingRatingForMessage:theMessage errorCallback:^(NSError * _Nonnull error) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:nil
|
|
error:error];
|
|
resultCallback(result);
|
|
} successCallback:^(PEPRating rating) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:@[@(rating)]
|
|
error:nil];
|
|
resultCallback(result);
|
|
}];
|
|
}
|
|
|
|
- (void)colorFromRating:(PEPRating)rating
|
|
resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
|
|
NSLog(@"%s", __PRETTY_FUNCTION__);
|
|
|
|
PEPSession *session = [PEPSession new];
|
|
PEPColor color = [session colorFromRating:rating];
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:@[@(color)]
|
|
error:nil];
|
|
resultCallback(result);
|
|
}
|
|
|
|
- (void)encryptMessage:(PEPMessage *)message
|
|
forSelf:(PEPIdentity *)ownIdentity
|
|
extraKeys:(PEPStringList *)extraKeys
|
|
resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
|
|
NSLog(@"%s", __PRETTY_FUNCTION__);
|
|
|
|
PEPSession *session = [PEPSession new];
|
|
[session encryptMessage:message forSelf:ownIdentity extraKeys:extraKeys errorCallback:^(NSError * _Nonnull error) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:nil
|
|
error:error];
|
|
resultCallback(result);
|
|
} successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:@[srcMessage, destMessage]
|
|
error:nil];
|
|
resultCallback(result);
|
|
}];
|
|
}
|
|
|
|
- (void)decryptMessage:(PEPMessage *)message
|
|
flags:(PEPDecryptFlags)flags
|
|
extraKeys:(PEPStringList *)extraKeys
|
|
resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
|
|
NSLog(@"%s", __PRETTY_FUNCTION__);
|
|
|
|
PEPSession *session = [PEPSession new];
|
|
[session decryptMessage:message flags:flags extraKeys:extraKeys errorCallback:^(NSError * _Nonnull error) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:nil
|
|
error:error];
|
|
resultCallback(result);
|
|
} successCallback:^(PEPMessage * _Nonnull srcMessage,
|
|
PEPMessage * _Nonnull dstMessage,
|
|
PEPStringList * _Nonnull keyList,
|
|
PEPRating rating,
|
|
PEPDecryptFlags flags,
|
|
BOOL isFormerlyEncryptedReuploadedMessage) {
|
|
PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
|
|
initWithResult:@[srcMessage,
|
|
dstMessage,
|
|
keyList,
|
|
@(rating),
|
|
@(flags),
|
|
@(isFormerlyEncryptedReuploadedMessage)]
|
|
error:nil];
|
|
resultCallback(result);
|
|
}];
|
|
}
|
|
|
|
- (void)setPassiveModeEnabled:(BOOL)enabled {
|
|
NSLog(@"%s <%@>", __PRETTY_FUNCTION__, enabled ? @"ON" : @"OFF");
|
|
[PEPObjCAdapter setPassiveModeEnabled:enabled];
|
|
}
|
|
|
|
@end
|