pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Mon, 18 Jun 2018 11:37:18 +0200
changeset 630 ac0b9f0507ba
parent 629 7e6343055e4d
child 633 e9078acc8b2a
permissions -rw-r--r--
IOSAD-95 really needed? Backed out changeset cb0e8fd9b407
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@516
    59
                       rating:(PEP_rating * _Nullable)rating
dirk@524
    60
                       status:(PEP_STATUS * _Nullable)status
dirk@516
    61
                        error:(NSError * _Nullable * _Nullable)error
andreas@272
    62
{
dirk@519
    63
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@524
    64
    return [session reEvaluateMessageDict:messageDict rating:rating status:status error:error];
andreas@272
    65
}
andreas@272
    66
dirk@535
    67
- (BOOL)reEvaluateMessage:(PEPMessage * _Nonnull)message
dirk@516
    68
                   rating:(PEP_rating * _Nullable)rating
dirk@524
    69
                   status:(PEP_STATUS * _Nullable)status
dirk@516
    70
                    error:(NSError * _Nullable * _Nullable)error
dirk@384
    71
{
dirk@519
    72
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@524
    73
    return [session reEvaluateMessage:message rating:rating status:status error:error];
dirk@384
    74
}
dirk@384
    75
dirk@535
    76
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@535
    77
                                    extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@522
    78
                                encFormat:(PEP_enc_format)encFormat
dirk@524
    79
                                   status:(PEP_STATUS * _Nullable)status
dirk@522
    80
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
    81
{
dirk@519
    82
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@523
    83
    return [session
dirk@523
    84
            encryptMessageDict:messageDict
dirk@523
    85
            extraKeys:extraKeys
dirk@523
    86
            encFormat:encFormat
dirk@524
    87
            status:status
dirk@523
    88
            error:error];
andreas@272
    89
}
andreas@272
    90
dirk@535
    91
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
    92
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@522
    93
                               encFormat:(PEP_enc_format)encFormat
dirk@524
    94
                                  status:(PEP_STATUS * _Nullable)status
dirk@522
    95
                                   error:(NSError * _Nullable * _Nullable)error
dirk@379
    96
{
dirk@519
    97
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@524
    98
    return [session
dirk@524
    99
            encryptMessage:message
dirk@524
   100
            extraKeys:extraKeys
dirk@524
   101
            encFormat:encFormat
dirk@524
   102
            status:status
dirk@524
   103
            error:error];
dirk@379
   104
}
dirk@379
   105
dirk@535
   106
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
   107
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@524
   108
                                  status:(PEP_STATUS * _Nullable)status
dirk@522
   109
                                   error:(NSError * _Nullable * _Nullable)error
dirk@386
   110
{
dirk@519
   111
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@630
   112
    return [session encryptMessage:message extraKeys:extraKeys status:status error:error];
dirk@386
   113
}
dirk@386
   114
dirk@535
   115
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@557
   116
                                  forSelf:(PEPIdentity * _Nonnull)ownIdentity
dirk@556
   117
                                extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@526
   118
                                   status:(PEP_STATUS * _Nullable)status
dirk@526
   119
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
   120
{
dirk@519
   121
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@556
   122
    return [session
dirk@556
   123
            encryptMessageDict:messageDict
dirk@557
   124
            forSelf:ownIdentity
dirk@556
   125
            extraKeys:extraKeys
dirk@556
   126
            status:status
dirk@556
   127
            error:error];
andreas@272
   128
}
andreas@272
   129
dirk@535
   130
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@557
   131
                                 forSelf:(PEPIdentity * _Nonnull)ownIdentity
dirk@556
   132
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@526
   133
                                  status:(PEP_STATUS * _Nullable)status
dirk@526
   134
                                   error:(NSError * _Nullable * _Nullable)error
dirk@381
   135
{
dirk@519
   136
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@556
   137
    return [session
dirk@556
   138
            encryptMessage:message
dirk@557
   139
            forSelf:ownIdentity
dirk@556
   140
            extraKeys:extraKeys
dirk@556
   141
            status:status
dirk@556
   142
            error:error];
dirk@381
   143
}
dirk@381
   144
dirk@611
   145
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@611
   146
                                    toFpr:(NSString * _Nonnull)toFpr
dirk@611
   147
                                encFormat:(PEP_enc_format)encFormat
dirk@611
   148
                                    flags:(PEP_decrypt_flags)flags
dirk@611
   149
                                   status:(PEP_STATUS * _Nullable)status
dirk@611
   150
                                    error:(NSError * _Nullable * _Nullable)error __deprecated
dirk@611
   151
{
dirk@611
   152
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@611
   153
    return [session
dirk@611
   154
            encryptMessageDict:messageDict
dirk@611
   155
            toFpr:toFpr
dirk@611
   156
            encFormat:encFormat
dirk@611
   157
            flags:flags
dirk@611
   158
            status:status
dirk@611
   159
            error:error];
dirk@611
   160
}
dirk@611
   161
dirk@611
   162
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@611
   163
                                   toFpr:(NSString * _Nonnull)toFpr
dirk@611
   164
                               encFormat:(PEP_enc_format)encFormat
dirk@611
   165
                                   flags:(PEP_decrypt_flags)flags
dirk@611
   166
                                  status:(PEP_STATUS * _Nullable)status
dirk@611
   167
                                   error:(NSError * _Nullable * _Nullable)error
dirk@611
   168
{
dirk@611
   169
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@611
   170
    return [session
dirk@611
   171
            encryptMessage:message
dirk@611
   172
            toFpr:toFpr
dirk@611
   173
            encFormat:encFormat
dirk@611
   174
            flags:flags
dirk@611
   175
            status:status
dirk@611
   176
            error:error];
dirk@611
   177
}
dirk@611
   178
