pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Mon, 13 Nov 2017 11:32:57 +0100
changeset 377 49e83dbae8d6
parent 369 8b9b9d8bb2aa
child 378 3da65b85585a
permissions -rw-r--r--
IOSAD-63 using outgoingColorForMessage
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@377
    56
- (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
dirk@377
    57
{
dirk@377
    58
    return [PEPSession outgoingColorForMessage:message];
dirk@377
    59
}
dirk@377
    60
dirk@364
    61
- (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
andreas@272
    62
{
andreas@272
    63
    return [PEPSession identityRating:identity];
andreas@272
    64
}
andreas@272
    65
andreas@272
    66
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
    67
                      shortened:(BOOL)shortened
andreas@272
    68
{
andreas@272
    69
    return [PEPSession trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
    70
}
andreas@272
    71
dirk@348
    72
- (void)mySelf:(nonnull PEPIdentity *)identity
andreas@272
    73
{
andreas@272
    74
    [PEPSession mySelf:identity];
andreas@272
    75
}
andreas@272
    76
dirk@349
    77
- (void)updateIdentity:(nonnull PEPIdentity *)identity
andreas@272
    78
{
dirk@349
    79
    if (identity.isOwn) {
dirk@302
    80
        [PEPSession mySelf:identity];
dirk@302
    81
    } else {
dirk@302
    82
        [PEPSession updateIdentity:identity];
dirk@302
    83
    }
andreas@272
    84
}
andreas@272
    85
dirk@360
    86
- (void)trustPersonalKey:(nonnull PEPIdentity *)identity
andreas@272
    87
{
andreas@272
    88
    [PEPSession trustPersonalKey:identity];
andreas@272
    89
}
andreas@272
    90
dirk@361
    91
- (void)keyMistrusted:(nonnull PEPIdentity *)identity
andreas@272
    92
{
andreas@272
    93
    [PEPSession keyMistrusted:identity];
andreas@272
    94
}
andreas@272
    95
dirk@361
    96
- (void)keyResetTrust:(nonnull PEPIdentity *)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
dirk@365
   119
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
dirk@365
   120
                                    identity2:(nonnull PEPIdentity *)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
dirk@369
   131
                                   receiver:(nonnull PEPIdentity *)receiver
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
dirk@366
   138
                                       receiver:receiver
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
dirk@363
   180
                        identity:(nonnull PEPIdentity *)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
dirk@377
   193
+ (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
dirk@377
   194
{
dirk@377
   195
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@377
   196
    return [session outgoingColorForMessage:message];
dirk@377
   197
}
dirk@377
   198
dirk@364
   199
+ (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
andreas@272
   200
{
andreas@272
   201
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   202
    return [session identityRating:identity];
andreas@272
   203
}
andreas@272
   204
andreas@272
   205
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
andreas@272
   206
                      shortened:(BOOL)shortened
andreas@272
   207
{
andreas@272
   208
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   209
    return [session trustwords:fpr forLanguage:languageID shortened:shortened];
andreas@272
   210
}
andreas@272
   211
dirk@348
   212
+ (void)mySelf:(nonnull PEPIdentity *)identity
andreas@272
   213
{
andreas@272
   214
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   215
    [session mySelf:identity];
andreas@272
   216
}
andreas@272
   217
dirk@349
   218
+ (void)updateIdentity:(nonnull PEPIdentity *)identity
andreas@272
   219
{
andreas@272
   220
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   221
    [session updateIdentity:identity];
andreas@272
   222
}
andreas@272
   223
dirk@360
   224
+ (void)trustPersonalKey:(nonnull PEPIdentity *)identity
andreas@272
   225
{
andreas@272
   226
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   227
    [session trustPersonalKey:identity];
andreas@272
   228
}
andreas@272
   229
dirk@361
   230
+ (void)keyMistrusted:(nonnull PEPIdentity *)identity
andreas@272
   231
{
andreas@272
   232
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   233
    [session keyMistrusted:identity];
andreas@272
   234
}
andreas@272
   235
dirk@361
   236
+ (void)keyResetTrust:(nonnull PEPIdentity *)identity
andreas@272
   237
{
andreas@272
   238
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   239
    [session keyResetTrust:identity];
andreas@272
   240
}
andreas@272
   241
andreas@272
   242
#pragma mark Internal API (testing etc.)
andreas@272
   243
andreas@272
   244
+ (void)importKey:(nonnull NSString *)keydata
andreas@272
   245
{
andreas@272
   246
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   247
    [session importKey:keydata];
andreas@272
   248
}
andreas@272
   249
andreas@272
   250
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
andreas@272
   251
     description:(nullable NSString *)description comment:(nullable NSString *)comment
andreas@272
   252
{
andreas@272
   253
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   254
    [session logTitle:title entity:entity description:description comment:comment];
andreas@272
   255
}
andreas@272
   256
andreas@272
   257
+ (nonnull NSString *)getLog
andreas@272
   258
{
andreas@272
   259
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   260
    return [session getLog];
andreas@272
   261
}
andreas@272
   262
dirk@365
   263
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
dirk@365
   264
                                    identity2:(nonnull PEPIdentity *)identity2
andreas@272
   265
                                     language:(nullable NSString *)language
andreas@272
   266
                                         full:(BOOL)full
andreas@272
   267
{
andreas@272
   268
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   269
    return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
andreas@272
   270
}
andreas@272
   271
andreas@272
   272
+ (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
dirk@366
   273
                                   receiver:(nonnull PEPIdentity *)receiver
andreas@272
   274
                                      keysArray:(PEPStringList * _Nullable)keysArray
andreas@272
   275
                                       language:(nullable NSString *)language
andreas@272
   276
                                           full:(BOOL)full
andreas@272
   277
                                resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
andreas@272
   278
{
andreas@272
   279
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@366
   280
    return [session getTrustwordsMessageDict:messageDict receiver:receiver keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
andreas@272
   281
}
andreas@272
   282
andreas@272
   283
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   284
{
andreas@272
   285
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   286
    return [session languageList];
andreas@272
   287
}
andreas@272
   288
andreas@272
   289
+ (PEP_STATUS)undoLastMistrust
andreas@272
   290
{
andreas@272
   291
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   292
    return [session undoLastMistrust];
andreas@272
   293
}
andreas@272
   294
andreas@270
   295
@end