pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Fri, 09 Feb 2018 08:29:59 +0100
changeset 427 256f5d977d4c
parent 417 595cf6bba6c5
child 430 800df6640c5b
permissions -rw-r--r--
ENGINE-365 dummy isPEPUser
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"
dirk@305
    13
#import "PEPIdentity.h"
andreas@272
    14
andreas@270
    15
@implementation PEPSession
andreas@270
    16
andreas@272
    17
#pragma mark - Public API
andreas@272
    18
dirk@291
    19
+ (void)cleanup
dirk@291
    20
{
dirk@291
    21
    [PEPSessionProvider cleanup];
dirk@291
    22
}
dirk@291
    23
andreas@272
    24
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@272
    25
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    26
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@272
    27
{
dirk@383
    28
    return [PEPSession decryptMessageDict:src dest:dst keys:keys];
dirk@383
    29
}
dirk@383
    30
dirk@383
    31
- (PEP_rating)decryptMessage:(nonnull PEPMessage *)src
dirk@383
    32
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@383
    33
                        keys:(PEPStringList * _Nullable * _Nullable)keys
dirk@383
    34
{
dirk@383
    35
    return [PEPSession decryptMessage:src dest:dst keys:keys];
andreas@272
    36
}
andreas@272
    37
andreas@272
    38
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@272
    39
{
andreas@272
    40
    return [PEPSession reEvaluateMessageRating:src];
andreas@272
    41
}
andreas@272
    42
dirk@384
    43
- (PEP_rating)reEvaluateRatingForMessage:(nonnull PEPMessage *)src
dirk@384
    44
{
dirk@384
    45
    return [PEPSession reEvaluateRatingForMessage:src];
dirk@384
    46
}
dirk@384
    47
andreas@272
    48
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
    49
                           extra:(nullable PEPStringList *)keys
dirk@386
    50
                       encFormat:(PEP_enc_format)encFormat
andreas@272
    51
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    52
{
dirk@386
    53
    return [PEPSession encryptMessageDict:src extra:keys encFormat:encFormat dest:dst];
andreas@272
    54
}
andreas@272
    55
dirk@379
    56
