pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dz@pep.security>
Thu, 12 Sep 2019 16:41:52 +0200
branchIOSAD-141
changeset 1245 cd15ff3a40b9
parent 1190 3a53851cc0b9
child 1285 bca0bfd9cc7a
permissions -rw-r--r--
IOSAD-141 Don't share session between threads.
andreas@270
     1
//
andreas@270
     2
//  PEPSession.m
andreas@270
     3
//  pEpObjCAdapter
andreas@270
     4
//
andreas@270
     5
//  Created by Andreas Buff on 11.10.17.
andreas@270
     6
//  Copyright © 2017 p≡p. All rights reserved.
andreas@270
     7
//
andreas@270
     8
andreas@270
     9
#import "PEPSession.h"
andreas@270
    10
andreas@272
    11
#import "PEPInternalSession.h"
andreas@272
    12
#import "PEPSessionProvider.h"
dz@902
    13
#import "PEPIdentity.h"
andreas@272
    14
dz@841
    15
#import "PEPMessageUtil.h"
dz@841
    16
#import "NSNumber+PEPRating.h"
dz@1105
    17
#import "NSError+PEP+Internal.h"
dz@1111
    18
#import "PEPInternalConstants.h"
dz@841
    19
andreas@270
    20
@implementation PEPSession
andreas@270
    21
dz@1153
    22
/**
dz@1153
    23
 Macro for causing a return if the given session is nil, optionally setting an error.
dz@1153
    24
dz@1153
    25
 @param session A session object that will be checked for being nil or not.
dz@1153
    26
 @param error If non-nil, will receive PEP_UNKNOWN_ERROR when the session is nil.
dz@1153
    27
 @param what The value to return in case of an error (session is nil).
dz@1153
    28
 */
dz@1107
    29
#define RETURN_ON_ERROR(session, error, what)\
dz@1107
    30
  if (session == nil) { \
dz@1107
    31
    if (error != nil) { \
dz@1107
    32
      *error = [NSError errorWithPEPStatusInternal:PEP_UNKNOWN_ERROR]; \
dz@1107
    33
      return what; \
dz@1107
    34
    } \
dz@1107
    35
  }
dz@1105
    36
andreas@272
    37
#pragma mark - Public API
andreas@272
    38
dirk@291
    39
+ (void)cleanup
dirk@291
    40
{
dirk@291
    41
    [PEPSessionProvider cleanup];
dirk@291
    42
}
dirk@291
    43
dirk@596
    44
- (PEPDict * _Nullable)decryptMessageDict:(PEPMutableDict * _Nonnull)messageDict
dz@826
    45
                                    flags:(PEPDecryptFlags * _Nullable)flags
dz@826
    46
                                   rating:(PEPRating * _Nullable)rating
dirk@523
    47
                                extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
dz@826
    48
                                   status:(PEPStatus * _Nullable)status
dirk@517
    49
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
    50
{
dirk@519
    51
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
    52
    RETURN_ON_ERROR(session, error, nil);
dirk@524
    53
    return [session
dirk@524
    54
            decryptMessageDict:messageDict
dirk@583
    55
            flags:flags
dirk@524
    56
            rating:rating
dirk@524
    57
            extraKeys:extraKeys
dirk@524
    58
            status:status
dirk@524
    59
            error:error];
dirk@383
    60
}
dirk@383
    61
dirk@535
    62
- (PEPMessage * _Nullable)decryptMessage:(PEPMessage * _Nonnull)message
dz@826
    63
                                   flags:(PEPDecryptFlags * _Nullable)flags
dz@826
    64
                                  rating:(PEPRating * _Nullable)rating
dirk@523
    65
                               extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
dz@826
    66
                                  status:(PEPStatus * _Nullable)status
dirk@517
    67
                                   error:(NSError * _Nullable * _Nullable)error
