pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Wed, 07 Nov 2018 10:54:28 +0100
branchIOSAD-103
changeset 773 eba616cd8912
parent 768 41f5d64f03c1
child 777 b8bff9ab5cdf
permissions -rw-r--r--
IOSAD-103 deliverHandshakeResult
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@596
    24
- (PEPDict * _Nullable)decryptMessageDict:(PEPMutableDict * _Nonnull)messageDict
dirk@583
    25
                                    flags:(PEP_decrypt_flags * _Nullable)flags
dirk@517
    26
                                   rating:(PEP_rating * _Nullable)rating
dirk@523
    27
                                extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
dirk@524
    28
                                   status:(PEP_STATUS * _Nullable)status
dirk@517
    29
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
    30
{
dirk@519
    31
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@524
    32
    return [session
dirk@524
    33
            decryptMessageDict:messageDict
dirk@583
    34
            flags:flags
dirk@524
    35
            rating:rating
dirk@524
    36
            extraKeys:extraKeys
dirk@524
    37
            status:status
dirk@524
    38
            error:error];
dirk@383
    39
}
dirk@383
    40
dirk@535
    41
- (PEPMessage * _Nullable)decryptMessage:(PEPMessage * _Nonnull)message
dirk@583
    42
                                   flags:(PEP_decrypt_flags * _Nullable)flags
dirk@517
    43
                                  rating:(PEP_rating * _Nullable)rating
dirk@523
    44
                               extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
dirk@524
    45
                                  status:(PEP_STATUS * _Nullable)status
dirk@517
    46
                                   error:(NSError * _Nullable * _Nullable)error
dirk@383
    47
{
dirk@519
    48
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@524
    49
    return [session
dirk@524
    50
            decryptMessage:message
dirk@583
    51
            flags:flags
dirk@524
    52
            rating:rating
dirk@524
    53
            extraKeys:extraKeys
dirk@524
    54
            status:status
dirk@524
    55
            error:error];
andreas@272
    56
}
andreas@272
    57
dirk@535
    58
- (BOOL)reEvaluateMessageDict:(PEPDict * _Nonnull)messageDict
dirk@634
    59
                     xKeyList:(PEPStringList * _Nullable)xKeyList
dirk@633
    60
                       rating:(PEP_rating * _Nonnull)rating
dirk@524
    61
                       status:(PEP_STATUS * _Nullable)status
dirk@516
    62
                        error:(NSError * _Nullable * _Nullable)error
andreas@272
    63
{
dirk@519
    64
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@634
    65
    return [session reEvaluateMessageDict:messageDict
dirk@634
    66
                                 xKeyList:xKeyList
dirk@634
    67
                                   rating:rating
dirk@634
    68
                                   status:status
dirk@634
    69
                                    error:error];
andreas@272
    70
}
andreas@272
    71
dirk@535
    72
- (BOOL)reEvaluateMessage:(PEPMessage * _Nonnull)message
dirk@634
    73
                 xKeyList:(PEPStringList * _Nullable)xKeyList
dirk@633
    74
                   rating:(PEP_rating * _Nonnull)rating
dirk@524
    75
                   status:(PEP_STATUS * _Nullable)status
dirk@516
    76
                    error:(NSError * _Nullable * _Nullable)error
dirk@384
    77
{
dirk@519
    78
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@634
    79
    return [session reEvaluateMessage:message
dirk@634
    80
                             xKeyList:xKeyList
dirk@634
    81
                               rating:rating
dirk@634
    82
                               status:status
dirk@634
    83
                                error:error];
dirk@384
    84
}
dirk@384
    85
dirk@535
    86
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@535
    87
                                    extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@522
    88
                                encFormat:(PEP_enc_format)encFormat
dirk@524
    89
                                   status:(PEP_STATUS * _Nullable)status
dirk@522
    90
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
    91
{
dirk@519
    92
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@523
    93
    return [session
dirk@523
    94
            encryptMessageDict:messageDict
dirk@523
    95
            extraKeys:extraKeys
dirk@523
    96
            encFormat:encFormat
dirk@524
    97
            status:status
dirk@523
    98
            error:error];
andreas@272
    99
}
andreas@272
   100
dirk@535
   101
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
   102
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@522
   103
                               encFormat:(PEP_enc_format)encFormat
dirk@524
   104
                                  status:(PEP_STATUS * _Nullable)status
dirk@522
   105
                                   error:(NSError * _Nullable * _Nullable)error
dirk@379
   106
{
dirk@519
   107
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@524
   108
    return [session
dirk@524
   109
            encryptMessage:message
dirk@524
   110
            extraKeys:extraKeys
dirk@524
   111
            encFormat:encFormat
dirk@524
   112
            status:status
dirk@524
   113
            error:error];
dirk@379
   114
}
dirk@379
   115
dirk@535
   116
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
   117
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@524
   118
                                  status:(PEP_STATUS * _Nullable)status
dirk@522
   119
                                   error:(NSError * _Nullable * _Nullable)error