- (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@379
    57
                       extra:(nullable PEPStringList *)keys
dirk@379
    58
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@379
    59
{
dirk@379
    60
    return [PEPSession encryptMessage:src extra:keys dest:dst];
dirk@379
    61
}
dirk@379
    62
dirk@386
    63
- (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@386
    64
                       extra:(nullable PEPStringList *)keys
dirk@386
    65
                   encFormat:(PEP_enc_format)encFormat
dirk@386
    66
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@386
    67
{
dirk@386
    68
    return [PEPSession encryptMessage:src extra:keys encFormat:encFormat dest:dst];
dirk@386
    69
}
dirk@386
    70
andreas@272
    71
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
dirk@363
    72
                        identity:(nonnull PEPIdentity *)identity
andreas@272
    73
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    74
{
andreas@272
    75
    return [PEPSession encryptMessageDict:src identity:identity dest:dst];
andreas@272
    76
}
andreas@272
    77
dirk@381
    78
- (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@381
    79
                    identity:(nonnull PEPIdentity *)identity
dirk@381
    80
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@381
    81
{
dirk@381
    82
    return [PEPSession encryptMessage:src identity:identity dest:dst];
dirk@381
    83
}
dirk@381
    84
dirk@377
    85
- (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
dirk@377
    86
{
dirk@377
    87
    return [PEPSession outgoingColorForMessage:message];
dirk@377
    88
}
dirk@377
    89
dirk@364
    90
- (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
andreas@272
    91
{
andreas@272
    92
    return [PEPSession identityRating:identity];
andreas@272
    93
}
andreas@272
    94
andreas@272
    95
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
    96
                      shortened:(BOOL)shortened
andreas@272
    97
{
andreas@272
    98
    return [PEPSession trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
    99
}
andreas@272
   100
dirk@348
   101
- (void)mySelf:(nonnull PEPIdentity *)identity
andreas@272
   102
{
andreas@272
   103
    [PEPSession mySelf:identity];
andreas@272
   104
}
andreas@272
   105
dirk@349
   106
- (void)updateIdentity:(nonnull PEPIdentity *)identity
andreas@272
   107
{
dirk@349
   108
    if (identity.isOwn) {
dirk@302
   109
        [PEPSession mySelf:identity];
dirk@302
   110
    } else {
dirk@302
   111
        [PEPSession updateIdentity:identity];
dirk@302
   112
    }
andreas@272
   113
}
andreas@272
   114
dirk@360
   115
- (void)trustPersonalKey:(nonnull PEPIdentity *)identity
andreas@272
   116
{
andreas@272
   117
    [PEPSession trustPersonalKey:identity];
andreas@272
   118
}
andreas@272
   119
dirk@361
   120
- (void)keyMistrusted:(nonnull PEPIdentity *)identity
andreas@272
   121
{
andreas@272
   122
    [PEPSession keyMistrusted:identity];
andreas@272
   123
}
andreas@272
   124
dirk@361
   125
- (void)keyResetTrust:(nonnull PEPIdentity *)identity
andreas@272
   126
{
andreas@272
   127
    [PEPSession keyResetTrust:identity];
andreas@272
   128
}
andreas@272
   129
andreas@272
   130
#pragma mark Internal API (testing etc.)
andreas@272
   131
andreas@272
   132
- (void)importKey:(nonnull NSString *)keydata
andreas@272
   133
{
andreas@272
   134
    [PEPSession importKey:keydata];
andreas@272
   135
}
andreas@272
   136
andreas@272
   137
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   138
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   139
{
andreas@272
   140
    [PEPSession logTitle:title entity:entity description:description comment:comment];
andreas@272
   141
}
andreas@272
   142
andreas@272
   143
- (nonnull NSString *)getLog
andreas@272
   144
{
andreas@272
   145
    return [PEPSession getLog];
andreas@272
   146
}
andreas@272
   147
dirk@365
   148
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
dirk@365
   149
                                    identity2:(nonnull PEPIdentity *)identity2
andreas@272
   150
                                     language:(nullable NSString *)language
andreas@272
   151
                                         full:(BOOL)full
andreas@272
   152
{
andreas@272
   153
    return [PEPSession getTrustwordsIdentity1:identity1
andreas@272
   154
                                        identity2:identity2
andreas@272
   155
                                         language:language
andreas@272
   156
                                             full:full];
andreas@272
   157
}
andreas@272
   158
andreas@272
   159
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
dirk@369
   160
                                   receiver:(nonnull PEPIdentity *)receiver
andreas@272
   161
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@272
   162
                                       language:(nullable NSString *)language
andreas@272
   163
                                           full:(BOOL)full
andreas@272
   164
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@272
   165
{
andreas@272
   166
    return [PEPSession getTrustwordsMessageDict:messageDict
dirk@366
   167
                                       receiver:receiver
andreas@272
   168
                                          keysArray:keysArray
andreas@272
   169
                                           language:language
andreas@272
   170
                                               full:full
andreas@272
   171
                                    resultingStatus:resultingStatus];
andreas@272
   172
}
andreas@272
   173
dirk@385
   174
- (nullable NSString *)getTrustwordsForMessage:(nonnull PEPMessage *)message
dirk@385
   175
                                      receiver:(nonnull PEPIdentity *)receiver
dirk@385
   176
                                     keysArray:(PEPStringList * _Nullable)keysArray
dirk@385
   177
                                      language:(nullable NSString *)language
dirk@385
   178
                                          full:(BOOL)full
dirk@385
   179
                               resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
dirk@385
   180
{
dirk@385
   181
    return [PEPSession getTrustwordsForMessage:message
dirk@385
   182
                                      receiver:receiver
dirk@385
   183
                                     keysArray:keysArray
dirk@385
   184
                                      language:language
dirk@385
   185
                                          full:full
dirk@385
   186
                               resultingStatus:resultingStatus];
dirk@385
   187
}
dirk@385
   188
andreas@272
   189
- (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   190
{
andreas@272
   191
    return [PEPSession languageList];
andreas@272
   192
}
andreas@272
   193
andreas@272
   194
- (PEP_STATUS)undoLastMistrust
andreas@272
   195
{
andreas@272
   196
    return [PEPSession undoLastMistrust];
andreas@272
   197
}
andreas@272
   198
dirk@417
   199
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   200
{
dirk@417
   201
    return [PEPSession ratingFromString:string];
dirk@417
   202
}
dirk@417
   203
dirk@417
   204
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   205
{
dirk@417
   206
    return [PEPSession stringFromRating:rating];
dirk@417
   207
}
dirk@417
   208
dirk@427
   209
- (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@427
   210
{
dirk@427
   211
    return [PEPSession isPEPUser:identity];
dirk@427
   212
}
dirk@427
   213
dirk@417
   214
#pragma mark - Static
andreas@272
   215
andreas@272
   216
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@272
   217
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   218
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@272
   219
{
andreas@272
   220
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   221
    return [session decryptMessageDict:src dest:dst keys:keys];
andreas@272
   222
}
andreas@272
   223
dirk@383
   224
+ (PEP_rating)decryptMessage:(nonnull PEPMessage *)src
dirk@383
   225
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@383
   226
                        keys:(PEPStringList * _Nullable * _Nullable)keys
dirk@383
   227
{
dirk@383
   228
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@383
   229
    return [session decryptMessage:src dest:dst keys:keys];
dirk@383
   230
}
dirk@383
   231
andreas@272
   232
+ (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@272
   233
{
andreas@272
   234
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   235
    return [session reEvaluateMessageRating:src];
andreas@272
   236
}
andreas@272
   237
dirk@384
   238
+ (PEP_rating)reEvaluateRatingForMessage:(nonnull PEPMessage *)src
dirk@384
   239
{
dirk@384
   240
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@384
   241
    return [session reEvaluateRatingForMessage:src];
dirk@384
   242
}
dirk@384
   243
andreas@272
   244
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
   245
                           extra:(nullable PEPStringList *)keys
dirk@386
   246
                       encFormat:(PEP_enc_format)encFormat
andreas@272
   247
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   248
{
andreas@272
   249
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@386
   250
    return [session encryptMessageDict:src extra:keys encFormat:encFormat dest:dst];
andreas@272
   251
}
andreas@272
   252
dirk@379
   253
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@379
   254
                           extra:(nullable PEPStringList *)keys
dirk@379
   255
                            dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@379
   256
{
dirk@379
   257
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@379
   258
    return [session encryptMessage:src extra:keys dest:dst];
dirk@379
   259
}
dirk@379
   260
dirk@386
   261
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@386
   262
                       extra:(nullable PEPStringList *)keys
dirk@386
   263
                   encFormat:(PEP_enc_format)encFormat
dirk@386
   264
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@386
   265
{
dirk@386
   266
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@386
   267
    return [session encryptMessage:src extra:keys encFormat:encFormat dest:dst];
dirk@386
   268
}
dirk@386
   269
andreas@272
   270
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
dirk@363
   271
                        identity:(nonnull PEPIdentity *)identity
andreas@272
   272
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   273
{
andreas@272
   274
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   275
    return [session encryptMessageDict:src identity:identity dest:dst];
andreas@272
   276
}
andreas@272
   277
dirk@381
   278
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@381
   279
                    identity:(nonnull PEPIdentity *)identity
dirk@381
   280
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@381
   281
{
dirk@381
   282
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@381
   283
    return [session encryptMessage:src identity:identity dest:dst];
dirk@381
   284
}
dirk@381
   285
dirk@377
   286
+ (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
dirk@377
   287
{
dirk@377
   288
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@377
   289
    return [session outgoingColorForMessage:message];
dirk@377
   290
}
dirk@377
   291
dirk@364
   292
+ (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
andreas@272
   293
{
andreas@272
   294
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   295
    return [session identityRating:identity];
andreas@272
   296
}
andreas@272
   297
andreas@272
   298
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
   299
                      shortened:(BOOL)shortened
andreas@272
   300
{
andreas@272
   301
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   302
    return [session trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
   303
}
andreas@272
   304
dirk@348
   305
+ (void)mySelf:(nonnull PEPIdentity *)identity
andreas@272
   306
{
andreas@272
   307
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   308
    [session mySelf:identity];
andreas@272
   309
}
andreas@272
   310
dirk@349
   311
+ (void)updateIdentity:(nonnull PEPIdentity *)identity
andreas@272
   312
{
andreas@272
   313
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   314
    [session updateIdentity:identity];
andreas@272
   315
}
andreas@272
   316
dirk@360
   317
+ (void)trustPersonalKey:(nonnull PEPIdentity *)identity
andreas@272
   318
{
andreas@272
   319
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   320
    [session trustPersonalKey:identity];
andreas@272
   321
}
andreas@272
   322
dirk@361
   323
+ (void)keyMistrusted:(nonnull PEPIdentity *)identity
andreas@272
   324
{
andreas@272
   325
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   326
    [session keyMistrusted:identity];
andreas@272
   327
}
andreas@272
   328
dirk@361
   329
+ (void)keyResetTrust:(nonnull PEPIdentity *)identity
andreas@272
   330
{
andreas@272
   331
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   332
    [session keyResetTrust:identity];
andreas@272
   333
}
andreas@272
   334
andreas@272
   335
#pragma mark Internal API (testing etc.)
andreas@272
   336
andreas@272
   337
+ (void)importKey:(nonnull NSString *)keydata
andreas@272
   338
{
andreas@272
   339
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   340
    [session importKey:keydata];
andreas@272
   341
}
andreas@272
   342
andreas@272
   343
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   344
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   345
{
andreas@272
   346
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   347
    [session logTitle:title entity:entity description:description comment:comment];
andreas@272
   348
}
andreas@272
   349
andreas@272
   350
+ (nonnull NSString *)getLog
andreas@272
   351
{
andreas@272
   352
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   353
    return [session getLog];
andreas@272
   354
}
andreas@272
   355
dirk@365
   356
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
dirk@365
   357
                                    identity2:(nonnull PEPIdentity *)identity2
andreas@272
   358
                                     language:(nullable NSString *)language
andreas@272
   359
                                         full:(BOOL)full
andreas@272
   360
{
andreas@272
   361
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   362
    return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
andreas@272
   363
}
andreas@272
   364
andreas@272
   365
+ (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
dirk@366
   366
                                   receiver:(nonnull PEPIdentity *)receiver
andreas@272
   367
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@272
   368
                                       language:(nullable NSString *)language
andreas@272
   369
                                           full:(BOOL)full
andreas@272
   370
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@272
   371
{
andreas@272
   372
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@366
   373
    return [session getTrustwordsMessageDict:messageDict receiver:receiver keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
andreas@272
   374
}
andreas@272
   375
dirk@385
   376
+ (nullable NSString *)getTrustwordsForMessage:(nonnull PEPMessage *)message
dirk@385
   377
                                      receiver:(nonnull PEPIdentity *)receiver
dirk@385
   378
                                     keysArray:(PEPStringList * _Nullable)keysArray
dirk@385
   379
                                      language:(nullable NSString *)language
dirk@385
   380
                                          full:(BOOL)full
dirk@385
   381
                               resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
dirk@385
   382
{
dirk@385
   383
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@385
   384
    return [session getTrustwordsForMessage:message receiver:receiver keysArray:keysArray
dirk@385
   385
                                   language:language full:full resultingStatus:resultingStatus];
dirk@385
   386
}
dirk@385
   387
andreas@272
   388
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   389
{
andreas@272
   390
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   391
    return [session languageList];
andreas@272
   392
}
andreas@272
   393
andreas@272
   394
+ (PEP_STATUS)undoLastMistrust
andreas@272
   395
{
andreas@272
   396
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   397
    return [session undoLastMistrust];
andreas@272
   398
}
andreas@272
   399
dirk@417
   400
+ (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   401
{
dirk@417
   402
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@417
   403
    return [session ratingFromString:string];
dirk@417
   404
}
dirk@417
   405
dirk@417
   406
+ (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   407
{
dirk@417
   408
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@417
   409
    return [session stringFromRating:rating];
dirk@417
   410
}
dirk@417
   411
dirk@427
   412
+ (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@427
   413
{
dirk@427
   414
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@427
   415
    return [session isPEPUser:identity];
dirk@427
   416
}
dirk@427
   417
andreas@270
   418
@end