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