pEpObjCAdapter/PEPObjCAdapter.m
author buff <andreas@pep-project.org>
Tue, 10 Oct 2017 18:56:57 +0200
branchIOSAD-50
changeset 268 afba0883d4d9
parent 262 9ab6513df261
child 269 5a187b6cf883
permissions -rw-r--r--
IOSAD-50 do not give the session to the client (I will mess it up otherwize).
dirk@187
     1
//
edouard@191
     2
//  pEpObjCAdapter.m
edouard@191
     3
//  pEpObjCAdapter
dirk@187
     4
//
dirk@187
     5
//  Created by Volker Birk on 28.04.15.
dirk@187
     6
//  Copyright (c) 2015 p≡p. All rights reserved.
dirk@187
     7
//
dirk@187
     8
dirk@187
     9
@import Foundation;
dirk@187
    10
dirk@187
    11
#import "PEPObjCAdapter.h"
dirk@187
    12
#import "PEPObjCAdapter+Internal.h"
dirk@187
    13
#import "PEPMessage.h"
andreas@262
    14
#import "PEPSessionProvider.h"
dirk@187
    15
#include "keymanagement.h"
andreas@262
    16
#import "PEPCopyableThread.h"
dirk@187
    17
dirk@187
    18
///////////////////////////////////////////////////////////////////////////////
dirk@187
    19
//  Keyserver and Identity lookup - C part
dirk@187
    20
dirk@187
    21
dirk@187
    22
int examine_identity(pEp_identity *ident, void *management)
dirk@187
    23
{
dirk@187
    24
    //PEPQueue *q = (__bridge PEPQueue *)management;
dirk@187
    25
    PEPQueue *q = [PEPObjCAdapter getLookupQueue];
dirk@187
    26
    
dirk@187
    27
    NSDictionary *identity = PEP_identityDictFromStruct(ident);
dirk@187
    28
    
dirk@187
    29
    [q enqueue:identity];
dirk@187
    30
    return 0;
dirk@187
    31
}
dirk@187
    32
dirk@187
    33
static pEp_identity *retrieve_next_identity(void *management)
dirk@187
    34
{
dirk@187
    35
    //PEPQueue *q = (__bridge PEPQueue *)management;
dirk@187
    36
    PEPQueue *q = [PEPObjCAdapter getLookupQueue];
dirk@187
    37
    
dirk@187
    38
    // Dequeue is a blocking operation
dirk@187
    39
    // that returns nil when queue is killed
dirk@187
    40
    NSDictionary *ident = [q dequeue];
dirk@187
    41
    
dirk@187
    42
    if (ident)
dirk@187
    43
        return PEP_identityDictToStruct(ident);
dirk@187
    44
    else
dirk@187
    45
        return NULL;
dirk@187
    46
}
dirk@187
    47
dirk@187
    48
///////////////////////////////////////////////////////////////////////////////
dirk@187
    49
// Sync - C part
dirk@187
    50
dirk@187
    51
// Called by sync thread only
dirk@187
    52