dirk@383
    68
{
dirk@519
    69
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
    70
    RETURN_ON_ERROR(session, error, nil);
dirk@524
    71
    return [session
dirk@524
    72
            decryptMessage:message
dirk@583
    73
            flags:flags
dirk@524
    74
            rating:rating
dirk@524
    75
            extraKeys:extraKeys
dirk@524
    76
            status:status
dirk@524
    77
            error:error];
andreas@272
    78
}
andreas@272
    79
dirk@535
    80
- (BOOL)reEvaluateMessageDict:(PEPDict * _Nonnull)messageDict
dirk@634
    81
                     xKeyList:(PEPStringList * _Nullable)xKeyList
dz@826
    82
                       rating:(PEPRating * _Nonnull)rating
dz@826
    83
                       status:(PEPStatus * _Nullable)status
dirk@516
    84
                        error:(NSError * _Nullable * _Nullable)error
andreas@272
    85
{
dirk@519
    86
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
    87
    RETURN_ON_ERROR(session, error, NO);
dirk@634
    88
    return [session reEvaluateMessageDict:messageDict
dirk@634
    89
                                 xKeyList:xKeyList
dirk@634
    90
                                   rating:rating
dirk@634
    91
                                   status:status
dirk@634
    92
                                    error:error];
andreas@272
    93
}
andreas@272
    94
dirk@535
    95
- (BOOL)reEvaluateMessage:(PEPMessage * _Nonnull)message
dirk@634
    96
                 xKeyList:(PEPStringList * _Nullable)xKeyList
dz@826
    97
                   rating:(PEPRating * _Nonnull)rating
dz@826
    98
                   status:(PEPStatus * _Nullable)status
dirk@516
    99
                    error:(NSError * _Nullable * _Nullable)error
dirk@384
   100
{
dirk@519
   101
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   102
    RETURN_ON_ERROR(session, error, NO);
dirk@634
   103
    return [session reEvaluateMessage:message
dirk@634
   104
                             xKeyList:xKeyList
dirk@634
   105
                               rating:rating
dirk@634
   106
                               status:status
dirk@634
   107
                                error:error];
dirk@384
   108
}
dirk@384
   109
dirk@535
   110
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@535
   111
                                    extraKeys:(PEPStringList * _Nullable)extraKeys
dz@826
   112
                                encFormat:(PEPEncFormat)encFormat
dz@826
   113
                                   status:(PEPStatus * _Nullable)status
dirk@522
   114
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
   115
{
dirk@519
   116
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   117
    RETURN_ON_ERROR(session, error, nil);
dirk@523
   118
    return [session
dirk@523
   119
            encryptMessageDict:messageDict
dirk@523
   120
            extraKeys:extraKeys
dirk@523
   121
            encFormat:encFormat
dirk@524
   122
            status:status
dirk@523
   123
            error:error];
andreas@272
   124
}
andreas@272
   125
dirk@535
   126
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
   127
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dz@826
   128
                               encFormat:(PEPEncFormat)encFormat
dz@826
   129
                                  status:(PEPStatus * _Nullable)status
dirk@522
   130
                                   error:(NSError * _Nullable * _Nullable)error
dirk@379
   131
{
dirk@519
   132
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   133
    RETURN_ON_ERROR(session, error, nil);
dirk@524
   134
    return [session
dirk@524
   135
            encryptMessage:message
dirk@524
   136
            extraKeys:extraKeys
dirk@524
   137
            encFormat:encFormat
dirk@524
   138
            status:status
dirk@524
   139
            error:error];
dirk@379
   140
}
dirk@379
   141
dirk@535
   142
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
   143
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dz@826
   144
                                  status:(PEPStatus * _Nullable)status
dirk@522
   145
                                   error:(NSError * _Nullable * _Nullable)error
dirk@386
   146
{
dirk@519
   147
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   148
    RETURN_ON_ERROR(session, error, nil);
dirk@630
   149
    return [session encryptMessage:message extraKeys:extraKeys status:status error:error];
dirk@386
   150
}
dirk@386
   151