dirk@573
   179
- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)message
dirk@573
   180
                                           error:(NSError * _Nullable * _Nullable)error
dirk@377
   181
{
dirk@519
   182
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@573
   183
    return [session outgoingRatingForMessage:message error:error];
dirk@377
   184
}
dirk@377
   185
dirk@574
   186
- (NSNumber * _Nullable)ratingForIdentity:(PEPIdentity * _Nonnull)identity
dirk@574
   187
                                    error:(NSError * _Nullable * _Nullable)error
dirk@530
   188
{
dirk@519
   189
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@574
   190
    return [session ratingForIdentity:identity error:error];
andreas@272
   191
}
andreas@272
   192
dirk@531
   193
- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
dirk@531
   194
                                     languageID:(NSString * _Nonnull)languageID
dirk@531
   195
                                      shortened:(BOOL)shortened
dirk@531
   196
                                          error:(NSError * _Nullable * _Nullable)error
andreas@272
   197
{
dirk@519
   198
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@531
   199
    return [session
dirk@531
   200
            trustwordsForFingerprint:fingerprint
dirk@531
   201
            languageID:languageID
dirk@531
   202
            shortened:shortened
dirk@531
   203
            error:error];
andreas@272
   204
}
andreas@272
   205
dirk@535
   206
- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
andreas@272
   207
{
dirk@519
   208
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   209
    return [session mySelf:identity error:error];
andreas@272
   210
}
andreas@272
   211
dirk@536
   212
- (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
dirk@536
   213
                 error:(NSError * _Nullable * _Nullable)error
andreas@272
   214
{
dirk@519
   215
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   216
    return [session updateIdentity:identity error:error];
andreas@272
   217
}
andreas@272
   218
dirk@535
   219
- (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
dirk@534
   220
                   error:(NSError * _Nullable * _Nullable)error
andreas@272
   221
{
dirk@519
   222
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@534
   223
    return [session trustPersonalKey:identity error:error];
andreas@272
   224
}
andreas@272
   225
dirk@536
   226
- (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
dirk@536
   227
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   228
{
dirk@519
   229
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@536
   230
    return [session keyMistrusted:identity error:error];
andreas@272
   231
}
andreas@272
   232
dirk@545
   233
- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
dirk@545
   234
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   235
{
dirk@519
   236
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@545
   237
    return [session keyResetTrust:identity error:error];
andreas@272
   238
}
andreas@272
   239
andreas@272
   240
#pragma mark Internal API (testing etc.)
andreas@272
   241
dirk@551
   242
- (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error
andreas@272
   243
{
dirk@551
   244
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@551
   245
    return [session importKey:keydata error:error];
andreas@272
   246
}
andreas@272
   247
dirk@553
   248
- (BOOL)logTitle:(NSString * _Nonnull)title
dirk@553
   249
          entity:(NSString * _Nonnull)entity
dirk@553
   250
     description:(NSString * _Nullable)description
dirk@553
   251
         comment:(NSString * _Nullable)comment
dirk@553
   252
           error:(NSError * _Nullable * _Nullable)error
andreas@272
   253
{
dirk@553
   254
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@553
   255
    return [session
dirk@553
   256
            logTitle:title
dirk@553
   257
            entity:entity
dirk@553
   258
            description:description
dirk@553
   259
            comment:comment
dirk@553
   260
            error:error];
andreas@272
   261
}
andreas@272
   262
dirk@552
   263
- (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   264
{
dirk@552
   265
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@552
   266
    return [session getLogWithError:error];
andreas@272
   267
}
andreas@272
   268
dirk@535
   269
- (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
dirk@535
   270
                                     identity2:(PEPIdentity * _Nonnull)identity2
dirk@535
   271
                                      language:(NSString * _Nullable)language
dirk@535
   272
                                          full:(BOOL)full
dirk@558
   273
                                         error:(NSError * _Nullable * _Nullable)error
andreas@272
   274
{
dirk@558
   275
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@558
   276
    return [session getTrustwordsIdentity1:identity1
dirk@558
   277
                                 identity2:identity2
dirk@558
   278
                                  language:language
dirk@558
   279
                                      full:full
dirk@558
   280
                                     error:error];
andreas@272
   281
}
andreas@272
   282
dirk@560
   283
- (NSArray<PEPLanguage *> * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   284
{
dirk@560
   285
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@560
   286
    return [session languageListWithError:error];
andreas@272
   287
}
andreas@272
   288
dirk@565
   289
- (BOOL)undoLastMistrustWithError:(NSError * _Nullable * _Nullable)error;
andreas@272
   290
{
dirk@565
   291
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@565
   292
    return [session undoLastMistrustWithError:error];
andreas@272
   293
}
andreas@272
   294
dirk@417
   295
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   296
{
dirk@566
   297
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@566
   298
    return [session ratingFromString:string];
dirk@417
   299
}
dirk@417
   300
dirk@417
   301
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   302
{
dirk@566
   303
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@566
   304
    return [session stringFromRating:rating];
dirk@417
   305
}
dirk@417
   306
dirk@567
   307
- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@567
   308
                            error:(NSError * _Nullable * _Nullable)error
dirk@427
   309
{
dirk@567
   310
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@567
   311
    return [session isPEPUser:identity error:error];
dirk@427
   312
}
dirk@427
   313
dirk@501
   314
- (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   315
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   316
{
dirk@501
   317
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@501
   318
    return [session setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   319
}
dirk@501
   320
dirk@624
   321
- (void)configurePassiveModeEnabled:(BOOL)enabled
dirk@624
   322
{
dirk@624
   323
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@624
   324
    return [session configurePassiveModeEnabled:enabled];
dirk@624
   325
}
dirk@624
   326
andreas@270
   327
@end