pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Thu, 15 Mar 2018 08:04:36 +0100
changeset 536 2c9ad397d261
parent 535 9ef279e6880d
child 545 7217e3c844e0
permissions -rw-r--r--
IOSAD-72 keyMistrusted
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@535
    24
- (PEPDict * _Nullable)decryptMessageDict:(PEPDict * _Nonnull)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@535
    39
- (PEPMessage * _Nullable)decryptMessage:(PEPMessage * _Nonnull)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@535
    54
- (BOOL)reEvaluateMessageDict:(PEPDict * _Nonnull)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@535
    63
- (BOOL)reEvaluateMessage:(PEPMessage * _Nonnull)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@535
    72
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@535
    73
                                    extraKeys:(PEPStringList * _Nullable)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@535
    87
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
    88
                               extraKeys:(PEPStringList * _Nullable)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@535
   102
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
   103
                               extraKeys:(PEPStringList * _Nullable)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@535
   111
- (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
dirk@535
   112
                                 identity:(PEPIdentity * _Nonnull)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@535
   120
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@535
   121
                                identity:(PEPIdentity * _Nonnull)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@528
   129
- (BOOL)outgoingRating:(PEP_rating * _Nonnull)rating
dirk@528
   130
            forMessage:(PEPMessage * _Nonnull)message
dirk@528
   131
                 error:(NSError * _Nullable * _Nullable)error
dirk@377
   132
{
dirk@519
   133
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@528
   134
    return [session outgoingRating:rating forMessage:message error:error];
dirk@377
   135
}
dirk@377
   136
dirk@529
   137
- (BOOL)rating:(PEP_rating * _Nonnull)rating
dirk@530
   138
   forIdentity:(PEPIdentity * _Nonnull)identity
dirk@530
   139
         error:(NSError * _Nullable * _Nullable)error
dirk@530
   140
{
dirk@519
   141
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@529
   142
    return [session rating:rating forIdentity:identity error:error];
andreas@272
   143
}
andreas@272
   144
dirk@531
   145
- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
dirk@531
   146
                                     languageID:(NSString * _Nonnull)languageID
dirk@531
   147
                                      shortened:(BOOL)shortened
dirk@531
   148
                                          error:(NSError * _Nullable * _Nullable)error
andreas@272
   149
{
dirk@519
   150
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@531
   151
    return [session
dirk@531
   152
            trustwordsForFingerprint:fingerprint
dirk@531
   153
            languageID:languageID
dirk@531
   154
            shortened:shortened
dirk@531
   155
            error:error];
andreas@272
   156
}
andreas@272
   157
dirk@535
   158
- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
andreas@272
   159
{
dirk@519
   160
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   161
    return [session mySelf:identity error:error];
andreas@272
   162
}
andreas@272
   163
dirk@536
   164
- (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
dirk@536
   165
                 error:(NSError * _Nullable * _Nullable)error
andreas@272
   166
{
dirk@519
   167
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   168
    return [session updateIdentity:identity error:error];
andreas@272
   169
}
andreas@272
   170
dirk@535
   171
- (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
dirk@534
   172
                   error:(NSError * _Nullable * _Nullable)error
andreas@272
   173
{
dirk@519
   174
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@534
   175
    return [session trustPersonalKey:identity error:error];
andreas@272
   176
}
andreas@272
   177
dirk@536
   178
- (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
dirk@536
   179
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   180
{
dirk@519
   181
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@536
   182
    return [session keyMistrusted:identity error:error];
andreas@272
   183
}
andreas@272
   184
dirk@535
   185
- (void)keyResetTrust:(PEPIdentity * _Nonnull)identity
andreas@272
   186
{
dirk@519
   187
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@519
   188
    [session keyResetTrust:identity];
andreas@272
   189
}
andreas@272
   190
andreas@272
   191
#pragma mark Internal API (testing etc.)
andreas@272
   192
dirk@535
   193
- (void)importKey:(NSString * _Nonnull)keydata
andreas@272
   194
{
andreas@272
   195
    [PEPSession importKey:keydata];
andreas@272
   196
}
andreas@272
   197
dirk@535
   198
- (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
dirk@535
   199
     description:(NSString * _Nullable)description comment:(NSString * _Nullable)comment
andreas@272
   200
{
andreas@272
   201
    [PEPSession logTitle:title entity:entity description:description comment:comment];
andreas@272
   202
}
andreas@272
   203
dirk@535
   204
- (NSString * _Nullable)getLog
andreas@272
   205
{
andreas@272
   206
    return [PEPSession getLog];
andreas@272
   207
}
andreas@272
   208
dirk@535
   209
- (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
dirk@535
   210
                                     identity2:(PEPIdentity * _Nonnull)identity2
dirk@535
   211
                                      language:(NSString * _Nullable)language
dirk@535
   212
                                          full:(BOOL)full
andreas@272
   213
{
andreas@272
   214
    return [PEPSession getTrustwordsIdentity1:identity1
andreas@272
   215
                                        identity2:identity2
andreas@272
   216
                                         language:language
andreas@272
   217
                                             full:full];
andreas@272
   218
}
andreas@272
   219
andreas@272
   220
- (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   221
{
andreas@272
   222
    return [PEPSession languageList];
andreas@272
   223
}
andreas@272
   224
andreas@272
   225
- (PEP_STATUS)undoLastMistrust
andreas@272
   226
{
andreas@272
   227
    return [PEPSession undoLastMistrust];
andreas@272
   228
}
andreas@272
   229
dirk@417
   230
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   231
{
dirk@417
   232
    return [PEPSession ratingFromString:string];
dirk@417
   233
}
dirk@417
   234
dirk@417
   235
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   236
{
dirk@417
   237
    return [PEPSession stringFromRating:rating];
dirk@417
   238
}
dirk@417
   239
dirk@453
   240
- (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@427
   241
{
dirk@453
   242
    return [PEPSession isPEPUser:identity];
dirk@427
   243
}
dirk@427
   244
dirk@501
   245
- (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   246
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   247
{
dirk@501
   248
    return [PEPSession setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   249
}
dirk@501
   250
andreas@272
   251
#pragma mark Internal API (testing etc.)
andreas@272
   252
dirk@535
   253
+ (void)importKey:(NSString * _Nonnull)keydata
andreas@272
   254
{
andreas@272
   255
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   256
    [session importKey:keydata];
andreas@272
   257
}
andreas@272
   258
dirk@535
   259
+ (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
dirk@535
   260
     description:(NSString * _Nullable)description comment:(NSString * _Nullable)comment
andreas@272
   261
{
andreas@272
   262
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   263
    [session logTitle:title entity:entity description:description comment:comment];
andreas@272
   264
}
andreas@272
   265
dirk@535
   266
+ (NSString * _Nullable)getLog
andreas@272
   267
{
andreas@272
   268
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   269
    return [session getLog];
andreas@272
   270
}
andreas@272
   271
dirk@535
   272
+ (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
dirk@535
   273
                                     identity2:(PEPIdentity * _Nonnull)identity2
dirk@535
   274
                                      language:(NSString * _Nullable)language
dirk@535
   275
                                          full:(BOOL)full
andreas@272
   276
{
andreas@272
   277
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   278
    return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
andreas@272
   279
}
andreas@272
   280
andreas@272
   281
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
andreas@272
   282
{
andreas@272
   283
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   284
    return [session languageList];
andreas@272
   285
}
andreas@272
   286
andreas@272
   287
+ (PEP_STATUS)undoLastMistrust
andreas@272
   288
{
andreas@272
   289
    PEPInternalSession *session = [PEPSessionProvider session];
andreas@272
   290
    return [session undoLastMistrust];
andreas@272
   291
}
andreas@272
   292
dirk@417
   293
+ (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   294
{
dirk@417
   295
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@417
   296
    return [session ratingFromString:string];
dirk@417
   297
}
dirk@417
   298
dirk@417
   299
+ (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   300
{
dirk@417
   301
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@417
   302
    return [session stringFromRating:rating];
dirk@417
   303
}
dirk@417
   304
dirk@453
   305
+ (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
dirk@427
   306
{
dirk@427
   307
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@453
   308
    return [session isPEPUser:identity];
dirk@427
   309
}
dirk@427
   310
dirk@501
   311
+ (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   312
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   313
{
dirk@501
   314
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@501
   315
    return [session setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   316
}
dirk@501
   317
andreas@270
   318
@end