dirk@535
   152
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@557
   153
                                  forSelf:(PEPIdentity * _Nonnull)ownIdentity
dirk@556
   154
                                extraKeys:(PEPStringList * _Nullable)extraKeys
dz@826
   155
                                   status:(PEPStatus * _Nullable)status
dirk@526
   156
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
   157
{
dirk@519
   158
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   159
    RETURN_ON_ERROR(session, error, nil);
dirk@556
   160
    return [session
dirk@556
   161
            encryptMessageDict:messageDict
dirk@557
   162
            forSelf:ownIdentity
dirk@556
   163
            extraKeys:extraKeys
dirk@556
   164
            status:status
dirk@556
   165
            error:error];
andreas@272
   166
}
andreas@272
   167
dirk@535
   168
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@557
   169
                                 forSelf:(PEPIdentity * _Nonnull)ownIdentity
dirk@556
   170
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dz@826
   171
                                  status:(PEPStatus * _Nullable)status
dirk@526
   172
                                   error:(NSError * _Nullable * _Nullable)error
dirk@381
   173
{
dirk@519
   174
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   175
    RETURN_ON_ERROR(session, error, nil);
dirk@556
   176
    return [session
dirk@556
   177
            encryptMessage:message
dirk@557
   178
            forSelf:ownIdentity
dirk@556
   179
            extraKeys:extraKeys
dirk@556
   180
            status:status
dirk@556
   181
            error:error];
dirk@381
   182
}
dirk@381
   183
dirk@611
   184
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@611
   185
                                    toFpr:(NSString * _Nonnull)toFpr
dz@826
   186
                                encFormat:(PEPEncFormat)encFormat
dz@826
   187
                                    flags:(PEPDecryptFlags)flags
dz@826
   188
                                   status:(PEPStatus * _Nullable)status
dirk@611
   189
                                    error:(NSError * _Nullable * _Nullable)error __deprecated
dirk@611
   190
{
dirk@611
   191
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   192
    RETURN_ON_ERROR(session, error, nil);
dirk@611
   193
    return [session
dirk@611
   194
            encryptMessageDict:messageDict
dirk@611
   195
            toFpr:toFpr
dirk@611
   196
            encFormat:encFormat
dirk@611
   197
            flags:flags
dirk@611
   198
            status:status
dirk@611
   199
            error:error];
dirk@611
   200
}
dirk@611
   201
dirk@611
   202
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@611
   203
                                   toFpr:(NSString * _Nonnull)toFpr
dz@826
   204
                               encFormat:(PEPEncFormat)encFormat
dz@826
   205
                                   flags:(PEPDecryptFlags)flags
dz@826
   206
                                  status:(PEPStatus * _Nullable)status
dirk@611
   207
                                   error:(NSError * _Nullable * _Nullable)error
dirk@611
   208
{
dirk@611
   209
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   210
    RETURN_ON_ERROR(session, error, nil);
dirk@611
   211
    return [session
dirk@611
   212
            encryptMessage:message
dirk@611
   213
            toFpr:toFpr
dirk@611
   214
            encFormat:encFormat
dirk@611
   215
            flags:flags
dirk@611
   216
            status:status
dirk@611
   217
            error:error];
dirk@611
   218
}
dirk@611
   219
dirk@650
   220
- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
dirk@573
   221
                                           error:(NSError * _Nullable * _Nullable)error
dirk@377
   222
{
dirk@519
   223
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   224
    RETURN_ON_ERROR(session, error, nil);
dirk@650
   225
    return [session outgoingRatingForMessage:theMessage error:error];
dirk@377
   226
}
dirk@377
   227
dirk@652
   228
- (NSNumber * _Nullable)outgoingRatingPreviewForMessage:(PEPMessage * _Nonnull)theMessage
dirk@652
   229
                                                  error:(NSError * _Nullable * _Nullable)error
