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