pEpObjCAdapter/PEPSession.m
author buff <andreas@pep-project.org>
Fri, 20 Oct 2017 00:23:36 +0200
changeset 289 bbe4e8da3568
parent 280 505c8528010c
parent 287 640d621c9dbf
child 291 1d64f8889d2c
permissions -rw-r--r--
merges IOSAD-50 into 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 
    14 @implementation PEPSession
    15 
    16 #pragma mark - Public API
    17 
    18 - (instancetype)init
    19 {
    20     self = [super init];
    21     if (self) {
    22         // Trigger provider to make sure a internal session is kept for the current thread.
    23         [PEPSessionProvider session];
    24     }
    25     return self;
    26 }
    27 
    28 - (void)cleanup
    29 {
    30     [PEPSessionProvider cleanup];
    31 }
    32 
    33 - (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
    34                             dest:(PEPDict * _Nullable * _Nullable)dst
    35                             keys:(PEPStringList * _Nullable * _Nullable)keys
    36 {
    37     return [PEPSession decryptMessageDict:src dest:(PEPDict * _Nullable * _Nullable)dst
    38                                          keys:(PEPStringList * _Nullable * _Nullable)keys];
    39 }
    40 
    41 - (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
    42 {
    43     return [PEPSession reEvaluateMessageRating:src];
    44 }
    45 
    46 - (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
    47                            extra:(nullable PEPStringList *)keys
    48                             dest:(PEPDict * _Nullable * _Nullable)dst
    49 {
    50     return [PEPSession encryptMessageDict:src extra:keys dest:dst];
    51 }
    52 
    53 - (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
    54                         identity:(nonnull PEPDict *)identity
    55                             dest:(PEPDict * _Nullable * _Nullable)dst
    56 {
    57     return [PEPSession encryptMessageDict:src identity:identity dest:dst];
    58 }
    59 
    60 - (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
    61 {
    62     return [PEPSession outgoingMessageColor:msg];
    63 }
    64 
    65 - (PEP_rating)identityRating:(nonnull PEPDict *)identity
    66 {
    67     return [PEPSession identityRating:identity];
    68 }
    69 
    70 - (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
    71                       shortened:(BOOL)shortened
    72 {
    73     return [PEPSession trustwords:fpr forLanguage:languageID shortened:shortened];
    74 }
    75 
    76 - (void)mySelf:(nonnull PEPMutableDict *)identity
    77 {
    78     [PEPSession mySelf:identity];
    79 }
    80 
    81 - (void)updateIdentity:(nonnull PEPMutableDict *)identity
    82 {
    83     [PEPSession updateIdentity:identity];
    84 }
    85 
    86 - (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
    87 {
    88     [PEPSession trustPersonalKey:identity];
    89 }
    90 
    91 - (void)keyMistrusted:(nonnull PEPMutableDict *)identity
    92 {
    93     [PEPSession keyMistrusted:identity];
    94 }
    95 
    96 - (void)keyResetTrust:(nonnull PEPMutableDict *)identity
    97 {
    98     [PEPSession keyResetTrust:identity];
    99 }
   100 
   101 #pragma mark Internal API (testing etc.)
   102 
   103 - (void)importKey:(nonnull NSString *)keydata
   104 {
   105     [PEPSession importKey:keydata];
   106 }
   107 
   108 - (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
   109      description:(nullable NSString *)description comment:(nullable NSString *)comment
   110 {
   111     [PEPSession logTitle:title entity:entity description:description comment:comment];
   112 }
   113 
   114 - (nonnull NSString *)getLog
   115 {
   116     return [PEPSession getLog];
   117 }
   118 
   119 - (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
   120                                     identity2:(nonnull PEPDict *)identity2
   121                                      language:(nullable NSString *)language
   122                                          full:(BOOL)full
   123 {
   124     return [PEPSession getTrustwordsIdentity1:identity1
   125                                         identity2:identity2
   126                                          language:language
   127                                              full:full];
   128 }
   129 
   130 - (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
   131                                    receiverDict:(nonnull PEPDict *)receiverDict
   132                                       keysArray:(PEPStringList * _Nullable)keysArray
   133                                        language:(nullable NSString *)language
   134                                            full:(BOOL)full
   135                                 resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
   136 {
   137     return [PEPSession getTrustwordsMessageDict:messageDict
   138                                        receiverDict:receiverDict
   139                                           keysArray:keysArray
   140                                            language:language
   141                                                full:full
   142                                     resultingStatus:resultingStatus];
   143 }
   144 
   145 - (NSArray<PEPLanguage *> * _Nonnull)languageList
   146 {
   147     return [PEPSession languageList];
   148 }
   149 
   150 - (PEP_STATUS)undoLastMistrust
   151 {
   152     return [PEPSession undoLastMistrust];
   153 }
   154 
   155 #pragma mark - Static 
   156 
   157 + (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
   158                             dest:(PEPDict * _Nullable * _Nullable)dst
   159                             keys:(PEPStringList * _Nullable * _Nullable)keys
   160 {
   161     PEPInternalSession *session = [PEPSessionProvider session];
   162     return [session decryptMessageDict:src dest:dst keys:keys];
   163 }
   164 
   165 + (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
   166 {
   167     PEPInternalSession *session = [PEPSessionProvider session];
   168     return [session reEvaluateMessageRating:src];
   169 }
   170 
   171 + (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
   172                            extra:(nullable PEPStringList *)keys
   173                             dest:(PEPDict * _Nullable * _Nullable)dst
   174 {
   175     PEPInternalSession *session = [PEPSessionProvider session];
   176     return [session encryptMessageDict:src extra:keys dest:dst];
   177 }
   178 
   179 + (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
   180                         identity:(nonnull PEPDict *)identity
   181                             dest:(PEPDict * _Nullable * _Nullable)dst
   182 {
   183     PEPInternalSession *session = [PEPSessionProvider session];
   184     return [session encryptMessageDict:src identity:identity dest:dst];
   185 }
   186 
   187 + (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
   188 {
   189     PEPInternalSession *session = [PEPSessionProvider session];
   190     return [session outgoingMessageColor:msg];
   191 }
   192 
   193 + (PEP_rating)identityRating:(nonnull PEPDict *)identity
   194 {
   195     PEPInternalSession *session = [PEPSessionProvider session];
   196     return [session identityRating:identity];
   197 }
   198 
   199 + (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
   200                       shortened:(BOOL)shortened
   201 {
   202     PEPInternalSession *session = [PEPSessionProvider session];
   203     return [session trustwords:fpr forLanguage:languageID shortened:shortened];
   204 }
   205 
   206 + (void)mySelf:(nonnull PEPMutableDict *)identity
   207 {
   208     PEPInternalSession *session = [PEPSessionProvider session];
   209     [session mySelf:identity];
   210 }
   211 
   212 + (void)updateIdentity:(nonnull PEPMutableDict *)identity
   213 {
   214     PEPInternalSession *session = [PEPSessionProvider session];
   215     [session updateIdentity:identity];
   216 }
   217 
   218 + (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
   219 {
   220     PEPInternalSession *session = [PEPSessionProvider session];
   221     [session trustPersonalKey:identity];
   222 }
   223 
   224 + (void)keyMistrusted:(nonnull PEPMutableDict *)identity
   225 {
   226     PEPInternalSession *session = [PEPSessionProvider session];
   227     [session keyMistrusted:identity];
   228 }
   229 
   230 + (void)keyResetTrust:(nonnull PEPMutableDict *)identity
   231 {
   232     PEPInternalSession *session = [PEPSessionProvider session];
   233     [session keyResetTrust:identity];
   234 }
   235 
   236 #pragma mark Internal API (testing etc.)
   237 
   238 + (void)importKey:(nonnull NSString *)keydata
   239 {
   240     PEPInternalSession *session = [PEPSessionProvider session];
   241     [session importKey:keydata];
   242 }
   243 
   244 + (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
   245      description:(nullable NSString *)description comment:(nullable NSString *)comment
   246 {
   247     PEPInternalSession *session = [PEPSessionProvider session];
   248     [session logTitle:title entity:entity description:description comment:comment];
   249 }
   250 
   251 + (nonnull NSString *)getLog
   252 {
   253     PEPInternalSession *session = [PEPSessionProvider session];
   254     return [session getLog];
   255 }
   256 
   257 + (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
   258                                     identity2:(nonnull PEPDict *)identity2
   259                                      language:(nullable NSString *)language
   260                                          full:(BOOL)full
   261 {
   262     PEPInternalSession *session = [PEPSessionProvider session];
   263     return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
   264 }
   265 
   266 + (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
   267                                    receiverDict:(nonnull PEPDict *)receiverDict
   268                                       keysArray:(PEPStringList * _Nullable)keysArray
   269                                        language:(nullable NSString *)language
   270                                            full:(BOOL)full
   271                                 resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
   272 {
   273     PEPInternalSession *session = [PEPSessionProvider session];
   274     return [session getTrustwordsMessageDict:messageDict receiverDict:receiverDict keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
   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 @end