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