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