pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Thu, 22 Mar 2018 15:38:12 +0100
changeset 551 6b7914602bc6
parent 545 7217e3c844e0
child 552 0f362cd2de6a
permissions -rw-r--r--
IOSAD-72 importKey error handling
     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:(PEPDict * _Nonnull)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:(PEPMessage * _Nonnull)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:(PEPDict * _Nonnull)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:(PEPMessage * _Nonnull)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:(PEPDict * _Nonnull)messageDict
    73                                     extraKeys:(PEPStringList * _Nullable)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:(PEPMessage * _Nonnull)message
    88                                extraKeys:(PEPStringList * _Nullable)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:(PEPMessage * _Nonnull)message
   103                                extraKeys:(PEPStringList * _Nullable)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:(PEPDict * _Nonnull)messageDict
   112                                  identity:(PEPIdentity * _Nonnull)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:(PEPMessage * _Nonnull)message
   121                                 identity:(PEPIdentity * _Nonnull)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:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
   159 {
   160     PEPInternalSession *session = [PEPSessionProvider session];
   161     return [session mySelf:identity error:error];
   162 }
   163 
   164 - (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
   165                  error:(NSError * _Nullable * _Nullable)error
   166 {
   167     PEPInternalSession *session = [PEPSessionProvider session];
   168     return [session updateIdentity:identity error:error];
   169 }
   170 
   171 - (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
   172                    error:(NSError * _Nullable * _Nullable)error
   173 {
   174     PEPInternalSession *session = [PEPSessionProvider session];
   175     return [session trustPersonalKey:identity error:error];
   176 }
   177 
   178 - (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
   179                 error:(NSError * _Nullable * _Nullable)error
   180 {
   181     PEPInternalSession *session = [PEPSessionProvider session];
   182     return [session keyMistrusted:identity error:error];
   183 }
   184 
   185 - (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
   186                 error:(NSError * _Nullable * _Nullable)error
   187 {
   188     PEPInternalSession *session = [PEPSessionProvider session];
   189     return [session keyResetTrust:identity error:error];
   190 }
   191 
   192 #pragma mark Internal API (testing etc.)
   193 
   194 - (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error
   195 {
   196     PEPInternalSession *session = [PEPSessionProvider session];
   197     return [session importKey:keydata error:error];
   198 }
   199 
   200 - (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
   201      description:(NSString * _Nullable)description comment:(NSString * _Nullable)comment
   202 {
   203     [PEPSession logTitle:title entity:entity description:description comment:comment];
   204 }
   205 
   206 - (NSString * _Nullable)getLog
   207 {
   208     return [PEPSession getLog];
   209 }
   210 
   211 - (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   212                                      identity2:(PEPIdentity * _Nonnull)identity2
   213                                       language:(NSString * _Nullable)language
   214                                           full:(BOOL)full
   215 {
   216     return [PEPSession getTrustwordsIdentity1:identity1
   217                                         identity2:identity2
   218                                          language:language
   219                                              full:full];
   220 }
   221 
   222 - (NSArray<PEPLanguage *> * _Nonnull)languageList
   223 {
   224     return [PEPSession languageList];
   225 }
   226 
   227 - (PEP_STATUS)undoLastMistrust
   228 {
   229     return [PEPSession undoLastMistrust];
   230 }
   231 
   232 - (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   233 {
   234     return [PEPSession ratingFromString:string];
   235 }
   236 
   237 - (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   238 {
   239     return [PEPSession stringFromRating:rating];
   240 }
   241 
   242 - (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
   243 {
   244     return [PEPSession isPEPUser:identity];
   245 }
   246 
   247 - (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   248             error:(NSError * _Nullable * _Nullable)error
   249 {
   250     return [PEPSession setOwnKey:identity fingerprint:fingerprint error:error];
   251 }
   252 
   253 #pragma mark Internal API (testing etc.)
   254 
   255 + (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
   256      description:(NSString * _Nullable)description comment:(NSString * _Nullable)comment
   257 {
   258     PEPInternalSession *session = [PEPSessionProvider session];
   259     [session logTitle:title entity:entity description:description comment:comment];
   260 }
   261 
   262 + (NSString * _Nullable)getLog
   263 {
   264     PEPInternalSession *session = [PEPSessionProvider session];
   265     return [session getLog];
   266 }
   267 
   268 + (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   269                                      identity2:(PEPIdentity * _Nonnull)identity2
   270                                       language:(NSString * _Nullable)language
   271                                           full:(BOOL)full
   272 {
   273     PEPInternalSession *session = [PEPSessionProvider session];
   274     return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
   275 }
   276 
   277 + (NSArray<PEPLanguage *> * _Nonnull)languageList
   278 {
   279     PEPInternalSession *session = [PEPSessionProvider session];
   280     return [session languageList];
   281 }
   282 
   283 + (PEP_STATUS)undoLastMistrust
   284 {
   285     PEPInternalSession *session = [PEPSessionProvider session];
   286     return [session undoLastMistrust];
   287 }
   288 
   289 + (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   290 {
   291     PEPInternalSession *session = [PEPSessionProvider session];
   292     return [session ratingFromString:string];
   293 }
   294 
   295 + (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   296 {
   297     PEPInternalSession *session = [PEPSessionProvider session];
   298     return [session stringFromRating:rating];
   299 }
   300 
   301 + (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
   302 {
   303     PEPInternalSession *session = [PEPSessionProvider session];
   304     return [session isPEPUser:identity];
   305 }
   306 
   307 + (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   308             error:(NSError * _Nullable * _Nullable)error
   309 {
   310     PEPInternalSession *session = [PEPSessionProvider session];
   311     return [session setOwnKey:identity fingerprint:fingerprint error:error];
   312 }
   313 
   314 @end