dirk@386
   120
{
dirk@519
   121
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@630
   122
    return [session encryptMessage:message extraKeys:extraKeys status:status error:error];
dirk@386
   123
}
dirk@386
   124
dirk@535
   125
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@557
   126
                                  forSelf:(PEPIdentity * _Nonnull)ownIdentity
dirk@556
   127
                                extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@526
   128
                                   status:(PEP_STATUS * _Nullable)status
dirk@526
   129
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
   130
{
dirk@519
   131
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@556
   132
    return [session
dirk@556
   133
            encryptMessageDict:messageDict
dirk@557
   134
            forSelf:ownIdentity
dirk@556
   135
            extraKeys:extraKeys
dirk@556
   136
            status:status
dirk@556
   137
            error:error];
andreas@272
   138
}
andreas@272
   139
dirk@535
   140
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@557
   141
                                 forSelf:(PEPIdentity * _Nonnull)ownIdentity
dirk@556
   142
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@526
   143
                                  status:(PEP_STATUS * _Nullable)status
dirk@526
   144
                                   error:(NSError * _Nullable * _Nullable)error
dirk@381
   145
{
dirk@519
   146
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@556
   147
    return [session
dirk@556
   148
            encryptMessage:message
dirk@557
   149
            forSelf:ownIdentity
dirk@556
   150
            extraKeys:extraKeys
dirk@556
   151
            status:status
dirk@556
   152
            error:error];
dirk@381
   153
}
dirk@381
   154
dirk@611
   155
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@611
   156
                                    toFpr:(NSString * _Nonnull)toFpr
dirk@611
   157
                                encFormat:(PEP_enc_format)encFormat
dirk@611
   158
                                    flags:(PEP_decrypt_flags)flags
dirk@611
   159
                                   status:(PEP_STATUS * _Nullable)status
dirk@611
   160
                                    error:(NSError * _Nullable * _Nullable)error __deprecated
dirk@611
   161
{
dirk@611
   162
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@611
   163
    return [session
dirk@611
   164
            encryptMessageDict:messageDict
dirk@611
   165
            toFpr:toFpr
dirk@611
   166
            encFormat:encFormat
dirk@611
   167
            flags:flags
dirk@611
   168
            status:status
dirk@611
   169
            error:error];
dirk@611
   170
}
dirk@611
   171
dirk@611
   172
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@611
   173
                                   toFpr:(NSString * _Nonnull)toFpr
dirk@611
   174
                               encFormat:(PEP_enc_format)encFormat
dirk@611
   175
                                   flags:(PEP_decrypt_flags)flags
dirk@611
   176
                                  status:(PEP_STATUS * _Nullable)status
dirk@611
   177
                                   error:(NSError * _Nullable * _Nullable)error
dirk@611
   178
{
dirk@611
   179
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@611
   180
    return [session
dirk@611
   181
            encryptMessage:message
dirk@611
   182
            toFpr:toFpr
dirk@611
   183
            encFormat:encFormat
dirk@611
   184
            flags:flags
dirk@611
   185
            status:status
dirk@611
   186
            error:error];
dirk@611
   187
}
dirk@611
   188
dirk@650
   189
- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
dirk@573
   190
                                           error:(NSError * _Nullable * _Nullable)error
dirk@377
   191
{
dirk@519
   192
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@650
   193
    return [session outgoingRatingForMessage:theMessage error:error];
dirk@377
   194
}
dirk@377
   195
dirk@652
   196
- (NSNumber * _Nullable)outgoingRatingPreviewForMessage:(PEPMessage * _Nonnull)theMessage
dirk@652
   197
                                                  error:(NSError * _Nullable * _Nullable)error
dirk@652
   198
{
dirk@652
   199
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@652
   200
    return [session outgoingRatingPreviewForMessage:theMessage error:error];
dirk@652
   201
}
dirk@652
   202
dirk@574
   203
- (NSNumber * _Nullable)ratingForIdentity:(PEPIdentity * _Nonnull)identity
dirk@574
   204
                                    error:(NSError * _Nullable * _Nullable)error
dirk@530
   205
{
dirk@519
   206
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@574
   207
    return [session ratingForIdentity:identity error:error];
andreas@272
   208
}
andreas@272
   209
dirk@531
   210
- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
dirk@531
   211
                                     languageID:(NSString * _Nonnull)languageID
dirk@531
   212
                                      shortened:(BOOL)shortened
dirk@531
   213
                                          error:(NSError * _Nullable * _Nullable)error
andreas@272
   214
{
dirk@519
   215
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@531
   216
    return [session
dirk@531
   217
            trustwordsForFingerprint:fingerprint
dirk@531
   218
            languageID:languageID
dirk@531
   219
            shortened:shortened
dirk@531
   220
            error:error];
andreas@272
   221
}
andreas@272
   222
dirk@535
   223
- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
andreas@272
   224
{
dirk@519
   225
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   226
    return [session mySelf:identity error:error];
andreas@272
   227
}
andreas@272
   228
dirk@536
   229