dirk@652
   230
{
dirk@652
   231
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   232
    RETURN_ON_ERROR(session, error, nil);
dirk@652
   233
    return [session outgoingRatingPreviewForMessage:theMessage error:error];
dirk@652
   234
}
dirk@652
   235
dirk@574
   236
- (NSNumber * _Nullable)ratingForIdentity:(PEPIdentity * _Nonnull)identity
dirk@574
   237
                                    error:(NSError * _Nullable * _Nullable)error
dirk@530
   238
{
dirk@519
   239
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   240
    RETURN_ON_ERROR(session, error, nil);
dirk@574
   241
    return [session ratingForIdentity:identity error:error];
andreas@272
   242
}
andreas@272
   243
dirk@531
   244
- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
dirk@531
   245
                                     languageID:(NSString * _Nonnull)languageID
dirk@531
   246
                                      shortened:(BOOL)shortened
dirk@531
   247
                                          error:(NSError * _Nullable * _Nullable)error
andreas@272
   248
{
dirk@519
   249
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   250
    RETURN_ON_ERROR(session, error, nil);
dirk@531
   251
    return [session
dirk@531
   252
            trustwordsForFingerprint:fingerprint
dirk@531
   253
            languageID:languageID
dirk@531
   254
            shortened:shortened
dirk@531
   255
            error:error];
andreas@272
   256
}
andreas@272
   257
dirk@535
   258
- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
andreas@272
   259
{
dirk@519
   260
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   261
    RETURN_ON_ERROR(session, error, NO);
dirk@532
   262
    return [session mySelf:identity error:error];
andreas@272
   263
}
andreas@272
   264
dirk@536
   265
