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