pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Fri, 20 Oct 2017 14:53:31 +0200
changeset 291 1d64f8889d2c
parent 289 bbe4e8da3568
child 294 fff0d71fe385
permissions -rw-r--r--
IOS-766 PEPSession.cleanup now static
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"
andreas@272
    13
andreas@270
    14
@implementation PEPSession
andreas@270
    15
andreas@272
    16
#pragma mark - Public API
andreas@272
    17
dirk@291
    18
+ (void)cleanup
dirk@291
    19
{
dirk@291
    20
    [PEPSessionProvider cleanup];
dirk@291
    21
}
dirk@291
    22
andreas@286
    23
- (instancetype)init
andreas@286
    24
{
andreas@286
    25
    self = [super init];
andreas@286
    26
    if (self) {
andreas@287
    27
        // Trigger provider to make sure a internal session is kept for the current thread.
andreas@286
    28
        [PEPSessionProvider session];
andreas@286
    29
    }
andreas@286
    30
    return self;
andreas@286
    31
}
andreas@286
    32
andreas@272
    33
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@272
    34
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    35
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@272
    36
{
andreas@272
    37
    return [PEPSession decryptMessageDict:src dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    38
                                         keys:(PEPStringList * _Nullable * _Nullable)keys];
andreas@272
    39
}
andreas@272
    40
andreas@272
    41
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@272
    42
{
andreas@272
    43
    return [PEPSession reEvaluateMessageRating:src];
andreas@272
    44
}
andreas@272
    45
andreas@272
    46
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
    47
                           extra:(nullable PEPStringList *)keys
andreas@272
    48
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    49
{
andreas@272
    50
    return [PEPSession encryptMessageDict:src extra:keys dest:dst];
andreas@272
    51
}
andreas@272
    52
andreas@272
    53
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
    54
                        identity:(nonnull PEPDict *)identity
andreas@272
    55
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
    56
{
andreas@272
    57
    return [PEPSession encryptMessageDict:src identity:identity dest:dst];
andreas@272
    58
}
andreas@272
    59
andreas@272
    60