- (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
dirk@536
   266
                 error:(NSError * _Nullable * _Nullable)error
andreas@272
   267
{
dirk@519
   268
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   269
    RETURN_ON_ERROR(session, error, NO);
dirk@532
   270
    return [session updateIdentity:identity error:error];
andreas@272
   271
}
andreas@272
   272
dirk@535
   273
- (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
dirk@534
   274
                   error:(NSError * _Nullable * _Nullable)error
andreas@272
   275
{
dirk@519
   276
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   277
    RETURN_ON_ERROR(session, error, NO);
dirk@534
   278
    return [session trustPersonalKey:identity error:error];
andreas@272
   279
}
andreas@272
   280
dirk@536
   281
- (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
dirk@536
   282
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   283
{
dirk@519
   284
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   285
    RETURN_ON_ERROR(session, error, NO);
dirk@536
   286
    return [session keyMistrusted:identity error:error];
andreas@272
   287
}
andreas@272
   288
dirk@545
   289
- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
dirk@545
   290
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   291
{
dirk@519
   292
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   293
    RETURN_ON_ERROR(session, error, NO);
dirk@545
   294
    return [session keyResetTrust:identity error:error];
andreas@272
   295
}
andreas@272
   296
dz@1181
   297
- (BOOL)enableSyncForIdentity:(PEPIdentity * _Nonnull)identity
dz@1181
   298
                        error:(NSError * _Nullable * _Nullable)error
dz@1181
   299
{
dz@1181
   300
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1181
   301
    RETURN_ON_ERROR(session, error, NO);
dz@1181
   302
    return [session enableSyncForIdentity:identity error:error];
dz@1181
   303
}
dz@1181
   304
dz@1186
   305
- (BOOL)disableSyncForIdentity:(PEPIdentity * _Nonnull)identity
dz@1186
   306
                         error:(NSError * _Nullable * _Nullable)error
dz@1186
   307
{
dz@1186
   308
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1186
   309
    RETURN_ON_ERROR(session, error, NO);
dz@1186
   310
    return [session disableSyncForIdentity:identity error:error];
dz@1186
   311
}
dz@1186
   312
dz@1190
   313
- (NSNumber * _Nullable)queryKeySyncEnabledForIdentity:(PEPIdentity * _Nonnull)identity
dz@1190
   314
                                                 error:(NSError * _Nullable * _Nullable)error
dz@1190
   315
{
dz@1190
   316
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1190
   317
    RETURN_ON_ERROR(session, error, nil);
dz@1190
   318
    return [session queryKeySyncEnabledForIdentity:identity error:error];
dz@1190
   319
}
dz@1190
   320
andreas@272
   321
#pragma mark Internal API (testing etc.)
andreas@272
   322
dirk@665
   323
- (NSArray * _Nullable)importKey:(NSString * _Nonnull)keydata
dirk@665
   324
                           error:(NSError * _Nullable * _Nullable)error
andreas@272
   325
{
dirk@551
   326
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   327
    RETURN_ON_ERROR(session, error, nil);
dirk@551
   328
    return [session importKey:keydata error:error];
andreas@272
   329
}
andreas@272
   330
dirk@553
   331
- (BOOL)logTitle:(NSString * _Nonnull)title
dirk@553
   332
          entity:(NSString * _Nonnull)entity
dirk@553
   333
     description:(NSString * _Nullable)description
dirk@553
   334
         comment:(NSString * _Nullable)comment
dirk@553
   335
           error:(NSError * _Nullable * _Nullable)error
andreas@272
   336
{
dirk@553
   337
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   338
    RETURN_ON_ERROR(session, error, NO);
dirk@553
   339
    return [session
dirk@553
   340
            logTitle:title
dirk@553
   341
            entity:entity
dirk@553
   342
            description:description
dirk@553
   343
            comment:comment
dirk@553
   344
            error:error];
andreas@272
   345
}
andreas@272
   346
dirk@552
   347
- (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   348
{
dirk@552
   349
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   350
    RETURN_ON_ERROR(session, error, nil);
dirk@552
   351
    return [session getLogWithError:error];
andreas@272
   352
}
andreas@272
   353
dirk@535
   354
- (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
dirk@535
   355
                                     identity2:(PEPIdentity * _Nonnull)identity2
dirk@535
   356
                                      language:(NSString * _Nullable)language
dirk@535
   357
                                          full:(BOOL)full
dirk@558
   358
                                         error:(NSError * _Nullable * _Nullable)error
andreas@272
   359
{
dirk@558
   360
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   361
    RETURN_ON_ERROR(session, error, nil);
dirk@558
   362
    return [session getTrustwordsIdentity1:identity1
dirk@558
   363
                                 identity2:identity2
dirk@558
   364
                                  language:language
dirk@558
   365
                                      full:full
dirk@558
   366
                                     error:error];
andreas@272
   367
}
andreas@272
   368
vb@986
   369
- (NSString * _Nullable)getTrustwordsFpr1:(NSString * _Nonnull)fpr1
vb@986
   370
                                     fpr2:(NSString * _Nonnull)fpr2
vb@986
   371
                                 language:(NSString * _Nullable)language
vb@986
   372
                                     full:(BOOL)full
vb@986
   373
                                    error:(NSError * _Nullable * _Nullable)error
vb@986
   374
{
vb@986
   375
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   376
    RETURN_ON_ERROR(session, error, nil);
vb@986
   377
    return [session getTrustwordsFpr1:fpr1 fpr2:fpr2 language:language full:full error:error];
vb@986
   378
}
vb@986
   379
dirk@560
   380
- (NSArray<PEPLanguage *> * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   381
{
dirk@560
   382
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   383
    RETURN_ON_ERROR(session, error, nil);
dirk@560
   384
    return [session languageListWithError:error];
andreas@272
   385
}
andreas@272
   386
dz@826
   387
- (PEPRating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   388
{
dirk@566
   389
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1109
   390
    if (session == nil) {
dz@1109
   391
        return PEPRatingUndefined;
dz@1109
   392
    }
dirk@566
   393
    return [session ratingFromString:string];
dirk@417
   394
}
dirk@417
   395
dz@826
   396
- (NSString * _Nonnull)stringFromRating:(PEPRating)rating
dirk@417
   397
{
dirk@566
   398
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1109
   399
    if (session == nil) {
dz@1111
   400
        return kUndefined;
dz@1109
   401
    }
dirk@566
   402
    return [session stringFromRating:rating];
dirk@417
   403
}
dirk@417
   404
dirk@567
   405
- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@567
   406
                            error:(NSError * _Nullable * _Nullable)error
dirk@427
   407
{
dirk@567
   408
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1107
   409
    RETURN_ON_ERROR(session, error, nil);
dirk@567
   410
    return [session isPEPUser:identity error:error];
dirk@427
   411
}
dirk@427
   412
dirk@501
   413
- (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   414
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   415
{
dirk@501
   416
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   417
    RETURN_ON_ERROR(session, error, NO);
dirk@501
   418
    return [session setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   419
}
dirk@501
   420
dirk@624
   421
- (void)configurePassiveModeEnabled:(BOOL)enabled
dirk@624
   422
{
dirk@624
   423
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@624
   424
    return [session configurePassiveModeEnabled:enabled];
dirk@624
   425
}
dirk@624
   426
dz@826
   427
- (BOOL)setFlags:(PEPIdentityFlags)flags
dirk@768
   428
     forIdentity:(PEPIdentity *)identity
dirk@768
   429
           error:(NSError * _Nullable * _Nullable)error
dirk@768
   430
{
dirk@768
   431
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   432
    RETURN_ON_ERROR(session, error, NO);
dirk@768
   433
    return [session setFlags:flags forIdentity:identity error:error];
dirk@768
   434
}
dirk@768
   435
dz@928
   436
- (BOOL)trustOwnKeyIdentity:(PEPIdentity * _Nonnull)identity
dz@775
   437
                      error:(NSError * _Nullable * _Nullable)error
dz@775
   438
{
dz@775
   439
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   440
    RETURN_ON_ERROR(session, error, NO);
dz@775
   441
    return [session trustOwnKeyIdentity:identity error:error];
dz@775
   442
}
dz@775
   443
dz@827
   444
- (BOOL)deliverHandshakeResult:(PEPSyncHandshakeResult)result
dz@913
   445
             identitiesSharing:(NSArray<PEPIdentity *> * _Nullable)identitiesSharing
dz@913
   446
                         error:(NSError * _Nullable * _Nullable)error;
dirk@773
   447
{
dirk@773
   448
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   449
    RETURN_ON_ERROR(session, error, NO);
dz@913
   450
    return [session deliverHandshakeResult:result identitiesSharing:identitiesSharing error:error];
dirk@773
   451
}
dirk@773
   452
dz@856
   453
- (PEPColor)colorFromRating:(PEPRating)rating
dz@856
   454
{
dz@856
   455
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1109
   456
    if (session == nil) {
dz@1112
   457
        return PEPColorNoColor;
dz@1109
   458
    }
dz@856
   459
    return [session colorFromRating:rating];
dz@856
   460
}
dz@856
   461
dz@931
   462
- (BOOL)keyReset:(PEPIdentity * _Nonnull)identity
dz@931
   463
     fingerprint:(NSString * _Nullable)fingerprint
dz@931
   464
           error:(NSError * _Nullable * _Nullable)error
dz@931
   465
{
dz@931
   466
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   467
    RETURN_ON_ERROR(session, error, NO);
dz@931
   468
    return [session keyReset:identity fingerprint:fingerprint error:error];
dz@931
   469
}
dz@931
   470
dz@1010
   471
- (BOOL)leaveDeviceGroupError:(NSError * _Nullable * _Nullable)error
dz@1010
   472
{
dz@1010
   473
    PEPInternalSession *session = [PEPSessionProvider session];
dz@1108
   474
    RETURN_ON_ERROR(session, error, NO);
dz@1010
   475
    return [session leaveDeviceGroupError:error];
dz@1010
   476
}
dz@1010
   477
andreas@270
   478
@end