pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Wed, 13 Jun 2018 09:53:42 +0200
changeset 624 fb142cf04649
parent 611 35c2fdba3af6
child 629 7e6343055e4d
permissions -rw-r--r--
IOSAD-94 wrap config_passive_mode
     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                        rating:(PEP_rating * _Nullable)rating
    60                        status:(PEP_STATUS * _Nullable)status
    61                         error:(NSError * _Nullable * _Nullable)error
    62 {
    63     PEPInternalSession *session = [PEPSessionProvider session];
    64     return [session reEvaluateMessageDict:messageDict rating:rating status:status error:error];
    65 }
    66 
    67 - (BOOL)reEvaluateMessage:(PEPMessage * _Nonnull)message
    68                    rating:(PEP_rating * _Nullable)rating
    69                    status:(PEP_STATUS * _Nullable)status
    70                     error:(NSError * _Nullable * _Nullable)error
    71 {
    72     PEPInternalSession *session = [PEPSessionProvider session];
    73     return [session reEvaluateMessage:message rating:rating status:status error:error];
    74 }
    75 
    76 - (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
    77                                     extraKeys:(PEPStringList * _Nullable)extraKeys
    78                                 encFormat:(PEP_enc_format)encFormat
    79                                    status:(PEP_STATUS * _Nullable)status
    80                                     error:(NSError * _Nullable * _Nullable)error
    81 {
    82     PEPInternalSession *session = [PEPSessionProvider session];
    83     return [session
    84             encryptMessageDict:messageDict
    85             extraKeys:extraKeys
    86             encFormat:encFormat
    87             status:status
    88             error:error];
    89 }
    90 
    91 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
    92                                extraKeys:(PEPStringList * _Nullable)extraKeys
    93                                encFormat:(PEP_enc_format)encFormat
    94                                   status:(PEP_STATUS * _Nullable)status
    95                                    error:(NSError * _Nullable * _Nullable)error
    96 {
    97     PEPInternalSession *session = [PEPSessionProvider session];
    98     return [session
    99             encryptMessage:message
   100             extraKeys:extraKeys
   101             encFormat:encFormat
   102             status:status
   103             error:error];
   104 }
   105 
   106 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   107                                extraKeys:(PEPStringList * _Nullable)extraKeys
   108                                   status:(PEP_STATUS * _Nullable)status
   109                                    error:(NSError * _Nullable * _Nullable)error
   110 {
   111     PEPInternalSession *session = [PEPSessionProvider session];
   112     return [session encryptMessage:message extraKeys:extraKeys status:status error:error];
   113 }
   114 
   115 - (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
   116                                   forSelf:(PEPIdentity * _Nonnull)ownIdentity
   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
   123             encryptMessageDict:messageDict
   124             forSelf:ownIdentity
   125             extraKeys:extraKeys
   126             status:status
   127             error:error];
   128 }
   129 
   130 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   131                                  forSelf:(PEPIdentity * _Nonnull)ownIdentity
   132                                extraKeys:(PEPStringList * _Nullable)extraKeys
   133                                   status:(PEP_STATUS * _Nullable)status
   134                                    error:(NSError * _Nullable * _Nullable)error
   135 {
   136     PEPInternalSession *session = [PEPSessionProvider session];
   137     return [session
   138             encryptMessage:message
   139             forSelf:ownIdentity
   140             extraKeys:extraKeys
   141             status:status
   142             error:error];
   143 }
   144 
   145 - (PEPDict * _Nullable)encryptMessageDict:(PEPDict * _Nonnull)messageDict
   146                                     toFpr:(NSString * _Nonnull)toFpr
   147                                 encFormat:(PEP_enc_format)encFormat
   148                                     flags:(PEP_decrypt_flags)flags
   149                                    status:(PEP_STATUS * _Nullable)status
   150                                     error:(NSError * _Nullable * _Nullable)error __deprecated
   151 {
   152     PEPInternalSession *session = [PEPSessionProvider session];
   153     return [session
   154             encryptMessageDict:messageDict
   155             toFpr:toFpr
   156             encFormat:encFormat
   157             flags:flags
   158             status:status
   159             error:error];
   160 }
   161 
   162 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   163                                    toFpr:(NSString * _Nonnull)toFpr
   164                                encFormat:(PEP_enc_format)encFormat
   165                                    flags:(PEP_decrypt_flags)flags
   166                                   status:(PEP_STATUS * _Nullable)status
   167                                    error:(NSError * _Nullable * _Nullable)error
   168 {
   169     PEPInternalSession *session = [PEPSessionProvider session];
   170     return [session
   171             encryptMessage:message
   172             toFpr:toFpr
   173             encFormat:encFormat
   174             flags:flags
   175             status:status
   176             error:error];
   177 }
   178 
   179 - (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)message
   180                                            error:(NSError * _Nullable * _Nullable)error
   181 {
   182     PEPInternalSession *session = [PEPSessionProvider session];
   183     return [session outgoingRatingForMessage:message error:error];
   184 }
   185 
   186 - (NSNumber * _Nullable)ratingForIdentity:(PEPIdentity * _Nonnull)identity
   187                                     error:(NSError * _Nullable * _Nullable)error
   188 {
   189     PEPInternalSession *session = [PEPSessionProvider session];
   190     return [session ratingForIdentity:identity error:error];
   191 }
   192 
   193 - (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
   194                                      languageID:(NSString * _Nonnull)languageID
   195                                       shortened:(BOOL)shortened
   196                                           error:(NSError * _Nullable * _Nullable)error
   197 {
   198     PEPInternalSession *session = [PEPSessionProvider session];
   199     return [session
   200             trustwordsForFingerprint:fingerprint
   201             languageID:languageID
   202             shortened:shortened
   203             error:error];
   204 }
   205 
   206 - (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
   207 {
   208     PEPInternalSession *session = [PEPSessionProvider session];
   209     return [session mySelf:identity error:error];
   210 }
   211 
   212 - (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
   213                  error:(NSError * _Nullable * _Nullable)error
   214 {
   215     PEPInternalSession *session = [PEPSessionProvider session];
   216     return [session updateIdentity:identity error:error];
   217 }
   218 
   219 - (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
   220                    error:(NSError * _Nullable * _Nullable)error
   221 {
   222     PEPInternalSession *session = [PEPSessionProvider session];
   223     return [session trustPersonalKey:identity error:error];
   224 }
   225 
   226 - (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
   227                 error:(NSError * _Nullable * _Nullable)error
   228 {
   229     PEPInternalSession *session = [PEPSessionProvider session];
   230     return [session keyMistrusted:identity error:error];
   231 }
   232 
   233 - (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
   234                 error:(NSError * _Nullable * _Nullable)error
   235 {
   236     PEPInternalSession *session = [PEPSessionProvider session];
   237     return [session keyResetTrust:identity error:error];
   238 }
   239 
   240 #pragma mark Internal API (testing etc.)
   241 
   242 - (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error
   243 {
   244     PEPInternalSession *session = [PEPSessionProvider session];
   245     return [session importKey:keydata error:error];
   246 }
   247 
   248 - (BOOL)logTitle:(NSString * _Nonnull)title
   249           entity:(NSString * _Nonnull)entity
   250      description:(NSString * _Nullable)description
   251          comment:(NSString * _Nullable)comment
   252            error:(NSError * _Nullable * _Nullable)error
   253 {
   254     PEPInternalSession *session = [PEPSessionProvider session];
   255     return [session
   256             logTitle:title
   257             entity:entity
   258             description:description
   259             comment:comment
   260             error:error];
   261 }
   262 
   263 - (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
   264 {
   265     PEPInternalSession *session = [PEPSessionProvider session];
   266     return [session getLogWithError:error];
   267 }
   268 
   269 - (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   270                                      identity2:(PEPIdentity * _Nonnull)identity2
   271                                       language:(NSString * _Nullable)language
   272                                           full:(BOOL)full
   273                                          error:(NSError * _Nullable * _Nullable)error
   274 {
   275     PEPInternalSession *session = [PEPSessionProvider session];
   276     return [session getTrustwordsIdentity1:identity1
   277                                  identity2:identity2
   278                                   language:language
   279                                       full:full
   280                                      error:error];
   281 }
   282 
   283 - (NSArray<PEPLanguage *> * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error
   284 {
   285     PEPInternalSession *session = [PEPSessionProvider session];
   286     return [session languageListWithError:error];
   287 }
   288 
   289 - (BOOL)undoLastMistrustWithError:(NSError * _Nullable * _Nullable)error;
   290 {
   291     PEPInternalSession *session = [PEPSessionProvider session];
   292     return [session undoLastMistrustWithError:error];
   293 }
   294 
   295 - (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   296 {
   297     PEPInternalSession *session = [PEPSessionProvider session];
   298     return [session ratingFromString:string];
   299 }
   300 
   301 - (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   302 {
   303     PEPInternalSession *session = [PEPSessionProvider session];
   304     return [session stringFromRating:rating];
   305 }
   306 
   307 - (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
   308                             error:(NSError * _Nullable * _Nullable)error
   309 {
   310     PEPInternalSession *session = [PEPSessionProvider session];
   311     return [session isPEPUser:identity error:error];
   312 }
   313 
   314 - (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   315             error:(NSError * _Nullable * _Nullable)error
   316 {
   317     PEPInternalSession *session = [PEPSessionProvider session];
   318     return [session setOwnKey:identity fingerprint:fingerprint error:error];
   319 }
   320 
   321 - (void)configurePassiveModeEnabled:(BOOL)enabled
   322 {
   323     PEPInternalSession *session = [PEPSessionProvider session];
   324     return [session configurePassiveModeEnabled:enabled];
   325 }
   326 
   327 @end