- (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
andreas@272
    61
{
andreas@272
    62
    return [PEPSession outgoingMessageColor:msg];
andreas@272
    63
}
andreas@272
    64
andreas@272
    65
- (PEP_rating)identityRating:(nonnull PEPDict *)identity
andreas@272
    66
{
andreas@272
    67
    return [PEPSession identityRating:identity];
andreas@272
    68
}
andreas@272
    69
andreas@272
    70
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
    71
                      shortened:(BOOL)shortened
andreas@272
    72
{
andreas@272
    73
    return [PEPSession trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
    74
}
andreas@272
    75
andreas@272
    76
- (void)mySelf:(nonnull PEPMutableDict *)identity
andreas@272
    77
{
andreas@272
    78
    [PEPSession mySelf:identity];
andreas@272
    79
}
andreas@272
    80
andreas@272
    81
- (void)updateIdentity:(nonnull PEPMutableDict *)identity
andreas@272
    82
{
andreas@272
    83
    [PEPSession updateIdentity:identity];
andreas@272
    84
}
andreas@272
    85
andreas@272
    86
- (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
andreas@272
    87
{
andreas@272
    88
    [PEPSession trustPersonalKey:identity];
andreas@272
    89
}
andreas@272
    90
andreas@272
    91
- (void)keyMistrusted:(nonnull PEPMutableDict *)identity
andreas@272
    92
{
andreas@272
    93
    [PEPSession keyMistrusted:identity];
andreas@272
    94
}
andreas@272
    95
andreas@272
    96
- (void)keyResetTrust:(nonnull PEPMutableDict *)identity
andreas@272
    97
{
andreas@272
    98
    [PEPSession keyResetTrust:identity];
andreas@272
    99
}
andreas@272
   100
andreas@272
   101
#pragma mark Internal API (testing etc.)
andreas@272
   102
andreas@272
   103
- (void)importKey:(nonnull NSString *)keydata
andreas@272
   104
{
andreas@272
   105
    [PEPSession importKey:keydata];
andreas@272
   106
}
andreas@272
   107
andreas@272
   108
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   109
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   110
{
andreas@272
   111
    [PEPSession logTitle:title entity:entity description:description comment:comment];
andreas@272
   112
}
andreas@272
   113
andreas@272
   114
- (nonnull NSString *)getLog
andreas@272
   115
{
andreas@272
   116
    return [PEPSession getLog];
andreas@272
   117
}
andreas@272
   118
andreas@272
   119
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
andreas@272
   120
                                    identity2:(nonnull PEPDict *)identity2
andreas@272
   121
                                     language:(nullable NSString *)language
andreas@272
   122
                                         full:(BOOL)full
andreas@272
   123
{
andreas@272
   124
    return [PEPSession getTrustwordsIdentity1:identity1
andreas@272
   125
                                        identity2:identity2
andreas@272
   126
                                         language:language
andreas@272
   127
                                             full:full];
andreas@272
   128
}
andreas@272
   129
andreas@272
   130
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
andreas@272
   131
                                   receiverDict:(nonnull PEPDict *)receiverDict
andreas@272
   132
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@272
   133
                                       language:(nullable NSString *)language
andreas@272
   134
                                           full:(BOOL)full
andreas@272
   135
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@272
   136
{
andreas@272
   137
    return [PEPSession getTrustwordsMessageDict:messageDict
andreas@272
   138
                                       receiverDict:receiverDict
andreas@272
   139
                                          keysArray:keysArray
andreas@272
   140
                                           language:language
andreas@272
   141
                                               full:full
andreas@272
   142
                                    resultingStatus:resultingStatus];
andreas@272
   143
}
andreas@272
   144
andreas@272
   145
- (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   146
{
andreas@272
   147
    return [PEPSession languageList];
andreas@272
   148
}
andreas@272
   149
andreas@272
   150
- (PEP_STATUS)undoLastMistrust
andreas@272
   151
{
andreas@272
   152
    return [PEPSession undoLastMistrust];
andreas@272
   153
}
andreas@272
   154
andreas@272
   155
#pragma mark - Static 
andreas@272
   156
andreas@272
   157
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
andreas@272
   158
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   159
                            keys:(PEPStringList * _Nullable * _Nullable)keys
andreas@272
   160
{
andreas@272
   161
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   162
    return [session decryptMessageDict:src dest:dst keys:keys];
andreas@272
   163
}
andreas@272
   164
andreas@272
   165
+ (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
andreas@272
   166
{
andreas@272
   167
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   168
    return [session reEvaluateMessageRating:src];
andreas@272
   169
}
andreas@272
   170
andreas@272
   171
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
   172
                           extra:(nullable PEPStringList *)keys
andreas@272
   173
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   174
{
andreas@272
   175
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   176
    return [session encryptMessageDict:src extra:keys dest:dst];
andreas@272
   177
}
andreas@272
   178
andreas@272
   179
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
andreas@272
   180
                        identity:(nonnull PEPDict *)identity
andreas@272
   181
                            dest:(PEPDict * _Nullable * _Nullable)dst
andreas@272
   182
{
andreas@272
   183
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   184
    return [session encryptMessageDict:src identity:identity dest:dst];
andreas@272
   185
}
andreas@272
   186
andreas@272
   187
+ (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
andreas@272
   188
{
andreas@272
   189
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   190
    return [session outgoingMessageColor:msg];
andreas@272
   191
}
andreas@272
   192
andreas@272
   193
+ (PEP_rating)identityRating:(nonnull PEPDict *)identity
andreas@272
   194
{
andreas@272
   195
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   196
    return [session identityRating:identity];
andreas@272
   197
}
andreas@272
   198
andreas@272
   199
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
   200
                      shortened:(BOOL)shortened
andreas@272
   201
{
andreas@272
   202
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   203
    return [session trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
   204
}
andreas@272
   205
andreas@272
   206
+ (void)mySelf:(nonnull PEPMutableDict *)identity
andreas@272
   207
{
andreas@272
   208
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   209
    [session mySelf:identity];
andreas@272
   210
}
andreas@272
   211
andreas@272
   212
+ (void)updateIdentity:(nonnull PEPMutableDict *)identity
andreas@272
   213
{
andreas@272
   214
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   215
    [session updateIdentity:identity];
andreas@272
   216
}
andreas@272
   217
andreas@272
   218
+ (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
andreas@272
   219
{
andreas@272
   220
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   221
    [session trustPersonalKey:identity];
andreas@272
   222
}
andreas@272
   223
andreas@272
   224
+ (void)keyMistrusted:(nonnull PEPMutableDict *)identity
andreas@272
   225
{
andreas@272
   226
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   227
    [session keyMistrusted:identity];
andreas@272
   228
}
andreas@272
   229
andreas@272
   230
+ (void)keyResetTrust:(nonnull PEPMutableDict *)identity
andreas@272
   231
{
andreas@272
   232
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   233
    [session keyResetTrust:identity];
andreas@272
   234
}
andreas@272
   235
andreas@272
   236
#pragma mark Internal API (testing etc.)
andreas@272
   237
andreas@272
   238
+ (void)importKey:(nonnull NSString *)keydata
andreas@272
   239
{
andreas@272
   240
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   241
    [session importKey:keydata];
andreas@272
   242
}
andreas@272
   243
andreas@272
   244
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   245
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   246
{
andreas@272
   247
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   248
    [session logTitle:title entity:entity description:description comment:comment];
andreas@272
   249
}
andreas@272
   250
andreas@272
   251
+ (nonnull NSString *)getLog
andreas@272
   252
{
andreas@272
   253
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   254
    return [session getLog];
andreas@272
   255
}
andreas@272
   256
andreas@272
   257
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
andreas@272
   258
                                    identity2:(nonnull PEPDict *)identity2
andreas@272
   259
                                     language:(nullable NSString *)language
andreas@272
   260
                                         full:(BOOL)full
andreas@272
   261
{
andreas@272
   262
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   263
    return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
andreas@272
   264
}
andreas@272
   265
andreas@272
   266
+ (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
andreas@272
   267
                                   receiverDict:(nonnull PEPDict *)receiverDict
andreas@272
   268
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@272
   269
                                       language:(nullable NSString *)language
andreas@272
   270
                                           full:(BOOL)full
andreas@272
   271
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@272
   272
{
andreas@272
   273
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   274
    return [session getTrustwordsMessageDict:messageDict receiverDict:receiverDict keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
andreas@272
   275
}
andreas@272
   276
andreas@272
   277
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   278
{
andreas@272
   279
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   280
    return [session languageList];
andreas@272
   281
}
andreas@272
   282
andreas@272
   283
+ (PEP_STATUS)undoLastMistrust
andreas@272
   284
{
andreas@272
   285
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   286
    return [session undoLastMistrust];
andreas@272
   287
}
andreas@272
   288
andreas@270
   289
@end