pEpObjCAdapter/PEPSession.h
author Edouard Tisserant <edouard@pep-project.org>
Wed, 09 Aug 2017 14:43:30 +0200
branchIOSAD-21
changeset 198 55e448e712a6
parent 196 d660aae03056
child 202 9887f3326221
permissions -rw-r--r--
IOSAD-21 no more @"me" in identity dicts
     1 //
     2 //  PEPSession.h
     3 //  pEpiOSAdapter
     4 //
     5 //  Created by Volker Birk on 08.07.15.
     6 //  Copyright (c) 2015 p≡p. All rights reserved.
     7 //
     8 
     9 #import <Foundation/Foundation.h>
    10 
    11 #import "PEPObjCAdapter.h"
    12 #import "PEPMessage.h"
    13 
    14 @class PEPSession;
    15 @class PEPLanguage;
    16 
    17 /** Callback type for doing something with a session */
    18 typedef void (^PEPSessionBlock)(PEPSession * _Nonnull session);
    19 
    20 @interface PEPSession : NSObject
    21 
    22 #pragma mark -- Public API
    23 
    24 + (nonnull PEPSession *)session;
    25 
    26 /**
    27  Execute a block concurrently on a session.
    28  The session is created solely for execution of the block.
    29  */
    30 + (void)dispatchAsyncOnSession:(nonnull PEPSessionBlock)block;
    31 
    32 /**
    33  Execute a block on a session and wait for it.
    34  The session is created solely for execution of the block.
    35  */
    36 + (void)dispatchSyncOnSession:(nonnull PEPSessionBlock)block;
    37 
    38 /** Decrypt a message */
    39 - (PEP_rating)decryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
    40                             dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
    41                             keys:(NSArray<NSString *> * _Nullable * _Nullable)keys;
    42 
    43 /** Re-evaluate rating of decrypted message */
    44 - (PEP_rating)reEvaluateMessageRating:(nonnull NSDictionary<NSString *, id> *)src;
    45 
    46 /** Encrypt a message */
    47 - (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
    48                            extra:(nullable NSArray<NSString *> *)keys
    49                             dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst;
    50 
    51 /** Encrypt a message for the given identity, which is usually a mySelf identity */
    52 - (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
    53                         identity:(nonnull NSDictionary<NSString *, id> *)identity
    54                             dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst;
    55 
    56 /** Determine the status color of a message to be sent */
    57 - (PEP_rating)outgoingMessageColor:(nonnull NSDictionary<NSString *, id> *)msg;
    58 
    59 /** Determine the rating of an identity */
    60 - (PEP_rating)identityRating:(nonnull NSDictionary<NSString *, id> *)identity;
    61 
    62 /** Get trustwords for a fingerprint */
    63 - (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
    64                       shortened:(BOOL)shortened;
    65 
    66 /**
    67  Supply an account used by our user himself. The identity is supplemented with the missing parts
    68 
    69  An identity is a `NSDictionary` mapping a field name as `NSString` to different values.
    70  An identity can have the following fields (all other keys are ignored).
    71  It is not necessary to supply all fields; missing fields are supplemented by p≡p engine.
    72  
    73  @"username": real name or nick name (if pseudonymous) of identity
    74  @"address": URI or SMTP address
    75  @"user_id": persistent unique ID for identity
    76  @"lang": preferred languageID for communication with this ID (default: @"en")
    77  @"fpr": fingerprint of key to use for communication with this ID
    78  @"comm_type": communication type code (usually not needed)
    79  
    80  As an example:
    81  
    82  User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
    83  
    84  NSDictionary *ident = [NSDictionary dictionaryWithObjectsAndKeys:
    85  @"Dipul Khatri", @"username", @"dipul@inboxcube.com", @"address", 
    86  @"23", @"user_id", nil];
    87  
    88 */
    89 - (void)mySelf:(nonnull NSMutableDictionary<NSString *, id> *)identity;
    90 
    91 /**
    92  Supplement missing information for an arbitrary identity (used for communication partners).
    93  See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
    94  */
    95 - (void)updateIdentity:(nonnull NSMutableDictionary<NSString *, id> *)identity;
    96 
    97 /**
    98  Mark a key as trusted with a person.
    99  See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
   100  */
   101 - (void)trustPersonalKey:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   102 
   103 /**
   104  if a key is not trusted by the user tell this using this message
   105  See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
   106  */
   107 - (void)keyMistrusted:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   108 
   109 /**
   110  Use this to undo keyCompromized or trustPersonalKey
   111  See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
   112 */
   113 - (void)keyResetTrust:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   114 
   115 #pragma mark -- Internal API (testing etc.)
   116 
   117 /** For testing purpose, manual key import */
   118 - (void)importKey:(nonnull NSString *)keydata;
   119 
   120 - (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
   121      description:(nullable NSString *)description comment:(nullable NSString *)comment;
   122 
   123 /**
   124  Retrieves the log from the engine.
   125  */
   126 - (nonnull NSString *)getLog;
   127 
   128 /** Determine trustwords for two identities */
   129 - (nullable NSString *)getTrustwordsIdentity1:(nonnull NSDictionary<NSString *, id> *)identity1
   130                                     identity2:(nonnull NSDictionary<NSString *, id> *)identity2
   131                                      language:(nullable NSString *)language
   132                                          full:(BOOL)full;
   133 
   134 /**
   135  @returns The list of supported languages for trustwords.
   136  */
   137 - (NSArray<PEPLanguage *> * _Nonnull)languageList;
   138 
   139 @end