pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Thu, 15 Mar 2018 08:04:32 +0100
changeset 532 775c55945da1
parent 531 8bd62764f284
child 534 8cca11a32204
permissions -rw-r--r--
IOSAD-72 error handling in mySelf and updateIdentity
     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:(nonnull PEPDict *)messageDict
    25                                    rating:(PEP_rating * _Nullable)rating
    26                                 extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
    27                                    status:(PEP_STATUS * _Nullable)status
    28                                     error:(NSError * _Nullable * _Nullable)error
    29 {
    30     PEPInternalSession *session = [PEPSessionProvider session];
    31     return [session
    32             decryptMessageDict:messageDict
    33             rating:rating
    34             extraKeys:extraKeys
    35             status:status
    36             error:error];
    37 }
    38 
    39 - (PEPMessage * _Nullable)decryptMessage:(nonnull PEPMessage *)message
    40                                   rating:(PEP_rating * _Nullable)rating
    41                                extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
    42                                   status:(PEP_STATUS * _Nullable)status
    43                                    error:(NSError * _Nullable * _Nullable)error
    44 {
    45     PEPInternalSession *session = [PEPSessionProvider session];
    46     return [session
    47             decryptMessage:message
    48             rating:rating
    49             extraKeys:extraKeys
    50             status:status
    51             error:error];
    52 }
    53 
    54 - (BOOL)reEvaluateMessageDict:(nonnull PEPDict *)messageDict
    55                        rating:(PEP_rating * _Nullable)rating
    56                        status:(PEP_STATUS * _Nullable)status
    57                         error:(NSError * _Nullable * _Nullable)error
    58 {
    59     PEPInternalSession *session = [PEPSessionProvider session];
    60     return [session reEvaluateMessageDict:messageDict rating:rating status:status error:error];
    61 }
    62 
    63 - (BOOL)reEvaluateMessage:(nonnull PEPMessage *)message
    64                    rating:(PEP_rating * _Nullable)rating
    65                    status:(PEP_STATUS * _Nullable)status
    66                     error:(NSError * _Nullable * _Nullable)error
    67 {
    68     PEPInternalSession *session = [PEPSessionProvider session];
    69     return [session reEvaluateMessage:message rating:rating status:status error:error];
    70 }
    71 
    72 - (PEPDict * _Nullable)encryptMessageDict:(nonnull PEPDict *)messageDict
    73                                     extraKeys:(nullable PEPStringList *)extraKeys
    74                                 encFormat:(PEP_enc_format)encFormat
    75                                    status:(PEP_STATUS * _Nullable)status
    76                                     error:(NSError * _Nullable * _Nullable)error
    77 {
    78     PEPInternalSession *session = [PEPSessionProvider session];
    79     return [session
    80             encryptMessageDict:messageDict
    81             extraKeys:extraKeys
    82             encFormat:encFormat
    83             status:status
    84             error:error];
    85 }
    86 
    87 - (PEPMessage * _Nullable)encryptMessage:(nonnull PEPMessage *)message
    88                                extraKeys:(nullable PEPStringList *)extraKeys
    89                                encFormat:(PEP_enc_format)encFormat
    90                                   status:(PEP_STATUS * _Nullable)status
    91                                    error:(NSError * _Nullable * _Nullable)error
    92 {
    93     PEPInternalSession *session = [PEPSessionProvider session];
    94     return [session
    95             encryptMessage:message
    96             extraKeys:extraKeys
    97             encFormat:encFormat
    98             status:status
    99             error:error];
   100 }
   101 
   102 - (PEPMessage * _Nullable)encryptMessage:(nonnull PEPMessage *)message
   103                                extraKeys:(nullable PEPStringList *)extraKeys
   104                                   status:(PEP_STATUS * _Nullable)status
   105                                    error:(NSError * _Nullable * _Nullable)error
   106 {
   107     PEPInternalSession *session = [PEPSessionProvider session];
   108     return [session encryptMessage:message extraKeys:extraKeys status:status error:error];
   109 }
   110 
   111 - (PEPDict * _Nullable)encryptMessageDict:(nonnull PEPDict *)messageDict
   112                                  identity:(nonnull PEPIdentity *)identity
   113                                    status:(PEP_STATUS * _Nullable)status
   114                                     error:(NSError * _Nullable * _Nullable)error
   115 {
   116     PEPInternalSession *session = [PEPSessionProvider session];
   117     return [session encryptMessageDict:messageDict identity:identity status:status error:error];
   118 }
   119 
   120 - (PEPMessage * _Nullable)encryptMessage:(nonnull PEPMessage *)message
   121                                 identity:(nonnull PEPIdentity *)identity
   122                                   status:(PEP_STATUS * _Nullable)status
   123                                    error:(NSError * _Nullable * _Nullable)error
   124 {
   125     PEPInternalSession *session = [PEPSessionProvider session];
   126     return [session encryptMessage:message identity:identity status:status error:error];
   127 }
   128 
   129 - (BOOL)outgoingRating:(PEP_rating * _Nonnull)rating
   130             forMessage:(PEPMessage * _Nonnull)message
   131                  error:(NSError * _Nullable * _Nullable)error
   132 {
   133     PEPInternalSession *session = [PEPSessionProvider session];
   134     return [session outgoingRating:rating forMessage:message error:error];
   135 }
   136 
   137 - (BOOL)rating:(PEP_rating * _Nonnull)rating
   138    forIdentity:(PEPIdentity * _Nonnull)identity
   139          error:(NSError * _Nullable * _Nullable)error
   140 {
   141     PEPInternalSession *session = [PEPSessionProvider session];
   142     return [session rating:rating forIdentity:identity error:error];
   143 }
   144 
   145 - (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
   146                                      languageID:(NSString * _Nonnull)languageID
   147                                       shortened:(BOOL)shortened
   148                                           error:(NSError * _Nullable * _Nullable)error
   149 {
   150     PEPInternalSession *session = [PEPSessionProvider session];
   151     return [session
   152             trustwordsForFingerprint:fingerprint
   153             languageID:languageID
   154             shortened:shortened
   155             error:error];
   156 }
   157 
   158 - (BOOL)mySelf:(nonnull PEPIdentity *)identity error:(NSError * _Nullable * _Nullable)error
   159 {
   160     PEPInternalSession *session = [PEPSessionProvider session];
   161     return [session mySelf:identity error:error];
   162 }
   163 
   164 - (BOOL)updateIdentity:(nonnull PEPIdentity *)identity error:(NSError * _Nullable * _Nullable)error
   165 {
   166     PEPInternalSession *session = [PEPSessionProvider session];
   167     return [session updateIdentity:identity error:error];
   168 }
   169 
   170 - (void)trustPersonalKey:(nonnull PEPIdentity *)identity
   171 {
   172     PEPInternalSession *session = [PEPSessionProvider session];
   173     [session trustPersonalKey:identity];
   174 }
   175 
   176 - (void)keyMistrusted:(nonnull PEPIdentity *)identity
   177 {
   178     PEPInternalSession *session = [PEPSessionProvider session];
   179     [session keyMistrusted:identity];
   180 }
   181 
   182 - (void)keyResetTrust:(nonnull PEPIdentity *)identity
   183 {
   184     PEPInternalSession *session = [PEPSessionProvider session];
   185     [session keyResetTrust:identity];
   186 }
   187 
   188 #pragma mark Internal API (testing etc.)
   189 
   190 - (void)importKey:(nonnull NSString *)keydata
   191 {
   192     [PEPSession importKey:keydata];
   193 }
   194 
   195 - (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
   196      description:(nullable NSString *)description comment:(nullable NSString *)comment
   197 {
   198     [PEPSession logTitle:title entity:entity description:description comment:comment];
   199 }
   200 
   201 - (nullable NSString *)getLog
   202 {
   203     return [PEPSession getLog];
   204 }
   205 
   206 - (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
   207                                     identity2:(nonnull PEPIdentity *)identity2
   208                                      language:(nullable NSString *)language
   209                                          full:(BOOL)full
   210 {
   211     return [PEPSession getTrustwordsIdentity1:identity1
   212                                         identity2:identity2
   213                                          language:language
   214                                              full:full];
   215 }
   216 
   217 - (NSArray<PEPLanguage *> * _Nonnull)languageList
   218 {
   219     return [PEPSession languageList];
   220 }
   221 
   222 - (PEP_STATUS)undoLastMistrust
   223 {
   224     return [PEPSession undoLastMistrust];
   225 }
   226 
   227 - (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   228 {
   229     return [PEPSession ratingFromString:string];
   230 }
   231 
   232 - (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   233 {
   234     return [PEPSession stringFromRating:rating];
   235 }
   236 
   237 - (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
   238 {
   239     return [PEPSession isPEPUser:identity];
   240 }
   241 
   242 - (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   243             error:(NSError * _Nullable * _Nullable)error
   244 {
   245     return [PEPSession setOwnKey:identity fingerprint:fingerprint error:error];
   246 }
   247 
   248 #pragma mark Internal API (testing etc.)
   249 
   250 + (void)importKey:(nonnull NSString *)keydata
   251 {
   252     PEPInternalSession *session = [PEPSessionProvider session];
   253     [session importKey:keydata];
   254 }
   255 
   256 + (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
   257      description:(nullable NSString *)description comment:(nullable NSString *)comment
   258 {
   259     PEPInternalSession *session = [PEPSessionProvider session];
   260     [session logTitle:title entity:entity description:description comment:comment];
   261 }
   262 
   263 + (nullable NSString *)getLog
   264 {
   265     PEPInternalSession *session = [PEPSessionProvider session];
   266     return [session getLog];
   267 }
   268 
   269 + (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
   270                                     identity2:(nonnull PEPIdentity *)identity2
   271                                      language:(nullable NSString *)language
   272                                          full:(BOOL)full
   273 {
   274     PEPInternalSession *session = [PEPSessionProvider session];
   275     return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
   276 }
   277 
   278 + (NSArray<PEPLanguage *> * _Nonnull)languageList
   279 {
   280     PEPInternalSession *session = [PEPSessionProvider session];
   281     return [session languageList];
   282 }
   283 
   284 + (PEP_STATUS)undoLastMistrust
   285 {
   286     PEPInternalSession *session = [PEPSessionProvider session];
   287     return [session undoLastMistrust];
   288 }
   289 
   290 + (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   291 {
   292     PEPInternalSession *session = [PEPSessionProvider session];
   293     return [session ratingFromString:string];
   294 }
   295 
   296 + (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   297 {
   298     PEPInternalSession *session = [PEPSessionProvider session];
   299     return [session stringFromRating:rating];
   300 }
   301 
   302 + (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
   303 {
   304     PEPInternalSession *session = [PEPSessionProvider session];
   305     return [session isPEPUser:identity];
   306 }
   307 
   308 + (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   309             error:(NSError * _Nullable * _Nullable)error
   310 {
   311     PEPInternalSession *session = [PEPSessionProvider session];
   312     return [session setOwnKey:identity fingerprint:fingerprint error:error];
   313 }
   314 
   315 @end