pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Mon, 23 Apr 2018 19:22:52 +0200
changeset 583 f81193bdb664
parent 574 03a019b2533b
child 584 7d876a17c31c
child 596 2a2f52bb7e41
permissions -rw-r--r--
IOSAD-72 decrypt with flags in/out
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@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@524
   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@573
   145
- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)message
dirk@573
   146
                                           error:(NSError * _Nullable * _Nullable)error
dirk@377
   147
{
dirk@519
   148
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@573
   149
    return [session outgoingRatingForMessage:message error:error];
dirk@377
   150
}
dirk@377
   151
dirk@574
   152
- (NSNumber * _Nullable)ratingForIdentity:(PEPIdentity * _Nonnull)identity
dirk@574
   153
                                    error:(NSError * _Nullable * _Nullable)error
dirk@530
   154
{
dirk@519
   155
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@574
   156
    return [session ratingForIdentity:identity error:error];
andreas@272
   157
}
andreas@272
   158
dirk@531
   159
- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
dirk@531
   160
                                     languageID:(NSString * _Nonnull)languageID
dirk@531
   161
                                      shortened:(BOOL)shortened
dirk@531
   162
                                          error:(NSError * _Nullable * _Nullable)error
andreas@272
   163
{
dirk@519
   164
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@531
   165
    return [session
dirk@531
   166
            trustwordsForFingerprint:fingerprint
dirk@531
   167
            languageID:languageID
dirk@531
   168
            shortened:shortened
dirk@531
   169
            error:error];
andreas@272
   170
}
andreas@272
   171
dirk@535
   172
- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
andreas@272
   173
{
dirk@519
   174
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   175
    return [session mySelf:identity error:error];
andreas@272
   176
}
andreas@272
   177
dirk@536
   178
- (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
dirk@536
   179
                 error:(NSError * _Nullable * _Nullable)error
andreas@272
   180
{
dirk@519
   181
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   182
    return [session updateIdentity:identity error:error];
andreas@272
   183
}
andreas@272
   184
dirk@535
   185
- (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
dirk@534
   186
                   error:(NSError * _Nullable * _Nullable)error
andreas@272
   187
{
dirk@519
   188
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@534
   189
    return [session trustPersonalKey:identity error:error];
andreas@272
   190
}
andreas@272
   191
dirk@536
   192
- (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
dirk@536
   193
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   194
{
dirk@519
   195
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@536
   196
    return [session keyMistrusted:identity error:error];
andreas@272
   197
}
andreas@272
   198
dirk@545
   199
- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
dirk@545
   200
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   201
{
dirk@519
   202
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@545
   203
    return [session keyResetTrust:identity error:error];
andreas@272
   204
}
andreas@272
   205
andreas@272
   206
#pragma mark Internal API (testing etc.)
andreas@272
   207
dirk@551
   208
- (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error
andreas@272
   209
{
dirk@551
   210
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@551
   211
    return [session importKey:keydata error:error];
andreas@272
   212
}
andreas@272
   213
dirk@553
   214
- (BOOL)logTitle:(NSString * _Nonnull)title
dirk@553
   215
          entity:(NSString * _Nonnull)entity
dirk@553
   216
     description:(NSString * _Nullable)description
dirk@553
   217
         comment:(NSString * _Nullable)comment
dirk@553
   218
           error:(NSError * _Nullable * _Nullable)error
andreas@272
   219
{
dirk@553
   220
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@553
   221
    return [session
dirk@553
   222
            logTitle:title
dirk@553
   223
            entity:entity
dirk@553
   224
            description:description
dirk@553
   225
            comment:comment
dirk@553
   226
            error:error];
andreas@272
   227
}
andreas@272
   228
dirk@552
   229
- (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   230
{
dirk@552
   231
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@552
   232
    return [session getLogWithError:error];
andreas@272
   233
}
andreas@272
   234
dirk@535
   235
- (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
dirk@535
   236
                                     identity2:(PEPIdentity * _Nonnull)identity2
dirk@535
   237
                                      language:(NSString * _Nullable)language
dirk@535
   238
                                          full:(BOOL)full
dirk@558
   239
                                         error:(NSError * _Nullable * _Nullable)error
andreas@272
   240
{
dirk@558
   241
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@558
   242
    return [session getTrustwordsIdentity1:identity1
dirk@558
   243
                                 identity2:identity2
dirk@558
   244
                                  language:language
dirk@558
   245
                                      full:full
dirk@558
   246
                                     error:error];
andreas@272
   247
}
andreas@272
   248
dirk@560
   249
- (NSArray<PEPLanguage *> * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   250
{
dirk@560
   251
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@560
   252
    return [session languageListWithError:error];
andreas@272
   253
}
andreas@272
   254
dirk@565
   255
- (BOOL)undoLastMistrustWithError:(NSError * _Nullable * _Nullable)error;
andreas@272
   256
{
dirk@565
   257
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@565
   258
    return [session undoLastMistrustWithError:error];
andreas@272
   259
}
andreas@272
   260
dirk@417
   261
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   262
{
dirk@566
   263
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@566
   264
    return [session ratingFromString:string];
dirk@417
   265
}
dirk@417
   266
dirk@417
   267
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   268
{
dirk@566
   269
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@566
   270
    return [session stringFromRating:rating];
dirk@417
   271
}
dirk@417
   272
dirk@567
   273
- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@567
   274
                            error:(NSError * _Nullable * _Nullable)error
dirk@427
   275
{
dirk@567
   276
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@567
   277
    return [session isPEPUser:identity error:error];
dirk@427
   278
}
dirk@427
   279
dirk@501
   280
- (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   281
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   282
{
dirk@501
   283
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@501
   284
    return [session setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   285
}
dirk@501
   286
andreas@270
   287
@end