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