pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Sat, 24 Feb 2018 18:50:45 +0100
changeset 501 739ae7e9693b
parent 480 f6c27f067389
child 514 1401bf4dd539
permissions -rw-r--r--
IOSAD-82 set_own_key
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
dirk@475
   143
- (nullable 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
- (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   160
{
andreas@272
   161
    return [PEPSession languageList];
andreas@272
   162
}
andreas@272
   163
andreas@272
   164
- (PEP_STATUS)undoLastMistrust
andreas@272
   165
{
andreas@272
   166
    return [PEPSession undoLastMistrust];
andreas@272
   167
}
andreas@272
   168
dirk@417
   169
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   170
{
dirk@417
   171
    return [PEPSession ratingFromString:string];
dirk@417
   172
}
dirk@417
   173
dirk@417
   174
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   175
{
dirk@417
   176
    return [PEPSession stringFromRating:rating];
dirk@417
   177
}
dirk@417
   178
dirk@453
   179
- (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@427
   180
{
dirk@453
   181
    return [PEPSession isPEPUser:identity];
dirk@427
   182
}
dirk@427
   183
dirk@501
   184
- (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   185
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   186
{
dirk@501
   187
    return [PEPSession setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   188
}
dirk@501
   189
dirk@417
   190
#pragma mark - Static
andreas@272
   191
andreas@272
   192
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@272
   193
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   194
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@272
   195
{
andreas@272
   196
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   197
    return [session decryptMessageDict:src dest:dst keys:keys];
andreas@272
   198
}
andreas@272
   199
dirk@383
   200
+ (PEP_rating)decryptMessage:(nonnull PEPMessage *)src
dirk@383
   201
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@383
   202
                        keys:(PEPStringList * _Nullable * _Nullable)keys
dirk@383
   203
{
dirk@383
   204
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@383
   205
    return [session decryptMessage:src dest:dst keys:keys];
dirk@383
   206
}
dirk@383
   207
andreas@272
   208
+ (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@272
   209
{
andreas@272
   210
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   211
    return [session reEvaluateMessageRating:src];
andreas@272
   212
}
andreas@272
   213
dirk@384
   214
+ (PEP_rating)reEvaluateRatingForMessage:(nonnull PEPMessage *)src
dirk@384
   215
{
dirk@384
   216
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@384
   217
    return [session reEvaluateRatingForMessage:src];
dirk@384
   218
}
dirk@384
   219
andreas@272
   220
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
   221
                           extra:(nullable PEPStringList *)keys
dirk@386
   222
                       encFormat:(PEP_enc_format)encFormat
andreas@272
   223
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   224
{
andreas@272
   225
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@386
   226
    return [session encryptMessageDict:src extra:keys encFormat:encFormat dest:dst];
andreas@272
   227
}
andreas@272
   228
dirk@379
   229
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@379
   230
                           extra:(nullable PEPStringList *)keys
dirk@379
   231
                            dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@379
   232
{
dirk@379
   233
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@379
   234
    return [session encryptMessage:src extra:keys dest:dst];
dirk@379
   235
}
dirk@379
   236
dirk@386
   237
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@386
   238
                       extra:(nullable PEPStringList *)keys
dirk@386
   239
                   encFormat:(PEP_enc_format)encFormat
dirk@386
   240
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@386
   241
{
dirk@386
   242
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@386
   243
    return [session encryptMessage:src extra:keys encFormat:encFormat dest:dst];
dirk@386
   244
}
dirk@386
   245
andreas@272
   246
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
dirk@363
   247
                        identity:(nonnull PEPIdentity *)identity
andreas@272
   248
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   249
{
andreas@272
   250
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   251
    return [session encryptMessageDict:src identity:identity dest:dst];
andreas@272
   252
}
andreas@272
   253
dirk@381
   254
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@381
   255
                    identity:(nonnull PEPIdentity *)identity
dirk@381
   256
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@381
   257
{
dirk@381
   258
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@381
   259
    return [session encryptMessage:src identity:identity dest:dst];
dirk@381
   260
}
dirk@381
   261
dirk@377
   262
+ (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
dirk@377
   263
{
dirk@377
   264
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@377
   265
    return [session outgoingColorForMessage:message];
dirk@377
   266
}
dirk@377
   267
dirk@364
   268
+ (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
andreas@272
   269
{
andreas@272
   270
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   271
    return [session identityRating:identity];
andreas@272
   272
}
andreas@272
   273
andreas@272
   274
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
   275
                      shortened:(BOOL)shortened
andreas@272
   276
{
andreas@272
   277
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   278
    return [session trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
   279
}
andreas@272
   280
dirk@348
   281
+ (void)mySelf:(nonnull PEPIdentity *)identity
andreas@272
   282
{
andreas@272
   283
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   284
    [session mySelf:identity];
andreas@272
   285
}
andreas@272
   286
dirk@349
   287
+ (void)updateIdentity:(nonnull PEPIdentity *)identity
andreas@272
   288
{
andreas@272
   289
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   290
    [session updateIdentity:identity];
andreas@272
   291
}
andreas@272
   292
dirk@360
   293
+ (void)trustPersonalKey:(nonnull PEPIdentity *)identity
andreas@272
   294
{
andreas@272
   295
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   296
    [session trustPersonalKey:identity];
andreas@272
   297
}
andreas@272
   298
dirk@361
   299
+ (void)keyMistrusted:(nonnull PEPIdentity *)identity
andreas@272
   300
{
andreas@272
   301
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   302
    [session keyMistrusted:identity];
andreas@272
   303
}
andreas@272
   304
dirk@361
   305
+ (void)keyResetTrust:(nonnull PEPIdentity *)identity
andreas@272
   306
{
andreas@272
   307
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   308
    [session keyResetTrust:identity];
andreas@272
   309
}
andreas@272
   310
andreas@272
   311
#pragma mark Internal API (testing etc.)
andreas@272
   312
andreas@272
   313
+ (void)importKey:(nonnull NSString *)keydata
andreas@272
   314
{
andreas@272
   315
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   316
    [session importKey:keydata];
andreas@272
   317
}
andreas@272
   318
andreas@272
   319
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   320
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   321
{
andreas@272
   322
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   323
    [session logTitle:title entity:entity description:description comment:comment];
andreas@272
   324
}
andreas@272
   325
dirk@475
   326
+ (nullable NSString *)getLog
andreas@272
   327
{
andreas@272
   328
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   329
    return [session getLog];
andreas@272
   330
}
andreas@272
   331
dirk@365
   332
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
dirk@365
   333
                                    identity2:(nonnull PEPIdentity *)identity2
andreas@272
   334
                                     language:(nullable NSString *)language
andreas@272
   335
                                         full:(BOOL)full
andreas@272
   336
{
andreas@272
   337
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   338
    return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
andreas@272
   339
}
andreas@272
   340
andreas@272
   341
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   342
{
andreas@272
   343
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   344
    return [session languageList];
andreas@272
   345
}
andreas@272
   346
andreas@272
   347
+ (PEP_STATUS)undoLastMistrust
andreas@272
   348
{
andreas@272
   349
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   350
    return [session undoLastMistrust];
andreas@272
   351
}
andreas@272
   352
dirk@417
   353
+ (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   354
{
dirk@417
   355
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@417
   356
    return [session ratingFromString:string];
dirk@417
   357
}
dirk@417
   358
dirk@417
   359
+ (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   360
{
dirk@417
   361
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@417
   362
    return [session stringFromRating:rating];
dirk@417
   363
}
dirk@417
   364
dirk@453
   365
+ (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
dirk@427
   366
{
dirk@427
   367
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@453
   368
    return [session isPEPUser:identity];
dirk@427
   369
}
dirk@427
   370
dirk@501
   371
+ (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   372
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   373
{
dirk@501
   374
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@501
   375
    return [session setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   376
}
dirk@501
   377
andreas@270
   378
@end