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