pEpObjCAdapter/PEPSession.m
author Dirk Zimmermann <dirk@pep-project.org>
Fri, 23 Mar 2018 09:38:37 +0100
changeset 552 0f362cd2de6a
parent 551 6b7914602bc6
child 553 3d19b5814b15
permissions -rw-r--r--
IOSAD-72 getLogWithError
     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)getLogWithError:(NSError * _Nullable * _Nullable)error
   207 {
   208     PEPInternalSession *session = [PEPSessionProvider session];
   209     return [session getLogWithError:error];
   210 }
   211 
   212 - (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   213                                      identity2:(PEPIdentity * _Nonnull)identity2
   214                                       language:(NSString * _Nullable)language
   215                                           full:(BOOL)full
   216 {
   217     return [PEPSession getTrustwordsIdentity1:identity1
   218                                         identity2:identity2
   219                                          language:language
   220                                              full:full];
   221 }
   222 
   223 - (NSArray<PEPLanguage *> * _Nonnull)languageList
   224 {
   225     return [PEPSession languageList];
   226 }
   227 
   228 - (PEP_STATUS)undoLastMistrust
   229 {
   230     return [PEPSession undoLastMistrust];
   231 }
   232 
   233 - (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   234 {
   235     return [PEPSession ratingFromString:string];
   236 }
   237 
   238 - (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   239 {
   240     return [PEPSession stringFromRating:rating];
   241 }
   242 
   243 - (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity
   244 {
   245     return [PEPSession isPEPUser:identity];
   246 }
   247 
   248 - (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   249             error:(NSError * _Nullable * _Nullable)error
   250 {
   251     return [PEPSession setOwnKey:identity fingerprint:fingerprint error:error];
   252 }
   253 
   254 #pragma mark Internal API (testing etc.)
   255 
   256 + (void)logTitle:(NSString * _Nonnull)title entity:(NSString * _Nonnull)entity
   257      description:(NSString * _Nullable)description comment:(NSString * _Nullable)comment
   258 {
   259     PEPInternalSession *session = [PEPSessionProvider session];
   260     [session logTitle:title entity:entity description:description comment:comment];
   261 }
   262 
   263 + (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   264                                      identity2:(PEPIdentity * _Nonnull)identity2
   265                                       language:(NSString * _Nullable)language
   266                                           full:(BOOL)full
   267 {
   268     PEPInternalSession *session = [PEPSessionProvider session];
   269     return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
   270 }
   271 
   272 + (NSArray<PEPLanguage *> * _Nonnull)languageList
   273 {
   274     PEPInternalSession *session = [PEPSessionProvider session];
   275     return [session languageList];
   276 }
   277 
   278 + (PEP_STATUS)undoLastMistrust
   279 {
   280     PEPInternalSession *session = [PEPSessionProvider session];
   281     return [session undoLastMistrust];
   282 }
   283 
   284 + (PEP_rating)ratingFromString:(NSString * _Nonnull)string
   285 {
   286     PEPInternalSession *session = [PEPSessionProvider session];
   287     return [session ratingFromString:string];
   288 }
   289 
   290 + (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
   291 {
   292     PEPInternalSession *session = [PEPSessionProvider session];
   293     return [session stringFromRating:rating];
   294 }
   295 
   296 + (BOOL)isPEPUser:(PEPIdentity * _Nonnull)identity;
   297 {
   298     PEPInternalSession *session = [PEPSessionProvider session];
   299     return [session isPEPUser:identity];
   300 }
   301 
   302 + (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
   303             error:(NSError * _Nullable * _Nullable)error
   304 {
   305     PEPInternalSession *session = [PEPSessionProvider session];
   306     return [session setOwnKey:identity fingerprint:fingerprint error:error];
   307 }
   308 
   309 @end