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