pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Fri, 06 Apr 2018 09:13:32 +0200
changeset 556 8f0dfa74c08b
parent 553 3d19b5814b15
child 557 7cf2f6710453
permissions -rw-r--r--
IOSAD-90 extraKeys for encrypt to self
     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                                 extraKeys:(PEPStringList * _Nullable)extraKeys
   114                                    status:(PEP_STATUS * _Nullable)status
   115                                     error:(NSError * _Nullable * _Nullable)error
   116 {
   117     PEPInternalSession *session = [PEPSessionProvider session];
   118     return [session
   119             encryptMessageDict:messageDict
   120             identity:identity
   121             extraKeys:extraKeys
   122             status:status
   123             error:error];
   124 }
   125 
   126 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   127                                 identity:(PEPIdentity * _Nonnull)identity
   128                                extraKeys:(PEPStringList * _Nullable)extraKeys
   129                                   status:(PEP_STATUS * _Nullable)status
   130                                    error:(NSError * _Nullable * _Nullable)error
   131 {
   132     PEPInternalSession *session = [PEPSessionProvider session];
   133     return [session
   134             encryptMessage:message
   135             identity:identity
   136             extraKeys:extraKeys
   137             status:status
   138             error:error];
   139 }
   140 
   141 - (BOOL)outgoingRating:(PEP_rating * _Nonnull)rating
   142             forMessage:(PEPMessage * _Nonnull)message
   143                  error:(NSError * _Nullable * _Nullable)error
   144 {
   145     PEPInternalSession *session = [PEPSessionProvider session];
   146     return [session outgoingRating:rating forMessage:message error:error];
   147 }
   148 
   149 - (BOOL)rating:(PEP_rating * _Nonnull)rating
   150    forIdentity:(PEPIdentity * _Nonnull)identity
   151          error:(NSError * _Nullable * _Nullable)error
   152 {
   153     PEPInternalSession *session = [PEPSessionProvider session];
   154     return [session rating:rating forIdentity:identity error:error];
   155 }
   156 
   157 - (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
   158                                      languageID:(NSString * _Nonnull)languageID
   159                                       shortened:(BOOL)shortened
   160                                           error:(NSError * _Nullable * _Nullable)error
   161 {
   162     PEPInternalSession *session = [PEPSessionProvider session];
   163     return [session
   164             trustwordsForFingerprint:fingerprint
   165             languageID:languageID
   166             shortened:shortened
   167             error:error];
   168 }
   169 
   170 - (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
   171 {
   172     PEPInternalSession *session = [PEPSessionProvider session];
   173     return [session mySelf:identity error:error];
   174 }
   175 
   176 - (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
   177                  error:(NSError * _Nullable * _Nullable)error
   178 {
   179     PEPInternalSession *session = [PEPSessionProvider session];
   180     return [session updateIdentity:identity error:error];
   181 }
   182 
   183 - (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
   184                    error:(NSError * _Nullable * _Nullable)error
   185 {
   186     PEPInternalSession *session = [PEPSessionProvider session];
   187     return [session trustPersonalKey:identity error:error];
   188 }
   189 
   190 - (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
   191                 error:(NSError * _Nullable * _Nullable)error
   192 {
   193     PEPInternalSession *session = [PEPSessionProvider session];
   194     return [session keyMistrusted:identity error:error];
   195 }
   196 
   197 - (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
   198                 error:(NSError * _Nullable * _Nullable)error
   199 {
   200     PEPInternalSession *session = [PEPSessionProvider session];
   201     return [session keyResetTrust:identity error:error];
   202 }
   203 
   204 #pragma mark Internal API (testing etc.)
   205 
   206 - (BOOL)importKey:(NSString * _Nonnull)keydata error:(NSError * _Nullable * _Nullable)error
   207 {
   208     PEPInternalSession *session = [PEPSessionProvider session];
   209     return [session importKey:keydata error:error];
   210 }
   211 
   212 - (BOOL)logTitle:(NSString * _Nonnull)title
   213           entity:(NSString * _Nonnull)entity
   214      description:(NSString * _Nullable)description
   215          comment:(NSString * _Nullable)comment
   216            error:(NSError * _Nullable * _Nullable)error
   217 {
   218     PEPInternalSession *session = [PEPSessionProvider session];
   219     return [session
   220             logTitle:title
   221             entity:entity
   222             description:description
   223             comment:comment
   224             error:error];
   225 }
   226 
   227 - (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
   228 {
   229     PEPInternalSession *session = [PEPSessionProvider session];
   230     return [session getLogWithError:error];
   231 }
   232 
   233 - (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   234                                      identity2:(PEPIdentity * _Nonnull)identity2
   235                                       language:(NSString * _Nullable)language
   236                                           full:(BOOL)full
   237 {
   238     return [PEPSession getTrustwordsIdentity1:identity1
   239                                         identity2:identity2
   240                                          language:language
   241                                              full:full];
   242 }
   243 
   244 - (NSArray<PEPLanguage *> * _Nonnull)languageList
   245 {
   246     return [PEPSession languageList];
   247 }
   248 
   249 - (PEP_STATUS)undoLastMistrust
   250 {
   251     return [PEPSession undoLastMistrust];
   252 }
   253 
   254 - (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   255 {
   256     return [PEPSession ratingFromString:string];
   257 }
   258 
   259 - (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   260 {
   261     return [PEPSession stringFromRating:rating];
   262 }
   263 
   264 - (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
   265 {
   266     return [PEPSession isPEPUser:identity];
   267 }
   268 
   269 - (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   270             error:(NSError * _Nullable * _Nullable)error
   271 {
   272     return [PEPSession setOwnKey:identity fingerprint:fingerprint error:error];
   273 }
   274 
   275 #pragma mark Internal API (testing etc.)
   276 
   277 + (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   278                                      identity2:(PEPIdentity * _Nonnull)identity2
   279                                       language:(NSString * _Nullable)language
   280                                           full:(BOOL)full
   281 {
   282     PEPInternalSession *session = [PEPSessionProvider session];
   283     return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
   284 }
   285 
   286 + (NSArray<PEPLanguage *> * _Nonnull)languageList
   287 {
   288     PEPInternalSession *session = [PEPSessionProvider session];
   289     return [session languageList];
   290 }
   291 
   292 + (PEP_STATUS)undoLastMistrust
   293 {
   294     PEPInternalSession *session = [PEPSessionProvider session];
   295     return [session undoLastMistrust];
   296 }
   297 
   298 + (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   299 {
   300     PEPInternalSession *session = [PEPSessionProvider session];
   301     return [session ratingFromString:string];
   302 }
   303 
   304 + (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   305 {
   306     PEPInternalSession *session = [PEPSessionProvider session];
   307     return [session stringFromRating:rating];
   308 }
   309 
   310 + (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
   311 {
   312     PEPInternalSession *session = [PEPSessionProvider session];
   313     return [session isPEPUser:identity];
   314 }
   315 
   316 + (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   317             error:(NSError * _Nullable * _Nullable)error
   318 {
   319     PEPInternalSession *session = [PEPSessionProvider session];
   320     return [session setOwnKey:identity fingerprint:fingerprint error:error];
   321 }
   322 
   323 @end