- (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
dirk@536
   230
                 error:(NSError * _Nullable * _Nullable)error
andreas@272
   231
{
dirk@519
   232
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   233
    return [session updateIdentity:identity error:error];
andreas@272
   234
}
andreas@272
   235
dirk@535
   236
- (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
dirk@534
   237
                   error:(NSError * _Nullable * _Nullable)error
andreas@272
   238
{
dirk@519
   239
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@534
   240
    return [session trustPersonalKey:identity error:error];
andreas@272
   241
}
andreas@272
   242
dirk@536
   243
- (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
dirk@536
   244
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   245
{
dirk@519
   246
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@536
   247
    return [session keyMistrusted:identity error:error];
andreas@272
   248
}
andreas@272
   249
dirk@545
   250
- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
dirk@545
   251
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   252
{
dirk@519
   253
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@545
   254
    return [session keyResetTrust:identity error:error];
andreas@272
   255
}
andreas@272
   256
andreas@272
   257
#pragma mark Internal API (testing etc.)
andreas@272
   258
dirk@665
   259
- (NSArray * _Nullable)importKey:(NSString * _Nonnull)keydata
dirk@665
   260
                           error:(NSError * _Nullable * _Nullable)error
andreas@272
   261
{
dirk@551
   262
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@551
   263
    return [session importKey:keydata error:error];
andreas@272
   264
}
andreas@272
   265
dirk@553
   266
- (BOOL)logTitle:(NSString * _Nonnull)title
dirk@553
   267
          entity:(NSString * _Nonnull)entity
dirk@553
   268
     description:(NSString * _Nullable)description
dirk@553
   269
         comment:(NSString * _Nullable)comment
dirk@553
   270
           error:(NSError * _Nullable * _Nullable)error
andreas@272
   271
{
dirk@553
   272
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@553
   273
    return [session
dirk@553
   274
            logTitle:title
dirk@553
   275
            entity:entity
dirk@553
   276
            description:description
dirk@553
   277
            comment:comment
dirk@553
   278
            error:error];
andreas@272
   279
}
andreas@272
   280
dirk@552
   281
- (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   282
{
dirk@552
   283
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@552
   284
    return [session getLogWithError:error];
andreas@272
   285
}
andreas@272
   286
dirk@535
   287
- (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
dirk@535
   288
                                     identity2:(PEPIdentity * _Nonnull)identity2
dirk@535
   289
                                      language:(NSString * _Nullable)language
dirk@535
   290
                                          full:(BOOL)full
dirk@558
   291
                                         error:(NSError * _Nullable * _Nullable)error
andreas@272
   292
{
dirk@558
   293
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@558
   294
    return [session getTrustwordsIdentity1:identity1
dirk@558
   295
                                 identity2:identity2
dirk@558
   296
                                  language:language
dirk@558
   297
                                      full:full
dirk@558
   298
                                     error:error];
andreas@272
   299
}
andreas@272
   300
dirk@560
   301
- (NSArray<PEPLanguage *> * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   302
{
dirk@560
   303
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@560
   304
    return [session languageListWithError:error];
andreas@272
   305
}
andreas@272
   306
dirk@417
   307
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   308
{
dirk@566
   309
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@566
   310
    return [session ratingFromString:string];
dirk@417
   311
}
dirk@417
   312
dirk@417
   313
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   314
{
dirk@566
   315
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@566
   316
    return [session stringFromRating:rating];
dirk@417
   317
}
dirk@417
   318
dirk@567
   319
- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@567
   320
                            error:(NSError * _Nullable * _Nullable)error
dirk@427
   321
{
dirk@567
   322
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@567
   323
    return [session isPEPUser:identity error:error];
dirk@427
   324
}
dirk@427
   325
dirk@501
   326
- (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   327
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   328
{
dirk@501
   329
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@501
   330
    return [session setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   331
}
dirk@501
   332
dirk@624
   333
- (void)configurePassiveModeEnabled:(BOOL)enabled
dirk@624
   334
{
dirk@624
   335
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@624
   336
    return [session configurePassiveModeEnabled:enabled];
dirk@624
   337
}
dirk@624
   338
dirk@768
   339
- (BOOL)setFlags:(identity_flags_t)flags
dirk@768
   340
     forIdentity:(PEPIdentity *)identity
dirk@768
   341
           error:(NSError * _Nullable * _Nullable)error
dirk@768
   342
{
dirk@768
   343
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@768
   344
    return [session setFlags:flags forIdentity:identity error:error];
dirk@768
   345
}
dirk@768
   346
dirk@773
   347
- (BOOL)deliverHandshakeResult:(sync_handshake_result)result
dirk@773
   348
                    forPartner:(PEPIdentity * _Nonnull)partner
dirk@773
   349
                         error:(NSError * _Nullable * _Nullable)error
dirk@773
   350
{
dirk@773
   351
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@773
   352
    return [session deliverHandshakeResult:result forPartner:partner error:error];
dirk@773
   353
}
dirk@773
   354
andreas@270
   355
@end