pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Fri, 02 Feb 2018 13:13:59 +0100
changeset 417 595cf6bba6c5
parent 386 34b3d14a4994
child 427 256f5d977d4c
permissions -rw-r--r--
IOSAD-73 ratingFromString:, stringFromRating:
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@417
   209
#pragma mark - Static
andreas@272
   210
andreas@272
   211
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@272
   212
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   213
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@272
   214
{
andreas@272
   215
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   216
    return [session decryptMessageDict:src dest:dst keys:keys];
andreas@272
   217
}
andreas@272
   218
dirk@383
   219
+ (PEP_rating)decryptMessage:(nonnull PEPMessage *)src
dirk@383
   220
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@383
   221
                        keys:(PEPStringList * _Nullable * _Nullable)keys
dirk@383
   222
{
dirk@383
   223
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@383
   224
    return [session decryptMessage:src dest:dst keys:keys];
dirk@383
   225
}
dirk@383
   226
andreas@272
   227
+ (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@272
   228
{
andreas@272
   229
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   230
    return [session reEvaluateMessageRating:src];
andreas@272
   231
}
andreas@272
   232
dirk@384
   233
+ (PEP_rating)reEvaluateRatingForMessage:(nonnull PEPMessage *)src
dirk@384
   234
{
dirk@384
   235
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@384
   236
    return [session reEvaluateRatingForMessage:src];
dirk@384
   237
}
dirk@384
   238
andreas@272
   239
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
   240
                           extra:(nullable PEPStringList *)keys
dirk@386
   241
                       encFormat:(PEP_enc_format)encFormat
andreas@272
   242
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   243
{
andreas@272
   244
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@386
   245
    return [session encryptMessageDict:src extra:keys encFormat:encFormat dest:dst];
andreas@272
   246
}
andreas@272
   247
dirk@379
   248
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@379
   249
                           extra:(nullable PEPStringList *)keys
dirk@379
   250
                            dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@379
   251
{
dirk@379
   252
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@379
   253
    return [session encryptMessage:src extra:keys dest:dst];
dirk@379
   254
}
dirk@379
   255
dirk@386
   256
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@386
   257
                       extra:(nullable PEPStringList *)keys
dirk@386
   258
                   encFormat:(PEP_enc_format)encFormat
dirk@386
   259
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@386
   260
{
dirk@386
   261
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@386
   262
    return [session encryptMessage:src extra:keys encFormat:encFormat dest:dst];
dirk@386
   263
}
dirk@386
   264
andreas@272
   265
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
dirk@363
   266
                        identity:(nonnull PEPIdentity *)identity
andreas@272
   267
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   268
{
andreas@272
   269
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   270
    return [session encryptMessageDict:src identity:identity dest:dst];
andreas@272
   271
}
andreas@272
   272
dirk@381
   273
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@381
   274
                    identity:(nonnull PEPIdentity *)identity
dirk@381
   275
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@381
   276
{
dirk@381
   277
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@381
   278
    return [session encryptMessage:src identity:identity dest:dst];
dirk@381
   279
}
dirk@381
   280
dirk@377
   281
+ (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
dirk@377
   282
{
dirk@377
   283
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@377
   284
    return [session outgoingColorForMessage:message];
dirk@377
   285
}
dirk@377
   286
dirk@364
   287
+ (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
andreas@272
   288
{
andreas@272
   289
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   290
    return [session identityRating:identity];
andreas@272
   291
}
andreas@272
   292
andreas@272
   293
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
   294
                      shortened:(BOOL)shortened
andreas@272
   295
{
andreas@272
   296
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   297
    return [session trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
   298
}
andreas@272
   299
dirk@348
   300
+ (void)mySelf:(nonnull PEPIdentity *)identity
andreas@272
   301
{
andreas@272
   302
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   303
    [session mySelf:identity];
andreas@272
   304
}
andreas@272
   305
dirk@349
   306
+ (void)updateIdentity:(nonnull PEPIdentity *)identity
andreas@272
   307
{
andreas@272
   308
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   309
    [session updateIdentity:identity];
andreas@272
   310
}
andreas@272
   311
dirk@360
   312
+ (void)trustPersonalKey:(nonnull PEPIdentity *)identity
andreas@272
   313
{
andreas@272
   314
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   315
    [session trustPersonalKey:identity];
andreas@272
   316
}
andreas@272
   317
dirk@361
   318
+ (void)keyMistrusted:(nonnull PEPIdentity *)identity
andreas@272
   319
{
andreas@272
   320
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   321
    [session keyMistrusted:identity];
andreas@272
   322
}
andreas@272
   323
dirk@361
   324
+ (void)keyResetTrust:(nonnull PEPIdentity *)identity
andreas@272
   325
{
andreas@272
   326
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   327
    [session keyResetTrust:identity];
andreas@272
   328
}
andreas@272
   329
andreas@272
   330
#pragma mark Internal API (testing etc.)
andreas@272
   331
andreas@272
   332
+ (void)importKey:(nonnull NSString *)keydata
andreas@272
   333
{
andreas@272
   334
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   335
    [session importKey:keydata];
andreas@272
   336
}
andreas@272
   337
andreas@272
   338
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   339
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   340
{
andreas@272
   341
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   342
    [session logTitle:title entity:entity description:description comment:comment];
andreas@272
   343
}
andreas@272
   344
andreas@272
   345
+ (nonnull NSString *)getLog
andreas@272
   346
{
andreas@272
   347
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   348
    return [session getLog];
andreas@272
   349
}
andreas@272
   350
dirk@365
   351
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
dirk@365
   352
                                    identity2:(nonnull PEPIdentity *)identity2
andreas@272
   353
                                     language:(nullable NSString *)language
andreas@272
   354
                                         full:(BOOL)full
andreas@272
   355
{
andreas@272
   356
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   357
    return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
andreas@272
   358
}
andreas@272
   359
andreas@272
   360
+ (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
dirk@366
   361
                                   receiver:(nonnull PEPIdentity *)receiver
andreas@272
   362
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@272
   363
                                       language:(nullable NSString *)language
andreas@272
   364
                                           full:(BOOL)full
andreas@272
   365
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@272
   366
{
andreas@272
   367
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@366
   368
    return [session getTrustwordsMessageDict:messageDict receiver:receiver keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
andreas@272
   369
}
andreas@272
   370
dirk@385
   371
+ (nullable NSString *)getTrustwordsForMessage:(nonnull PEPMessage *)message
dirk@385
   372
                                      receiver:(nonnull PEPIdentity *)receiver
dirk@385
   373
                                     keysArray:(PEPStringList * _Nullable)keysArray
dirk@385
   374
                                      language:(nullable NSString *)language
dirk@385
   375
                                          full:(BOOL)full
dirk@385
   376
                               resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
dirk@385
   377
{
dirk@385
   378
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@385
   379
    return [session getTrustwordsForMessage:message receiver:receiver keysArray:keysArray
dirk@385
   380
                                   language:language full:full resultingStatus:resultingStatus];
dirk@385
   381
}
dirk@385
   382
andreas@272
   383
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   384
{
andreas@272
   385
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   386
    return [session languageList];
andreas@272
   387
}
andreas@272
   388
andreas@272
   389
+ (PEP_STATUS)undoLastMistrust
andreas@272
   390
{
andreas@272
   391
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   392
    return [session undoLastMistrust];
andreas@272
   393
}
andreas@272
   394
dirk@417
   395
+ (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   396
{
dirk@417
   397
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@417
   398
    return [session ratingFromString:string];
dirk@417
   399
}
dirk@417
   400
dirk@417
   401
+ (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   402
{
dirk@417
   403
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@417
   404
    return [session stringFromRating:rating];
dirk@417
   405
}
dirk@417
   406
andreas@270
   407
@end