pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Thu, 08 Mar 2018 12:10:17 +0100
changeset 514 1401bf4dd539
parent 501 739ae7e9693b
child 515 3fea38d290ab
permissions -rw-r--r--
IOSAD-72 decryptMessage using NSError
     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 - (BOOL)decryptMessageDict:(nonnull PEPDict *)src
    25                       dest:(PEPDict * _Nullable * _Nullable)dst
    26                     rating:(PEP_rating * _Nullable)rating
    27                       keys:(PEPStringList * _Nullable * _Nullable)keys
    28                      error:(NSError * _Nullable * _Nullable)error
    29 {
    30     return [PEPSession decryptMessageDict:src dest:dst rating:rating keys:keys error:error];
    31 }
    32 
    33 - (BOOL)decryptMessage:(nonnull PEPMessage *)src
    34                   dest:(PEPMessage * _Nullable * _Nullable)dst
    35                 rating:(PEP_rating * _Nullable)rating
    36                   keys:(PEPStringList * _Nullable * _Nullable)keys
    37                  error:(NSError * _Nullable * _Nullable)error
    38 {
    39     return [PEPSession decryptMessage:src dest:dst rating:rating keys:keys error:error];
    40 }
    41 
    42 - (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
    43 {
    44     return [PEPSession reEvaluateMessageRating:src];
    45 }
    46 
    47 - (PEP_rating)reEvaluateRatingForMessage:(nonnull PEPMessage *)src
    48 {
    49     return [PEPSession reEvaluateRatingForMessage:src];
    50 }
    51 
    52 - (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
    53                            extra:(nullable PEPStringList *)keys
    54                        encFormat:(PEP_enc_format)encFormat
    55                             dest:(PEPDict * _Nullable * _Nullable)dst
    56 {
    57     return [PEPSession encryptMessageDict:src extra:keys encFormat:encFormat dest:dst];
    58 }
    59 
    60 - (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
    61                        extra:(nullable PEPStringList *)keys
    62                         dest:(PEPMessage * _Nullable * _Nullable)dst
    63 {
    64     return [PEPSession encryptMessage:src extra:keys dest:dst];
    65 }
    66 
    67 - (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
    68                        extra:(nullable PEPStringList *)keys
    69                    encFormat:(PEP_enc_format)encFormat
    70                         dest:(PEPMessage * _Nullable * _Nullable)dst
    71 {
    72     return [PEPSession encryptMessage:src extra:keys encFormat:encFormat dest:dst];
    73 }
    74 
    75 - (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
    76                         identity:(nonnull PEPIdentity *)identity
    77                             dest:(PEPDict * _Nullable * _Nullable)dst
    78 {
    79     return [PEPSession encryptMessageDict:src identity:identity dest:dst];
    80 }
    81 
    82 - (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
    83                     identity:(nonnull PEPIdentity *)identity
    84                         dest:(PEPMessage * _Nullable * _Nullable)dst
    85 {
    86     return [PEPSession encryptMessage:src identity:identity dest:dst];
    87 }
    88 
    89 - (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
    90 {
    91     return [PEPSession outgoingColorForMessage:message];
    92 }
    93 
    94 - (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
    95 {
    96     return [PEPSession identityRating:identity];
    97 }
    98 
    99 - (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
   100                       shortened:(BOOL)shortened
   101 {
   102     return [PEPSession trustwords:fpr forLanguage:languageID shortened:shortened];
   103 }
   104 
   105 - (void)mySelf:(nonnull PEPIdentity *)identity
   106 {
   107     [PEPSession mySelf:identity];
   108 }
   109 
   110 - (void)updateIdentity:(nonnull PEPIdentity *)identity
   111 {
   112     if (identity.isOwn) {
   113         [PEPSession mySelf:identity];
   114     } else {
   115         [PEPSession updateIdentity:identity];
   116     }
   117 }
   118 
   119 - (void)trustPersonalKey:(nonnull PEPIdentity *)identity
   120 {
   121     [PEPSession trustPersonalKey:identity];
   122 }
   123 
   124 - (void)keyMistrusted:(nonnull PEPIdentity *)identity
   125 {
   126     [PEPSession keyMistrusted:identity];
   127 }
   128 
   129 - (void)keyResetTrust:(nonnull PEPIdentity *)identity
   130 {
   131     [PEPSession keyResetTrust:identity];
   132 }
   133 
   134 #pragma mark Internal API (testing etc.)
   135 
   136 - (void)importKey:(nonnull NSString *)keydata
   137 {
   138     [PEPSession importKey:keydata];
   139 }
   140 
   141 - (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
   142      description:(nullable NSString *)description comment:(nullable NSString *)comment
   143 {
   144     [PEPSession logTitle:title entity:entity description:description comment:comment];
   145 }
   146 
   147 - (nullable NSString *)getLog
   148 {
   149     return [PEPSession getLog];
   150 }
   151 
   152 - (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
   153                                     identity2:(nonnull PEPIdentity *)identity2
   154                                      language:(nullable NSString *)language
   155                                          full:(BOOL)full
   156 {
   157     return [PEPSession getTrustwordsIdentity1:identity1
   158                                         identity2:identity2
   159                                          language:language
   160                                              full:full];
   161 }
   162 
   163 - (NSArray<PEPLanguage *> * _Nonnull)languageList
   164 {
   165     return [PEPSession languageList];
   166 }
   167 
   168 - (PEP_STATUS)undoLastMistrust
   169 {
   170     return [PEPSession undoLastMistrust];
   171 }
   172 
   173 - (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   174 {
   175     return [PEPSession ratingFromString:string];
   176 }
   177 
   178 - (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   179 {
   180     return [PEPSession stringFromRating:rating];
   181 }
   182 
   183 - (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
   184 {
   185     return [PEPSession isPEPUser:identity];
   186 }
   187 
   188 - (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   189             error:(NSError * _Nullable * _Nullable)error
   190 {
   191     return [PEPSession setOwnKey:identity fingerprint:fingerprint error:error];
   192 }
   193 
   194 #pragma mark - Static
   195 
   196 + (BOOL)decryptMessageDict:(nonnull PEPDict *)src
   197                       dest:(PEPDict * _Nullable * _Nullable)dst
   198                     rating:(PEP_rating * _Nullable)rating
   199                       keys:(PEPStringList * _Nullable * _Nullable)keys
   200                      error:(NSError * _Nullable * _Nullable)error __deprecated
   201 {
   202     PEPInternalSession *session = [PEPSessionProvider session];
   203     return [session decryptMessageDict:src dest:dst rating:rating keys:keys error:error];
   204 }
   205 
   206 + (BOOL)decryptMessage:(nonnull PEPMessage *)src
   207                   dest:(PEPMessage * _Nullable * _Nullable)dst
   208                 rating:(PEP_rating * _Nullable)rating
   209                   keys:(PEPStringList * _Nullable * _Nullable)keys
   210                  error:(NSError * _Nullable * _Nullable)error
   211 {
   212     PEPInternalSession *session = [PEPSessionProvider session];
   213     return [session decryptMessage:src dest:dst rating:rating keys:keys error:error];
   214 }
   215 
   216 + (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
   217 {
   218     PEPInternalSession *session = [PEPSessionProvider session];
   219     return [session reEvaluateMessageRating:src];
   220 }
   221 
   222 + (PEP_rating)reEvaluateRatingForMessage:(nonnull PEPMessage *)src
   223 {
   224     PEPInternalSession *session = [PEPSessionProvider session];
   225     return [session reEvaluateRatingForMessage:src];
   226 }
   227 
   228 + (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
   229                            extra:(nullable PEPStringList *)keys
   230                        encFormat:(PEP_enc_format)encFormat
   231                             dest:(PEPDict * _Nullable * _Nullable)dst
   232 {
   233     PEPInternalSession *session = [PEPSessionProvider session];
   234     return [session encryptMessageDict:src extra:keys encFormat:encFormat dest:dst];
   235 }
   236 
   237 + (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
   238                            extra:(nullable PEPStringList *)keys
   239                             dest:(PEPMessage * _Nullable * _Nullable)dst
   240 {
   241     PEPInternalSession *session = [PEPSessionProvider session];
   242     return [session encryptMessage:src extra:keys dest:dst];
   243 }
   244 
   245 + (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
   246                        extra:(nullable PEPStringList *)keys
   247                    encFormat:(PEP_enc_format)encFormat
   248                         dest:(PEPMessage * _Nullable * _Nullable)dst
   249 {
   250     PEPInternalSession *session = [PEPSessionProvider session];
   251     return [session encryptMessage:src extra:keys encFormat:encFormat dest:dst];
   252 }
   253 
   254 + (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
   255                         identity:(nonnull PEPIdentity *)identity
   256                             dest:(PEPDict * _Nullable * _Nullable)dst
   257 {
   258     PEPInternalSession *session = [PEPSessionProvider session];
   259     return [session encryptMessageDict:src identity:identity dest:dst];
   260 }
   261 
   262 + (PEP_STATUS)encryptMessage:(nonnull PEPMessage *)src
   263                     identity:(nonnull PEPIdentity *)identity
   264                         dest:(PEPMessage * _Nullable * _Nullable)dst
   265 {
   266     PEPInternalSession *session = [PEPSessionProvider session];
   267     return [session encryptMessage:src identity:identity dest:dst];
   268 }
   269 
   270 + (PEP_rating)outgoingColorForMessage:(nonnull PEPMessage *)message
   271 {
   272     PEPInternalSession *session = [PEPSessionProvider session];
   273     return [session outgoingColorForMessage:message];
   274 }
   275 
   276 + (PEP_rating)identityRating:(nonnull PEPIdentity *)identity
   277 {
   278     PEPInternalSession *session = [PEPSessionProvider session];
   279     return [session identityRating:identity];
   280 }
   281 
   282 + (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
   283                       shortened:(BOOL)shortened
   284 {
   285     PEPInternalSession *session = [PEPSessionProvider session];
   286     return [session trustwords:fpr forLanguage:languageID shortened:shortened];
   287 }
   288 
   289 + (void)mySelf:(nonnull PEPIdentity *)identity
   290 {
   291     PEPInternalSession *session = [PEPSessionProvider session];
   292     [session mySelf:identity];
   293 }
   294 
   295 + (void)updateIdentity:(nonnull PEPIdentity *)identity
   296 {
   297     PEPInternalSession *session = [PEPSessionProvider session];
   298     [session updateIdentity:identity];
   299 }
   300 
   301 + (void)trustPersonalKey:(nonnull PEPIdentity *)identity
   302 {
   303     PEPInternalSession *session = [PEPSessionProvider session];
   304     [session trustPersonalKey:identity];
   305 }
   306 
   307 + (void)keyMistrusted:(nonnull PEPIdentity *)identity
   308 {
   309     PEPInternalSession *session = [PEPSessionProvider session];
   310     [session keyMistrusted:identity];
   311 }
   312 
   313 + (void)keyResetTrust:(nonnull PEPIdentity *)identity
   314 {
   315     PEPInternalSession *session = [PEPSessionProvider session];
   316     [session keyResetTrust:identity];
   317 }
   318 
   319 #pragma mark Internal API (testing etc.)
   320 
   321 + (void)importKey:(nonnull NSString *)keydata
   322 {
   323     PEPInternalSession *session = [PEPSessionProvider session];
   324     [session importKey:keydata];
   325 }
   326 
   327 + (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
   328      description:(nullable NSString *)description comment:(nullable NSString *)comment
   329 {
   330     PEPInternalSession *session = [PEPSessionProvider session];
   331     [session logTitle:title entity:entity description:description comment:comment];
   332 }
   333 
   334 + (nullable NSString *)getLog
   335 {
   336     PEPInternalSession *session = [PEPSessionProvider session];
   337     return [session getLog];
   338 }
   339 
   340 + (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPIdentity *)identity1
   341                                     identity2:(nonnull PEPIdentity *)identity2
   342                                      language:(nullable NSString *)language
   343                                          full:(BOOL)full
   344 {
   345     PEPInternalSession *session = [PEPSessionProvider session];
   346     return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
   347 }
   348 
   349 + (NSArray<PEPLanguage *> * _Nonnull)languageList
   350 {
   351     PEPInternalSession *session = [PEPSessionProvider session];
   352     return [session languageList];
   353 }
   354 
   355 + (PEP_STATUS)undoLastMistrust
   356 {
   357     PEPInternalSession *session = [PEPSessionProvider session];
   358     return [session undoLastMistrust];
   359 }
   360 
   361 + (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   362 {
   363     PEPInternalSession *session = [PEPSessionProvider session];
   364     return [session ratingFromString:string];
   365 }
   366 
   367 + (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   368 {
   369     PEPInternalSession *session = [PEPSessionProvider session];
   370     return [session stringFromRating:rating];
   371 }
   372 
   373 + (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
   374 {
   375     PEPInternalSession *session = [PEPSessionProvider session];
   376     return [session isPEPUser:identity];
   377 }
   378 
   379 + (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   380             error:(NSError * _Nullable * _Nullable)error
   381 {
   382     PEPInternalSession *session = [PEPSessionProvider session];
   383     return [session setOwnKey:identity fingerprint:fingerprint error:error];
   384 }
   385 
   386 @end