pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Sat, 14 Apr 2018 14:19:03 +0200
changeset 573 bc2c03efe133
parent 568 d3c705c9c077
child 574 03a019b2533b
permissions -rw-r--r--
IOSAD-72 outgoingRatingForMessage -> NSNumber
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@557
   112
                                  forSelf:(PEPIdentity * _Nonnull)ownIdentity
dirk@556
   113
                                extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@526
   114
                                   status:(PEP_STATUS * _Nullable)status
dirk@526
   115
                                    error:(NSError * _Nullable * _Nullable)error
andreas@272
   116
{
dirk@519
   117
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@556
   118
    return [session
dirk@556
   119
            encryptMessageDict:messageDict
dirk@557
   120
            forSelf:ownIdentity
dirk@556
   121
            extraKeys:extraKeys
dirk@556
   122
            status:status
dirk@556
   123
            error:error];
andreas@272
   124
}
andreas@272
   125
dirk@535
   126
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
dirk@557
   127
                                 forSelf:(PEPIdentity * _Nonnull)ownIdentity
dirk@556
   128
                               extraKeys:(PEPStringList * _Nullable)extraKeys
dirk@526
   129
                                  status:(PEP_STATUS * _Nullable)status
dirk@526
   130
                                   error:(NSError * _Nullable * _Nullable)error
dirk@381
   131
{
dirk@519
   132
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@556
   133
    return [session
dirk@556
   134
            encryptMessage:message
dirk@557
   135
            forSelf:ownIdentity
dirk@556
   136
            extraKeys:extraKeys
dirk@556
   137
            status:status
dirk@556
   138
            error:error];
dirk@381
   139
}
dirk@381
   140
dirk@573
   141
- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)message
dirk@573
   142
                                           error:(NSError * _Nullable * _Nullable)error
dirk@377
   143
{
dirk@519
   144
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@573
   145
    return [session outgoingRatingForMessage:message error:error];
dirk@377
   146
}
dirk@377
   147
dirk@529
   148
- (BOOL)rating:(PEP_rating * _Nonnull)rating
dirk@530
   149
   forIdentity:(PEPIdentity * _Nonnull)identity
dirk@530
   150
         error:(NSError * _Nullable * _Nullable)error
dirk@530
   151
{
dirk@519
   152
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@529
   153
    return [session rating:rating forIdentity:identity error:error];
andreas@272
   154
}
andreas@272
   155
dirk@531
   156
- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
dirk@531
   157
                                     languageID:(NSString * _Nonnull)languageID
dirk@531
   158
                                      shortened:(BOOL)shortened
dirk@531
   159
                                          error:(NSError * _Nullable * _Nullable)error
andreas@272
   160
{
dirk@519
   161
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@531
   162
    return [session
dirk@531
   163
            trustwordsForFingerprint:fingerprint
dirk@531
   164
            languageID:languageID
dirk@531
   165
            shortened:shortened
dirk@531
   166
            error:error];
andreas@272
   167
}
andreas@272
   168
dirk@535
   169
- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
andreas@272
   170
{
dirk@519
   171
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   172
    return [session mySelf:identity error:error];
andreas@272
   173
}
andreas@272
   174
dirk@536
   175
- (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
dirk@536
   176
                 error:(NSError * _Nullable * _Nullable)error
andreas@272
   177
{
dirk@519
   178
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@532
   179
    return [session updateIdentity:identity error:error];
andreas@272
   180
}
andreas@272
   181
dirk@535
   182
- (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
dirk@534
   183
                   error:(NSError * _Nullable * _Nullable)error
andreas@272
   184
{
dirk@519
   185
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@534
   186
    return [session trustPersonalKey:identity error:error];
andreas@272
   187
}
andreas@272
   188
dirk@536
   189
- (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
dirk@536
   190
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   191
{
dirk@519
   192
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@536
   193
    return [session keyMistrusted:identity error:error];
andreas@272
   194
}
andreas@272
   195
dirk@545
   196
- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
dirk@545
   197
                error:(NSError * _Nullable * _Nullable)error
andreas@272
   198
{
dirk@519
   199
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@545
   200
    return [session keyResetTrust:identity error:error];
andreas@272
   201
}
andreas@272
   202
andreas@272
   203
#pragma mark Internal API (testing etc.)
andreas@272
   204
dirk@551
   205
- (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error
andreas@272
   206
{
dirk@551
   207
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@551
   208
    return [session importKey:keydata error:error];
andreas@272
   209
}
andreas@272
   210
dirk@553
   211
- (BOOL)logTitle:(NSString * _Nonnull)title
dirk@553
   212
          entity:(NSString * _Nonnull)entity
dirk@553
   213
     description:(NSString * _Nullable)description
dirk@553
   214
         comment:(NSString * _Nullable)comment
dirk@553
   215
           error:(NSError * _Nullable * _Nullable)error
andreas@272
   216
{
dirk@553
   217
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@553
   218
    return [session
dirk@553
   219
            logTitle:title
dirk@553
   220
            entity:entity
dirk@553
   221
            description:description
dirk@553
   222
            comment:comment
dirk@553
   223
            error:error];
andreas@272
   224
}
andreas@272
   225
dirk@552
   226
- (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   227
{
dirk@552
   228
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@552
   229
    return [session getLogWithError:error];
andreas@272
   230
}
andreas@272
   231
dirk@535
   232
- (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
dirk@535
   233
                                     identity2:(PEPIdentity * _Nonnull)identity2
dirk@535
   234
                                      language:(NSString * _Nullable)language
dirk@535
   235
                                          full:(BOOL)full
dirk@558
   236
                                         error:(NSError * _Nullable * _Nullable)error
andreas@272
   237
{
dirk@558
   238
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@558
   239
    return [session getTrustwordsIdentity1:identity1
dirk@558
   240
                                 identity2:identity2
dirk@558
   241
                                  language:language
dirk@558
   242
                                      full:full
dirk@558
   243
                                     error:error];
andreas@272
   244
}
andreas@272
   245
dirk@560
   246
- (NSArray<PEPLanguage *> * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error
andreas@272
   247
{
dirk@560
   248
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@560
   249
    return [session languageListWithError:error];
andreas@272
   250
}
andreas@272
   251
dirk@565
   252
- (BOOL)undoLastMistrustWithError:(NSError * _Nullable * _Nullable)error;
andreas@272
   253
{
dirk@565
   254
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@565
   255
    return [session undoLastMistrustWithError:error];
andreas@272
   256
}
andreas@272
   257
dirk@417
   258
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
dirk@417
   259
{
dirk@566
   260
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@566
   261
    return [session ratingFromString:string];
dirk@417
   262
}
dirk@417
   263
dirk@417
   264
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
dirk@417
   265
{
dirk@566
   266
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@566
   267
    return [session stringFromRating:rating];
dirk@417
   268
}
dirk@417
   269
dirk@567
   270
- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
dirk@567
   271
                            error:(NSError * _Nullable * _Nullable)error
dirk@427
   272
{
dirk@567
   273
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@567
   274
    return [session isPEPUser:identity error:error];
dirk@427
   275
}
dirk@427
   276
dirk@501
   277
- (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
dirk@501
   278
            error:(NSError * _Nullable * _Nullable)error
dirk@501
   279
{
dirk@501
   280
    PEPInternalSession *session = [PEPSessionProvider session];
dirk@501
   281
    return [session setOwnKey:identity fingerprint:fingerprint error:error];
dirk@501
   282
}
dirk@501
   283
andreas@270
   284
@end