PEP_STATUS notify_handshake(void *unused_object, pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
dirk@187
    53
{
dirk@187
    54
    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
dirk@187
    55
    if ( syncDelegate )
dirk@187
    56
        return [syncDelegate
dirk@187
    57
                notifyHandshakeWithSignal:signal
dirk@187
    58
                me:PEP_identityDictFromStruct(me)
dirk@187
    59
                partner:PEP_identityDictFromStruct(partner)];
dirk@187
    60
    else
dirk@187
    61
        return PEP_SYNC_NO_NOTIFY_CALLBACK;
dirk@187
    62
}
dirk@187
    63
dirk@187
    64
// Called by sync thread only
dirk@187
    65
PEP_STATUS message_to_send(void *unused_object, message *msg)
dirk@187
    66
{
dirk@187
    67
    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
dirk@187
    68
    if ( syncDelegate )
dirk@187
    69
        return [syncDelegate sendMessage:PEP_messageDictFromStruct(msg)];
dirk@187
    70
    else
dirk@187
    71
        return PEP_SEND_FUNCTION_NOT_REGISTERED;
dirk@187
    72
}
dirk@187
    73
dirk@187
    74
// called indirectly by decrypt message - any thread/session
dirk@187
    75
int inject_sync_msg(void *msg, void *unused_management)
dirk@187
    76
{
dirk@187
    77
    PEPQueue *q = [PEPObjCAdapter getSyncQueue];
dirk@187
    78
    
dirk@187
    79
    [q enqueue:[NSValue valueWithPointer:msg]];
dirk@187
    80
    
dirk@187
    81
    return 0;
dirk@187
    82
}
dirk@187
    83
dirk@187
    84
// Called by sync thread only
dirk@187
    85
void *retrieve_next_sync_msg(void *unused_mamagement, time_t *timeout)
dirk@187
    86
{
edouard@192
    87
    bool needs_fastpoll = (*timeout != 0);
edouard@192
    88
    
edouard@192
    89
    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
edouard@192
    90
    if ( syncDelegate && needs_fastpoll )
edouard@192
    91
        [syncDelegate fastPolling:true];
edouard@192
    92
    
dirk@187
    93
    PEPQueue *q = [PEPObjCAdapter getSyncQueue];
andreas@268
    94
    
edouard@193
    95
    void* result = (void*)[[q timedDequeue:timeout] pointerValue];
andreas@268
    96
    
edouard@192
    97
    if ( syncDelegate && needs_fastpoll )
edouard@192
    98
        [syncDelegate fastPolling:false];
dirk@187
    99
    
edouard@192
   100
    return result;
andreas@268
   101
    
dirk@187
   102
}
dirk@187
   103
dirk@187
   104
///////////////////////////////////////////////////////////////////////////////
dirk@187
   105
// DB and paths
dirk@187
   106
dirk@187
   107
const char* _Nullable SystemDB = NULL;
dirk@187
   108
NSURL *s_homeURL;
dirk@254
   109
static NSLock *s_initLock;
dirk@187
   110
dirk@187
   111
@implementation PEPObjCAdapter
dirk@187
   112
andreas@258
   113
+ (void)cleanup
andreas@258
   114
{
andreas@262
   115
    [PEPSessionProvider cleanup];
andreas@258
   116
}
andreas@258
   117
dirk@187
   118
+ (void)initialize
dirk@187
   119
{
dirk@187
   120
    s_homeURL = [self createApplicationDirectory];
dirk@254
   121
    s_initLock = [[NSLock alloc] init];
dirk@254
   122
}
dirk@254
   123
dirk@254
   124
+ (NSLock *)initLock
dirk@254
   125
{
dirk@254
   126
    return s_initLock;
dirk@187
   127
}
dirk@187
   128
dirk@187
   129
+ (NSURL *)homeURL
dirk@187
   130
{
dirk@187
   131
    return s_homeURL;
dirk@187
   132
}
dirk@187
   133
dirk@187
   134
+ (NSURL *)createApplicationDirectory
dirk@187
   135
{
dirk@187
   136
    NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
dirk@187
   137
    if (!bundleID) {
dirk@187
   138
        // This can happen in unit tests
dirk@187
   139
        bundleID = @"test";
dirk@187
   140
    }
dirk@187
   141
    NSFileManager *fm = [NSFileManager defaultManager];
dirk@187
   142
    NSURL *dirPath = nil;
andreas@268
   143
    
dirk@187
   144
    // Find the application support directory in the home directory.
dirk@187
   145
    NSArray *appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory
dirk@187
   146
                                        inDomains:NSUserDomainMask];
dirk@187
   147
    if ([appSupportDir count] > 0)
dirk@187
   148
    {
dirk@187
   149
        // Append the bundle ID to the URL for the
dirk@187
   150
        // Application Support directory.
dirk@187
   151
        // Mainly needed for OS X, but doesn't do any harm on iOS
dirk@187
   152
        dirPath = [[appSupportDir objectAtIndex:0] URLByAppendingPathComponent:bundleID];
andreas@268
   153
        
dirk@187
   154
        // If the directory does not exist, this method creates it.
dirk@187
   155
        // This method is only available in OS X v10.7 and iOS 5.0 or later.
dirk@187
   156
        NSError *theError = nil;
dirk@187
   157
        if (![fm createDirectoryAtURL:dirPath withIntermediateDirectories:YES
dirk@187
   158
                           attributes:nil error:&theError])
dirk@187
   159
        {
dirk@187
   160
            // Handle the error.
dirk@187
   161
            return nil;
dirk@187
   162
        }
dirk@187
   163
    }
andreas@268
   164
    
dirk@187
   165
    return dirPath;
dirk@187
   166
}
dirk@187
   167
