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