pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Mon, 13 Nov 2017 16:37:09 +0100
changeset 383 449e60192dc2
parent 381 8732373ad930
child 384 09893e3cfd8e
permissions -rw-r--r--
IOSAD-63 decryptMessage:
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
andreas@272
    43
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
    44
                           extra:(nullable PEPStringList *)keys
andreas@272
    45
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    46
{
andreas@272
    47
    return [PEPSession encryptMessageDict:src extra:keys dest:dst];
andreas@272
    48
}
andreas@272
    49
dirk@379
    50
- (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@379
    51
                       extra:(nullable PEPStringList *)keys
dirk@379
    52
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@379
    53
{
dirk@379
    54
    return [PEPSession encryptMessage:src extra:keys dest:dst];
dirk@379
    55
}
dirk@379
    56
andreas@272
    57
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
dirk@363
    58
                        identity:(nonnull PEPIdentity *)identity
andreas@272
    59
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    60
{
andreas@272
    61
    return [PEPSession encryptMessageDict:src identity:identity dest:dst];
andreas@272
    62
}
andreas@272
    63
dirk@381
    64
- (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@381
    65
                    identity:(nonnull PEPIdentity *)identity
dirk@381
    66
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@381
    67
{
dirk@381
    68
    return [PEPSession encryptMessage:src identity:identity dest:dst];
dirk@381
    69
}
dirk@381
    70
dirk@377
    71
- (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
dirk@377
    72
{
dirk@377
    73
    return [PEPSession outgoingColorForMessage:message];
dirk@377
    74
}
dirk@377
    75
dirk@364
    76
- (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
andreas@272
    77
{
andreas@272
    78
    return [PEPSession identityRating:identity];
andreas@272
    79
}
andreas@272
    80
andreas@272
    81
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
    82
                      shortened:(BOOL)shortened
andreas@272
    83
{
andreas@272
    84
    return [PEPSession trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
    85
}
andreas@272
    86
dirk@348
    87
- (void)mySelf:(nonnull PEPIdentity *)identity
andreas@272
    88
{
andreas@272
    89
    [PEPSession mySelf:identity];
andreas@272
    90
}
andreas@272
    91
dirk@349
    92
- (void)updateIdentity:(nonnull PEPIdentity *)identity
andreas@272
    93
{
dirk@349
    94
    if (identity.isOwn) {
dirk@302
    95
        [PEPSession mySelf:identity];
dirk@302
    96
    } else {
dirk@302
    97
        [PEPSession updateIdentity:identity];
dirk@302
    98
    }
andreas@272
    99
}
andreas@272
   100
dirk@360
   101
- (void)trustPersonalKey:(nonnull PEPIdentity *)identity
andreas@272
   102
{
andreas@272
   103
    [PEPSession trustPersonalKey:identity];
andreas@272
   104
}
andreas@272
   105
dirk@361
   106
- (void)keyMistrusted:(nonnull PEPIdentity *)identity
andreas@272
   107
{
andreas@272
   108
    [PEPSession keyMistrusted:identity];
andreas@272
   109
}
andreas@272
   110
dirk@361
   111
- (void)keyResetTrust:(nonnull PEPIdentity *)identity
andreas@272
   112
{
andreas@272
   113
    [PEPSession keyResetTrust:identity];
andreas@272
   114
}
andreas@272
   115
andreas@272
   116
#pragma mark Internal API (testing etc.)
andreas@272
   117
andreas@272
   118
- (void)importKey:(nonnull NSString *)keydata
andreas@272
   119
{
andreas@272
   120
    [PEPSession importKey:keydata];
andreas@272
   121
}
andreas@272
   122
andreas@272
   123
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   124
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   125
{
andreas@272
   126
    [PEPSession logTitle:title entity:entity description:description comment:comment];
andreas@272
   127
}
andreas@272
   128
andreas@272
   129
- (nonnull NSString *)getLog
andreas@272
   130
{
andreas@272
   131
    return [PEPSession getLog];
andreas@272
   132
}
andreas@272
   133
dirk@365
   134
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
dirk@365
   135
                                    identity2:(nonnull PEPIdentity *)identity2
andreas@272
   136
                                     language:(nullable NSString *)language
andreas@272
   137
                                         full:(BOOL)full
andreas@272
   138
{
andreas@272
   139
    return [PEPSession getTrustwordsIdentity1:identity1
andreas@272
   140
                                        identity2:identity2
andreas@272
   141
                                         language:language
andreas@272
   142
                                             full:full];
andreas@272
   143
}
andreas@272
   144
andreas@272
   145
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
dirk@369
   146
                                   receiver:(nonnull PEPIdentity *)receiver
andreas@272
   147
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@272
   148
                                       language:(nullable NSString *)language
andreas@272
   149
                                           full:(BOOL)full
andreas@272
   150
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@272
   151
{
andreas@272
   152
    return [PEPSession getTrustwordsMessageDict:messageDict
dirk@366
   153
                                       receiver:receiver
andreas@272
   154
                                          keysArray:keysArray
andreas@272
   155
                                           language:language
andreas@272
   156
                                               full:full
andreas@272
   157
                                    resultingStatus:resultingStatus];
andreas@272
   158
}
andreas@272
   159
andreas@272
   160
- (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   161
{
andreas@272
   162
    return [PEPSession languageList];
andreas@272
   163
}
andreas@272
   164
andreas@272
   165
- (PEP_STATUS)undoLastMistrust
andreas@272
   166
{
andreas@272
   167
    return [PEPSession undoLastMistrust];
andreas@272
   168
}
andreas@272
   169
andreas@272
   170
#pragma mark - Static 
andreas@272
   171
andreas@272
   172
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@272
   173
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   174
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@272
   175
{
andreas@272
   176
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   177
    return [session decryptMessageDict:src dest:dst keys:keys];
andreas@272
   178
}
andreas@272
   179
dirk@383
   180
+ (PEP_rating)decryptMessage:(nonnull PEPMessage *)src
dirk@383
   181
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@383
   182
                        keys:(PEPStringList * _Nullable * _Nullable)keys
dirk@383
   183
{
dirk@383
   184
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@383
   185
    return [session decryptMessage:src dest:dst keys:keys];
dirk@383
   186
}
dirk@383
   187
andreas@272
   188
+ (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@272
   189
{
andreas@272
   190
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   191
    return [session reEvaluateMessageRating:src];
andreas@272
   192
}
andreas@272
   193
andreas@272
   194
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
   195
                           extra:(nullable PEPStringList *)keys
andreas@272
   196
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   197
{
andreas@272
   198
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   199
    return [session encryptMessageDict:src extra:keys dest:dst];
andreas@272
   200
}
andreas@272
   201
dirk@379
   202
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@379
   203
                           extra:(nullable PEPStringList *)keys
dirk@379
   204
                            dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@379
   205
{
dirk@379
   206
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@379
   207
    return [session encryptMessage:src extra:keys dest:dst];
dirk@379
   208
}
dirk@379
   209
andreas@272
   210
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
dirk@363
   211
                        identity:(nonnull PEPIdentity *)identity
andreas@272
   212
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   213
{
andreas@272
   214
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   215
    return [session encryptMessageDict:src identity:identity dest:dst];
andreas@272
   216
}
andreas@272
   217
dirk@381
   218
+ (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
dirk@381
   219
                    identity:(nonnull PEPIdentity *)identity
dirk@381
   220
                        dest:(PEPMessage * _Nullable * _Nullable)dst
dirk@381
   221
{
dirk@381
   222
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@381
   223
    return [session encryptMessage:src identity:identity dest:dst];
dirk@381
   224
}
dirk@381
   225
dirk@377
   226
+ (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
dirk@377
   227
{
dirk@377
   228
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@377
   229
    return [session outgoingColorForMessage:message];
dirk@377
   230
}
dirk@377
   231
dirk@364
   232
+ (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
andreas@272
   233
{
andreas@272
   234
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   235
    return [session identityRating:identity];
andreas@272
   236
}
andreas@272
   237
andreas@272
   238
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
   239
                      shortened:(BOOL)shortened
andreas@272
   240
{
andreas@272
   241
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   242
    return [session trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
   243
}
andreas@272
   244
dirk@348
   245
+ (void)mySelf:(nonnull PEPIdentity *)identity
andreas@272
   246
{
andreas@272
   247
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   248
    [session mySelf:identity];
andreas@272
   249
}
andreas@272
   250
dirk@349
   251
+ (void)updateIdentity:(nonnull PEPIdentity *)identity
andreas@272
   252
{
andreas@272
   253
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   254
    [session updateIdentity:identity];
andreas@272
   255
}
andreas@272
   256
dirk@360
   257
+ (void)trustPersonalKey:(nonnull PEPIdentity *)identity
andreas@272
   258
{
andreas@272
   259
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   260
    [session trustPersonalKey:identity];
andreas@272
   261
}
andreas@272
   262
dirk@361
   263
+ (void)keyMistrusted:(nonnull PEPIdentity *)identity
andreas@272
   264
{
andreas@272
   265
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   266
    [session keyMistrusted:identity];
andreas@272
   267
}
andreas@272
   268
dirk@361
   269
+ (void)keyResetTrust:(nonnull PEPIdentity *)identity
andreas@272
   270
{
andreas@272
   271
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   272
    [session keyResetTrust:identity];
andreas@272
   273
}
andreas@272
   274
andreas@272
   275
#pragma mark Internal API (testing etc.)
andreas@272
   276
andreas@272
   277
+ (void)importKey:(nonnull NSString *)keydata
andreas@272
   278
{
andreas@272
   279
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   280
    [session importKey:keydata];
andreas@272
   281
}
andreas@272
   282
andreas@272
   283
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   284
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   285
{
andreas@272
   286
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   287
    [session logTitle:title entity:entity description:description comment:comment];
andreas@272
   288
}
andreas@272
   289
andreas@272
   290
+ (nonnull NSString *)getLog
andreas@272
   291
{
andreas@272
   292
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   293
    return [session getLog];
andreas@272
   294
}
andreas@272
   295
dirk@365
   296
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
dirk@365
   297
                                    identity2:(nonnull PEPIdentity *)identity2
andreas@272
   298
                                     language:(nullable NSString *)language
andreas@272
   299
                                         full:(BOOL)full
andreas@272
   300
{
andreas@272
   301
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   302
    return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
andreas@272
   303
}
andreas@272
   304
andreas@272
   305
+ (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
dirk@366
   306
                                   receiver:(nonnull PEPIdentity *)receiver
andreas@272
   307
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@272
   308
                                       language:(nullable NSString *)language
andreas@272
   309
                                           full:(BOOL)full
andreas@272
   310
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@272
   311
{
andreas@272
   312
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@366
   313
    return [session getTrustwordsMessageDict:messageDict receiver:receiver keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
andreas@272
   314
}
andreas@272
   315
andreas@272
   316
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   317
{
andreas@272
   318
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   319
    return [session languageList];
andreas@272
   320
}
andreas@272
   321
andreas@272
   322
+ (PEP_STATUS)undoLastMistrust
andreas@272
   323
{
andreas@272
   324
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   325
    return [session undoLastMistrust];
andreas@272
   326
}
andreas@272
   327
andreas@270
   328
@end