dirk@187
   168
+ (NSURL *)createAndSetHomeDirectory
dirk@187
   169
{
dirk@187
   170
    // create and set home directory
dirk@187
   171
    setenv("HOME", [[s_homeURL path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
andreas@268
   172
    
dirk@187
   173
    // create and set temp directory
dirk@187
   174
    NSURL *tmpDirUrl = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
dirk@187
   175
    setenv("TEMP", [[tmpDirUrl path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
andreas@268
   176
    
dirk@187
   177
    return s_homeURL;
dirk@187
   178
}
dirk@187
   179
dirk@187
   180
+ (NSString *) getBundlePathFor: (NSString *) filename
dirk@187
   181
{
dirk@187
   182
    return nil;
dirk@187
   183
}
dirk@187
   184
dirk@187
   185
+ (NSString *) copyAssetIntoDocumentsDirectory:(NSBundle *)rootBundle
andreas@262
   186
                                              :(NSString *)bundleName
andreas@262
   187
                                              :(NSString *)fileName{
andreas@268
   188
    
dirk@187
   189
    NSURL *homeUrl = [PEPObjCAdapter createAndSetHomeDirectory];
dirk@187
   190
    NSString *documentsDirectory = [homeUrl path];
dirk@187
   191
    
dirk@187
   192
    if(!(documentsDirectory && bundleName && fileName))
dirk@187
   193
        return nil;
dirk@187
   194
    
dirk@187
   195
    // Check if the database file exists in the documents directory.
dirk@187
   196
    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:fileName];
dirk@187
   197
    if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
dirk@187
   198
        // The file does not exist in the documents directory, so copy it from bundle now.
dirk@187
   199
        NSBundle *bundleObj = [NSBundle bundleWithPath:
dirk@187
   200
                               [[rootBundle resourcePath]
dirk@187
   201
                                stringByAppendingPathComponent: bundleName]];
dirk@187
   202
        
dirk@187
   203
        if (!bundleObj)
dirk@187
   204
            return nil;
dirk@187
   205
        
dirk@187
   206
        NSString *sourcePath =[[bundleObj resourcePath] stringByAppendingPathComponent: fileName];
dirk@187
   207
        
dirk@187
   208
        NSError *error;
dirk@187
   209
        [[NSFileManager defaultManager]
dirk@187
   210
         copyItemAtPath:sourcePath toPath:destinationPath error:&error];
dirk@187
   211
        
dirk@187
   212
        // Check if any error occurred during copying and display it.
dirk@187
   213
        if (error != nil) {
dirk@187
   214
            NSLog(@"%@", [error localizedDescription]);
dirk@187
   215
            return nil;
dirk@187
   216
        }
dirk@187
   217
    }
dirk@187
   218
    NSLog(@"Asset %@ copied into %@", fileName, destinationPath);
dirk@187
   219
    return destinationPath;
dirk@187
   220
}
dirk@187
   221
dirk@187
   222
+ (void)setupTrustWordsDB:(NSBundle *)rootBundle{
dirk@187
   223
    NSString *systemDBPath = [PEPObjCAdapter copyAssetIntoDocumentsDirectory:rootBundle
andreas@262
   224
                                                                            :@"pEpTrustWords.bundle"
andreas@262
   225
                                                                            :@"system.db"];
dirk@187
   226
    if (SystemDB) {
dirk@187
   227
        free((void *) SystemDB);
dirk@187
   228
    }
dirk@187
   229
    SystemDB = strdup(systemDBPath.UTF8String);
dirk@187
   230
}
dirk@187
   231
dirk@187
   232
+ (void)setupTrustWordsDB
dirk@187
   233
{
dirk@187
   234
    [PEPObjCAdapter setupTrustWordsDB:[NSBundle mainBundle]];
dirk@187
   235
}
dirk@187
   236
dirk@187
   237
static NSMutableArray* boundSessions = nil;
dirk@187
   238
dirk@187
   239
+ (NSMutableArray*)boundSessions
dirk@187
   240
{
dirk@187
   241
    static dispatch_once_t once;
dirk@187
   242
    dispatch_once(&once, ^{
dirk@187
   243
        boundSessions =  [[NSMutableArray alloc] init];
dirk@187
   244
    });
dirk@187
   245
    return boundSessions;
dirk@187
   246
}
dirk@187
   247
dirk@187
   248
///////////////////////////////////////////////////////////////////////////////
dirk@187
   249
//  Keyserver and Identity lookup - ObjC part
dirk@187
   250
dirk@187
   251
static PEPQueue *lookupQueue = nil;
dirk@187
   252
static NSThread *lookupThread = nil;
dirk@187
   253
static NSConditionLock *lookupThreadJoinCond = nil;
dirk@187
   254
dirk@187
   255
+ (void)lookupThreadRoutine:(id)object
dirk@187
   256
{
dirk@187
   257
    [lookupThreadJoinCond lock];
andreas@268
   258
    
dirk@187
   259
    // FIXME: do_KeyManagement asserts if management is null.
dirk@187
   260
    do_keymanagement(retrieve_next_identity, "NOTNULL" /* (__bridge void *)queue */);
dirk@187
   261
    
dirk@187
   262
    // Set and signal join()
dirk@187
   263
    [lookupThreadJoinCond unlockWithCondition:YES];
dirk@187
   264
}
dirk@187
   265
dirk@187
   266
+ (void)startKeyserverLookup
dirk@187
   267
{
dirk@187
   268
    if (!lookupQueue)
dirk@187
   269
    {
dirk@187
   270
        lookupQueue = [[PEPQueue alloc]init];
dirk@187
   271
        
dirk@187
   272
        // There is no join() call on NSThreads.
dirk@187
   273
        lookupThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
dirk@187
   274
        
dirk@187
   275
        lookupThread = [[NSThread alloc] initWithTarget:self selector:@selector(lookupThreadRoutine:) object:nil];
dirk@187
   276
        [lookupThread start];
dirk@187
   277
    }
dirk@187
   278
}
dirk@187
   279
dirk@187
   280
+ (void)stopKeyserverLookup
dirk@187
   281
{
dirk@187
   282
    
dirk@187
   283
    if (lookupQueue)
dirk@187
   284
    {
dirk@187
   285
        // Flush queue and kick the consumer
dirk@187
   286
        [lookupQueue kill];
dirk@187
   287
        
dirk@187
   288
        // Thread then bailout. Wait for that.
dirk@187
   289
        [lookupThreadJoinCond lockWhenCondition:YES];
dirk@187
   290
        [lookupThreadJoinCond unlock];
dirk@187
   291
        
dirk@187
   292
        lookupThread = nil;
dirk@187
   293
        lookupQueue = nil;
dirk@187
   294
        lookupThreadJoinCond = nil;
dirk@187
   295
    }
dirk@187
   296
}
dirk@187
   297
dirk@187
   298
+ (void)registerExamineFunction:(PEP_SESSION)session
dirk@187
   299
{
dirk@187
   300
    register_examine_function(session, examine_identity, NULL /* (__bridge void *)queue */);
dirk@187
   301
}
dirk@187
   302
dirk@187
   303
+ (PEPQueue*)getLookupQueue
dirk@187
   304
{
dirk@187
   305
    return lookupQueue;
dirk@187
   306
}
dirk@187
   307
dirk@187
   308
///////////////////////////////////////////////////////////////////////////////
dirk@187
   309
// Sync - ObjC part
dirk@187
   310
dirk@187
   311
static PEPQueue *syncQueue = nil;
dirk@187
   312
static NSThread *syncThread = nil;
dirk@187
   313
static NSConditionLock *syncThreadJoinCond = nil;
dirk@187
   314
static PEP_SESSION sync_session = NULL;
dirk@187
   315
static id <PEPSyncDelegate> syncDelegate = nil;
dirk@187
   316
dirk@187
   317
dirk@187
   318
+ (void)syncThreadRoutine:(id)object
dirk@187
   319
{
dirk@187
   320
    [syncThreadJoinCond lock];
dirk@187
   321
    
andreas@268
   322
    
edouard@195
   323
    PEP_STATUS status;
andreas@268
   324
    
dirk@187
   325
    status = do_sync_protocol(sync_session,
dirk@187
   326
                              /* "object" : notifying, sending (unused) */
dirk@187
   327
                              "NOTNULL");
dirk@187
   328
    
edouard@195
   329
    // TODO : log something if status not as expected
dirk@187
   330
    
dirk@187
   331
    
dirk@187
   332
    [syncThreadJoinCond unlockWithCondition:YES];
dirk@187
   333
}
dirk@187
   334
dirk@187
   335
+ (void)attachSyncSession:(PEP_SESSION)session
dirk@187
   336
{
dirk@187
   337
    if(sync_session)
dirk@187
   338
        attach_sync_session(session, sync_session);
dirk@187
   339
}
dirk@187
   340
dirk@187
   341
+ (void)detachSyncSession:(PEP_SESSION)session
dirk@187
   342
{
dirk@187
   343
    detach_sync_session(session);
dirk@187
   344
}
dirk@187
   345
dirk@187
   346
+ (void)startSync:(id <PEPSyncDelegate>)delegate;
dirk@187
   347
{
dirk@187
   348
    syncDelegate = delegate;
dirk@187
   349
    
dirk@187
   350
    if (!syncQueue)
dirk@187
   351
    {
dirk@187
   352
        syncQueue = [[PEPQueue alloc]init];
dirk@187
   353
        
dirk@187
   354
        syncThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
andreas@268
   355
        
dirk@254
   356
        [[PEPObjCAdapter initLock] lock];
edouard@195
   357
        PEP_STATUS status = init(&sync_session);
dirk@254
   358
        [[PEPObjCAdapter initLock] unlock];
edouard@195
   359
        if (status != PEP_STATUS_OK) {
edouard@195
   360
            return;
edouard@195
   361
        }
edouard@195
   362
        
edouard@195
   363
        register_sync_callbacks(sync_session,
edouard@195
   364
                                /* "management" : queuing (unused) */
edouard@195
   365
                                "NOTNULL",
edouard@195
   366
                                message_to_send,
edouard@195
   367
                                notify_handshake,
edouard@195
   368
                                inject_sync_msg,
edouard@195
   369
                                retrieve_next_sync_msg);
dirk@187
   370
        
dirk@187
   371
        syncThread = [[NSThread alloc]
dirk@187
   372
                      initWithTarget:self
dirk@187
   373
                      selector:@selector(syncThreadRoutine:)
dirk@187
   374
                      object:nil];
andreas@268
   375
        
dirk@187
   376
        [syncThread start];
dirk@187
   377
    }
andreas@268
   378
    
dirk@187
   379
    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
edouard@191
   380
    NSValue* v;
dirk@187
   381
    PEPSession* session;
dirk@187
   382
    @synchronized (sessionList) {
edouard@191
   383
        for (v in sessionList) {
edouard@191
   384
            session = [v nonretainedObjectValue];
dirk@187
   385
            [PEPObjCAdapter attachSyncSession:[session session]];
dirk@187
   386
        }
dirk@187
   387
    }
dirk@187
   388
}
dirk@187
   389
dirk@187
   390
+ (void)stopSync
dirk@187
   391
{
dirk@187
   392
    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
edouard@191
   393
    NSValue* v;
dirk@187
   394
    PEPSession* session;
dirk@187
   395
    @synchronized (sessionList) {
edouard@191
   396
        for (v in sessionList) {
edouard@191
   397
            session = [v nonretainedObjectValue];
dirk@187
   398
            [PEPObjCAdapter detachSyncSession:[session session]];
dirk@187
   399
        }
dirk@187
   400
    }
dirk@187
   401
    
dirk@187
   402
    syncDelegate = nil;
dirk@187
   403
    
dirk@187
   404
    if (syncQueue)
dirk@187
   405
    {
edouard@194
   406
        [syncQueue purge:^(id item){
edouard@194
   407
            sync_msg_t *msg = [item pointerValue];
edouard@194
   408
            free_sync_msg(msg);
edouard@194
   409
        }];
dirk@187
   410
        
dirk@187
   411
        [syncThreadJoinCond lockWhenCondition:YES];
dirk@187
   412
        [syncThreadJoinCond unlock];
andreas@268
   413
        
dirk@254
   414
        [[PEPObjCAdapter initLock] lock];
edouard@195
   415
        release(sync_session);
dirk@254
   416
        [[PEPObjCAdapter initLock] unlock];
dirk@187
   417
        
edouard@195
   418
        sync_session = NULL;
dirk@187
   419
        syncThread = nil;
dirk@187
   420
        syncQueue = nil;
dirk@187
   421
        syncThreadJoinCond = nil;
dirk@187
   422
    }
dirk@187
   423
}
dirk@187
   424
dirk@187
   425
+ (PEPQueue*)getSyncQueue
dirk@187
   426
{
dirk@187
   427
    return syncQueue;
dirk@187
   428
}
dirk@187
   429
dirk@187
   430
+ (id <PEPSyncDelegate>)getSyncDelegate
dirk@187
   431
{
dirk@187
   432
    return syncDelegate;
dirk@187
   433
}
dirk@187
   434
dirk@187
   435
+ (void)bindSession:(PEPSession*)session
dirk@187
   436
{
dirk@187
   437
    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
dirk@187
   438
    @synchronized (sessionList) {
edouard@191
   439
        [sessionList addObject:[NSValue valueWithNonretainedObject:session]];
dirk@187
   440
    }
andreas@268
   441
    
dirk@187
   442
    [PEPObjCAdapter registerExamineFunction:[session session]];
dirk@187
   443
    [PEPObjCAdapter attachSyncSession:[session session]];
dirk@187
   444
}
dirk@187
   445
dirk@187
   446
+ (void)unbindSession:(PEPSession*)session
dirk@187
   447
{
dirk@187
   448
    [PEPObjCAdapter detachSyncSession:[session session]];
dirk@187
   449
    
dirk@187
   450
    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
dirk@187
   451
    @synchronized (sessionList) {
edouard@191
   452
        [sessionList removeObject:[NSValue valueWithNonretainedObject:session]];
dirk@187
   453
    }
andreas@268
   454
    
andreas@268
   455
}
dirk@187
   456
andreas@268
   457
#pragma mark - PEPSession Public Methods - non static
andreas@268
   458
andreas@268
   459
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@268
   460
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@268
   461
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@268
   462
{
andreas@268
   463
    return [PEPObjCAdapter decryptMessageDict:src dest:(PEPDict * _Nullable * _Nullable)dst
andreas@268
   464
                                         keys:(PEPStringList * _Nullable * _Nullable)keys];
andreas@268
   465
}
andreas@268
   466
andreas@268
   467
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@268
   468
{
andreas@268
   469
    return [PEPObjCAdapter reEvaluateMessageRating:src];
andreas@268
   470
}
andreas@268
   471
andreas@268
   472
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@268
   473
                           extra:(nullable PEPStringList *)keys
andreas@268
   474
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@268
   475
{
andreas@268
   476
    return [PEPObjCAdapter encryptMessageDict:src extra:keys dest:dst];
andreas@268
   477
}
andreas@268
   478
andreas@268
   479
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@268
   480
                        identity:(nonnull PEPDict *)identity
andreas@268
   481
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@268
   482
{
andreas@268
   483
    return [PEPObjCAdapter encryptMessageDict:src identity:identity dest:dst];
andreas@268
   484
}
andreas@268
   485
andreas@268
   486
- (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
andreas@268
   487
{
andreas@268
   488
    return [PEPObjCAdapter outgoingMessageColor:msg];
andreas@268
   489
}
andreas@268
   490
andreas@268
   491
- (PEP_rating)identityRating:(nonnull PEPDict *)identity
andreas@268
   492
{
andreas@268
   493
    return [PEPObjCAdapter identityRating:identity];
andreas@268
   494
}
andreas@268
   495
andreas@268
   496
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@268
   497
                      shortened:(BOOL)shortened
andreas@268
   498
{
andreas@268
   499
    return [PEPObjCAdapter trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@268
   500
}
andreas@268
   501
andreas@268
   502
- (void)mySelf:(nonnull PEPMutableDict *)identity
andreas@268
   503
{
andreas@268
   504
    [PEPObjCAdapter mySelf:identity];
andreas@268
   505
}
andreas@268
   506
andreas@268
   507
- (void)updateIdentity:(nonnull PEPMutableDict *)identity
andreas@268
   508
{
andreas@268
   509
    [PEPObjCAdapter updateIdentity:identity];
andreas@268
   510
}
andreas@268
   511
andreas@268
   512
- (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
andreas@268
   513
{
andreas@268
   514
    [PEPObjCAdapter trustPersonalKey:identity];
andreas@268
   515
}
andreas@268
   516
andreas@268
   517
- (void)keyMistrusted:(nonnull PEPMutableDict *)identity
andreas@268
   518
{
andreas@268
   519
    [PEPObjCAdapter keyMistrusted:identity];
andreas@268
   520
}
andreas@268
   521
andreas@268
   522
- (void)keyResetTrust:(nonnull PEPMutableDict *)identity
andreas@268
   523
{
andreas@268
   524
    [PEPObjCAdapter keyResetTrust:identity];
andreas@268
   525
}
andreas@268
   526
andreas@268
   527
#pragma mark Internal API (testing etc.)
andreas@268
   528
andreas@268
   529
- (void)importKey:(nonnull NSString *)keydata
andreas@268
   530
{
andreas@268
   531
    [PEPObjCAdapter importKey:keydata];
andreas@268
   532
}
andreas@268
   533
andreas@268
   534
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@268
   535
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@268
   536
{
andreas@268
   537
    [PEPObjCAdapter logTitle:title entity:entity description:description comment:comment];
andreas@268
   538
}
andreas@268
   539
andreas@268
   540
- (nonnull NSString *)getLog
andreas@268
   541
{
andreas@268
   542
    return [PEPObjCAdapter getLog];
andreas@268
   543
}
andreas@268
   544
andreas@268
   545
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
andreas@268
   546
                                    identity2:(nonnull PEPDict *)identity2
andreas@268
   547
                                     language:(nullable NSString *)language
andreas@268
   548
                                         full:(BOOL)full
andreas@268
   549
{
andreas@268
   550
    return [PEPObjCAdapter getTrustwordsIdentity1:identity1
andreas@268
   551
                                        identity2:identity2
andreas@268
   552
                                         language:language
andreas@268
   553
                                             full:full];
andreas@268
   554
}
andreas@268
   555
andreas@268
   556
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
andreas@268
   557
                                   receiverDict:(nonnull PEPDict *)receiverDict
andreas@268
   558
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@268
   559
                                       language:(nullable NSString *)language
andreas@268
   560
                                           full:(BOOL)full
andreas@268
   561
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@268
   562
{
andreas@268
   563
    return [PEPObjCAdapter getTrustwordsMessageDict:messageDict
andreas@268
   564
                                       receiverDict:receiverDict
andreas@268
   565
                                          keysArray:keysArray
andreas@268
   566
                                           language:language
andreas@268
   567
                                               full:full
andreas@268
   568
                                    resultingStatus:resultingStatus];
andreas@268
   569
}
andreas@268
   570
andreas@268
   571
- (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@268
   572
{
andreas@268
   573
    return [PEPObjCAdapter languageList];
andreas@268
   574
}
andreas@268
   575
andreas@268
   576
- (PEP_STATUS)undoLastMistrust
andreas@268
   577
{
andreas@268
   578
    return [PEPObjCAdapter undoLastMistrust];
andreas@268
   579
}
andreas@268
   580
andreas@268
   581
#pragma mark - PEPSession Public Methods - static
andreas@268
   582
andreas@268
   583
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@268
   584
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@268
   585
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@268
   586
{
andreas@268
   587
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   588
    return [session decryptMessageDict:src dest:dst keys:keys];
andreas@268
   589
}
andreas@268
   590
andreas@268
   591
+ (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@268
   592
{
andreas@268
   593
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   594
    return [session reEvaluateMessageRating:src];
andreas@268
   595
}
andreas@268
   596
andreas@268
   597
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@268
   598
                           extra:(nullable PEPStringList *)keys
andreas@268
   599
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@268
   600
{
andreas@268
   601
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   602
    return [session encryptMessageDict:src extra:keys dest:dst];
andreas@268
   603
}
andreas@268
   604
andreas@268
   605
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@268
   606
                        identity:(nonnull PEPDict *)identity
andreas@268
   607
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@268
   608
{
andreas@268
   609
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   610
    return [session encryptMessageDict:src identity:identity dest:dst];
andreas@268
   611
}
andreas@268
   612
andreas@268
   613
+ (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
andreas@268
   614
{
andreas@268
   615
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   616
    return [session outgoingMessageColor:msg];
andreas@268
   617
}
andreas@268
   618
andreas@268
   619
+ (PEP_rating)identityRating:(nonnull PEPDict *)identity
andreas@268
   620
{
andreas@268
   621
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   622
    return [session identityRating:identity];
andreas@268
   623
}
andreas@268
   624
andreas@268
   625
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@268
   626
                      shortened:(BOOL)shortened
andreas@268
   627
{
andreas@268
   628
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   629
    return [session trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@268
   630
}
andreas@268
   631
andreas@268
   632
+ (void)mySelf:(nonnull PEPMutableDict *)identity
andreas@268
   633
{
andreas@268
   634
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   635
    [session mySelf:identity];
andreas@268
   636
}
andreas@268
   637
andreas@268
   638
+ (void)updateIdentity:(nonnull PEPMutableDict *)identity
andreas@268
   639
{
andreas@268
   640
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   641
    [session updateIdentity:identity];
andreas@268
   642
}
andreas@268
   643
andreas@268
   644
+ (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
andreas@268
   645
{
andreas@268
   646
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   647
    [session trustPersonalKey:identity];
andreas@268
   648
}
andreas@268
   649
andreas@268
   650
+ (void)keyMistrusted:(nonnull PEPMutableDict *)identity
andreas@268
   651
{
andreas@268
   652
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   653
    [session keyMistrusted:identity];
andreas@268
   654
}
andreas@268
   655
andreas@268
   656
+ (void)keyResetTrust:(nonnull PEPMutableDict *)identity
andreas@268
   657
{
andreas@268
   658
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   659
    [session keyResetTrust:identity];
andreas@268
   660
}
andreas@268
   661
andreas@268
   662
#pragma mark Internal API (testing etc.)
andreas@268
   663
andreas@268
   664
+ (void)importKey:(nonnull NSString *)keydata
andreas@268
   665
{
andreas@268
   666
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   667
    [session importKey:keydata];
andreas@268
   668
}
andreas@268
   669
andreas@268
   670
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@268
   671
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@268
   672
{
andreas@268
   673
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   674
    [session logTitle:title entity:entity description:description comment:comment];
andreas@268
   675
}
andreas@268
   676
andreas@268
   677
+ (nonnull NSString *)getLog
andreas@268
   678
{
andreas@268
   679
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   680
    return [session getLog];
andreas@268
   681
}
andreas@268
   682
andreas@268
   683
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
andreas@268
   684
                                    identity2:(nonnull PEPDict *)identity2
andreas@268
   685
                                     language:(nullable NSString *)language
andreas@268
   686
                                         full:(BOOL)full
andreas@268
   687
{
andreas@268
   688
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   689
    return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
andreas@268
   690
}
andreas@268
   691
andreas@268
   692
+ (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
andreas@268
   693
                                   receiverDict:(nonnull PEPDict *)receiverDict
andreas@268
   694
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@268
   695
                                       language:(nullable NSString *)language
andreas@268
   696
                                           full:(BOOL)full
andreas@268
   697
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@268
   698
{
andreas@268
   699
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   700
    return [session getTrustwordsMessageDict:messageDict receiverDict:receiverDict keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
andreas@268
   701
}
andreas@268
   702
andreas@268
   703
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@268
   704
{
andreas@268
   705
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   706
    return [session languageList];
andreas@268
   707
}
andreas@268
   708
andreas@268
   709
+ (PEP_STATUS)undoLastMistrust
andreas@268
   710
{
andreas@268
   711
    PEPSession *session = [PEPSessionProvider session];
andreas@268
   712
    return [session undoLastMistrust];
dirk@187
   713
}
dirk@187
   714
dirk@187
   715
@end