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