pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Fri, 21 Sep 2018 07:15:40 +0200
branchIOSAD-101
changeset 666 031f0676ddec
parent 660 3107cd86f326
parent 665 9f2c780129c4
permissions -rw-r--r--
IOSAD-101 merge default
     1 //
     2 //  PEPSession.m
     3 //  pEpObjCAdapter
     4 //
     5 //  Created by Andreas Buff on 11.10.17.
     6 //  Copyright © 2017 p≡p. All rights reserved.
     7 //
     8 
     9 #import "PEPSession.h"
    10 
    11 #import "PEPInternalSession.h"
    12 #import "PEPSessionProvider.h"
    13 #import "PEPIdentity.h"
    14 
    15 @implementation PEPSession
    16 
    17 #pragma mark - Public API
    18 
    19 + (void)cleanup
    20 {
    21     [PEPSessionProvider cleanup];
    22 }
    23 
    24 - (PEPDict * _Nullable)decryptMessageDict:(PEPMutableDict * _Nonnull)messageDict
    25                                     flags:(PEP_decrypt_flags * _Nullable)flags
    26                                    rating:(PEP_rating * _Nullable)rating
    27                                 extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
    28                                    status:(PEP_STATUS * _Nullable)status
    29                                     error:(NSError * _Nullable * _Nullable)error
    30 {
    31     PEPInternalSession *session = [PEPSessionProvider session];
    32     return [session
    33             decryptMessageDict:messageDict
    34             flags:flags
    35             rating:rating
    36             extraKeys:extraKeys
    37             status:status
    38             error:error];
    39 }
    40 
    41 - (PEPMessage * _Nullable)decryptMessage:(PEPMessage * _Nonnull)message
    42                                    flags:(PEP_decrypt_flags * _Nullable)flags
    43                                   rating:(PEP_rating * _Nullable)rating
    44                                extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
    45                                   status:(PEP_STATUS * _Nullable)status
    46                                    error:(NSError * _Nullable * _Nullable)error
    47 {
    48     PEPInternalSession *session = [PEPSessionProvider session];
    49     return [session
    50             decryptMessage:message
    51             flags:flags
    52             rating:rating
    53             extraKeys:extraKeys
    54             status:status
    55             error:error];
    56 }
    57 
    58 - (BOOL)reEvaluateMessageDict:(PEPDict * _Nonnull)messageDict
    59                      xKeyList:(PEPStringList * _Nullable)xKeyList
    60                        rating:(PEP_rating * _Nonnull)rating
    61                        status:(PEP_STATUS * _Nullable)status
    62                         error:(NSError * _Nullable * _Nullable)error
    63 {
    64     PEPInternalSession *session = [PEPSessionProvider session];
    65     return [session reEvaluateMessageDict:messageDict
    66                                  xKeyList:xKeyList
    67                                    rating:rating
    68                                    status:status
    69                                     error:error];
    70 }
    71 
    72 - (BOOL)reEvaluateMessage:(PEPMessage * _Nonnull)message
    73                  xKeyList:(PEPStringList * _Nullable)xKeyList
    74                    rating:(PEP_rating * _Nonnull)rating
    75                    status:(PEP_STATUS * _Nullable)status
    76                     error:(NSError * _Nullable * _Nullable)error
    77 {
    78     PEPInternalSession *session = [PEPSessionProvider session];
    79     return [session reEvaluateMessage:message
    80                              xKeyList:xKeyList
    81                                rating:rating
    82                                status:status
    83                                 error:error];
    84 }
    85 
    86 - (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
    87                                     extraKeys:(PEPStringList * _Nullable)extraKeys
    88                                 encFormat:(PEP_enc_format)encFormat
    89                                    status:(PEP_STATUS * _Nullable)status
    90                                     error:(NSError * _Nullable * _Nullable)error
    91 {
    92     PEPInternalSession *session = [PEPSessionProvider session];
    93     return [session
    94             encryptMessageDict:messageDict
    95             extraKeys:extraKeys
    96             encFormat:encFormat
    97             status:status
    98             error:error];
    99 }
   100 
   101 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   102                                extraKeys:(PEPStringList * _Nullable)extraKeys
   103                                encFormat:(PEP_enc_format)encFormat
   104                                   status:(PEP_STATUS * _Nullable)status
   105                                    error:(NSError * _Nullable * _Nullable)error
   106 {
   107     PEPInternalSession *session = [PEPSessionProvider session];
   108     return [session
   109             encryptMessage:message
   110             extraKeys:extraKeys
   111             encFormat:encFormat
   112             status:status
   113             error:error];
   114 }
   115 
   116 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   117                                extraKeys:(PEPStringList * _Nullable)extraKeys
   118                                   status:(PEP_STATUS * _Nullable)status
   119                                    error:(NSError * _Nullable * _Nullable)error
   120 {
   121     PEPInternalSession *session = [PEPSessionProvider session];
   122     return [session encryptMessage:message extraKeys:extraKeys status:status error:error];
   123 }
   124 
   125 - (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
   126                                   forSelf:(PEPIdentity * _Nonnull)ownIdentity
   127                                 extraKeys:(PEPStringList * _Nullable)extraKeys
   128                                    status:(PEP_STATUS * _Nullable)status
   129                                     error:(NSError * _Nullable * _Nullable)error
   130 {
   131     PEPInternalSession *session = [PEPSessionProvider session];
   132     return [session
   133             encryptMessageDict:messageDict
   134             forSelf:ownIdentity
   135             extraKeys:extraKeys
   136             status:status
   137             error:error];
   138 }
   139 
   140 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   141                                  forSelf:(PEPIdentity * _Nonnull)ownIdentity
   142                                extraKeys:(PEPStringList * _Nullable)extraKeys
   143                                   status:(PEP_STATUS * _Nullable)status
   144                                    error:(NSError * _Nullable * _Nullable)error
   145 {
   146     PEPInternalSession *session = [PEPSessionProvider session];
   147     return [session
   148             encryptMessage:message
   149             forSelf:ownIdentity
   150             extraKeys:extraKeys
   151             status:status
   152             error:error];
   153 }
   154 
   155 - (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
   156                                     toFpr:(NSString * _Nonnull)toFpr
   157                                 encFormat:(PEP_enc_format)encFormat
   158                                     flags:(PEP_decrypt_flags)flags
   159                                    status:(PEP_STATUS * _Nullable)status
   160                                     error:(NSError * _Nullable * _Nullable)error __deprecated
   161 {
   162     PEPInternalSession *session = [PEPSessionProvider session];
   163     return [session
   164             encryptMessageDict:messageDict
   165             toFpr:toFpr
   166             encFormat:encFormat
   167             flags:flags
   168             status:status
   169             error:error];
   170 }
   171 
   172 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   173                                    toFpr:(NSString * _Nonnull)toFpr
   174                                encFormat:(PEP_enc_format)encFormat
   175                                    flags:(PEP_decrypt_flags)flags
   176                                   status:(PEP_STATUS * _Nullable)status
   177                                    error:(NSError * _Nullable * _Nullable)error
   178 {
   179     PEPInternalSession *session = [PEPSessionProvider session];
   180     return [session
   181             encryptMessage:message
   182             toFpr:toFpr
   183             encFormat:encFormat
   184             flags:flags
   185             status:status
   186             error:error];
   187 }
   188 
   189 - (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
   190                                            error:(NSError * _Nullable * _Nullable)error
   191 {
   192     PEPInternalSession *session = [PEPSessionProvider session];
   193     return [session outgoingRatingForMessage:theMessage error:error];
   194 }
   195 
   196 - (NSNumber * _Nullable)outgoingRatingPreviewForMessage:(PEPMessage * _Nonnull)theMessage
   197                                                   error:(NSError * _Nullable * _Nullable)error
   198 {
   199     PEPInternalSession *session = [PEPSessionProvider session];
   200     return [session outgoingRatingPreviewForMessage:theMessage error:error];
   201 }
   202 
   203 - (NSNumber * _Nullable)ratingForIdentity:(PEPIdentity * _Nonnull)identity
   204                                     error:(NSError * _Nullable * _Nullable)error
   205 {
   206     PEPInternalSession *session = [PEPSessionProvider session];
   207     return [session ratingForIdentity:identity error:error];
   208 }
   209 
   210 - (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
   211                                      languageID:(NSString * _Nonnull)languageID
   212                                       shortened:(BOOL)shortened
   213                                           error:(NSError * _Nullable * _Nullable)error
   214 {
   215     PEPInternalSession *session = [PEPSessionProvider session];
   216     return [session
   217             trustwordsForFingerprint:fingerprint
   218             languageID:languageID
   219             shortened:shortened
   220             error:error];
   221 }
   222 
   223 - (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
   224 {
   225     PEPInternalSession *session = [PEPSessionProvider session];
   226     return [session mySelf:identity error:error];
   227 }
   228 
   229 - (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
   230                  error:(NSError * _Nullable * _Nullable)error
   231 {
   232     PEPInternalSession *session = [PEPSessionProvider session];
   233     return [session updateIdentity:identity error:error];
   234 }
   235 
   236 - (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
   237                    error:(NSError * _Nullable * _Nullable)error
   238 {
   239     PEPInternalSession *session = [PEPSessionProvider session];
   240     return [session trustPersonalKey:identity error:error];
   241 }
   242 
   243 - (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
   244                 error:(NSError * _Nullable * _Nullable)error
   245 {
   246     PEPInternalSession *session = [PEPSessionProvider session];
   247     return [session keyMistrusted:identity error:error];
   248 }
   249 
   250 - (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
   251                 error:(NSError * _Nullable * _Nullable)error
   252 {
   253     PEPInternalSession *session = [PEPSessionProvider session];
   254     return [session keyResetTrust:identity error:error];
   255 }
   256 
   257 #pragma mark Internal API (testing etc.)
   258 
   259 - (NSArray * _Nullable)importKey:(NSString * _Nonnull)keydata
   260                            error:(NSError * _Nullable * _Nullable)error
   261 {
   262     PEPInternalSession *session = [PEPSessionProvider session];
   263     return [session importKey:keydata error:error];
   264 }
   265 
   266 - (BOOL)logTitle:(NSString * _Nonnull)title
   267           entity:(NSString * _Nonnull)entity
   268      description:(NSString * _Nullable)description
   269          comment:(NSString * _Nullable)comment
   270            error:(NSError * _Nullable * _Nullable)error
   271 {
   272     PEPInternalSession *session = [PEPSessionProvider session];
   273     return [session
   274             logTitle:title
   275             entity:entity
   276             description:description
   277             comment:comment
   278             error:error];
   279 }
   280 
   281 - (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
   282 {
   283     PEPInternalSession *session = [PEPSessionProvider session];
   284     return [session getLogWithError:error];
   285 }
   286 
   287 - (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   288                                      identity2:(PEPIdentity * _Nonnull)identity2
   289                                       language:(NSString * _Nullable)language
   290                                           full:(BOOL)full
   291                                          error:(NSError * _Nullable * _Nullable)error
   292 {
   293     PEPInternalSession *session = [PEPSessionProvider session];
   294     return [session getTrustwordsIdentity1:identity1
   295                                  identity2:identity2
   296                                   language:language
   297                                       full:full
   298                                      error:error];
   299 }
   300 
   301 - (NSArray<PEPLanguage *> * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error
   302 {
   303     PEPInternalSession *session = [PEPSessionProvider session];
   304     return [session languageListWithError:error];
   305 }
   306 
   307 - (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   308 {
   309     PEPInternalSession *session = [PEPSessionProvider session];
   310     return [session ratingFromString:string];
   311 }
   312 
   313 - (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   314 {
   315     PEPInternalSession *session = [PEPSessionProvider session];
   316     return [session stringFromRating:rating];
   317 }
   318 
   319 - (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
   320                             error:(NSError * _Nullable * _Nullable)error
   321 {
   322     PEPInternalSession *session = [PEPSessionProvider session];
   323     return [session isPEPUser:identity error:error];
   324 }
   325 
   326 - (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   327             error:(NSError * _Nullable * _Nullable)error
   328 {
   329     PEPInternalSession *session = [PEPSessionProvider session];
   330     return [session setOwnKey:identity fingerprint:fingerprint error:error];
   331 }
   332 
   333 - (void)configurePassiveModeEnabled:(BOOL)enabled
   334 {
   335     PEPInternalSession *session = [PEPSessionProvider session];
   336     return [session configurePassiveModeEnabled:enabled];
   337 }
   338 
   339 - (BOOL)keyReset:(PEPIdentity * _Nullable)identity
   340      fingerprint:(NSString * _Nullable)fingerprint
   341            error:(NSError * _Nullable * _Nullable)error
   342 {
   343     PEPInternalSession *session = [PEPSessionProvider session];
   344     return [session keyReset:identity fingerprint:fingerprint error:error];
   345 }
   346 
   347 @end