pEpObjCAdapter/PEPSession.h
author Dirk Zimmermann <dirk@pep-project.org>
Wed, 17 May 2017 09:27:57 +0200
changeset 187 1f630a05e444
child 196 d660aae03056
permissions -rw-r--r--
IOSAD-15 more renames
     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 /** Encrypt a message */
    44 - (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
    45                            extra:(nullable NSArray<NSString *> *)keys
    46                             dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst;
    47 
    48 /** Encrypt a message for the given identity, which is usually a mySelf identity */
    49 - (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
    50                         identity:(nonnull NSDictionary<NSString *, id> *)identity
    51                             dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst;
    52 
    53 /** Determine the status color of a message to be sent */
    54 - (PEP_rating)outgoingMessageColor:(nonnull NSDictionary<NSString *, id> *)msg;
    55 
    56 /** Determine the rating of an identity */
    57 - (PEP_rating)identityRating:(nonnull NSDictionary<NSString *, id> *)identity;
    58 
    59 /** Get trustwords for a fingerprint */
    60 - (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
    61                       shortened:(BOOL)shortened;
    62 
    63 /**
    64  Supply an account used by our user himself. The identity is supplemented with the missing parts
    65 
    66  An identity is a `NSDictionary` mapping a field name as `NSString` to different values.
    67  An identity can have the following fields (all other keys are ignored).
    68  It is not necessary to supply all fields; missing fields are supplemented by p≡p engine.
    69  
    70  @"username": real name or nick name (if pseudonymous) of identity
    71  @"address": URI or SMTP address
    72  @"user_id": persistent unique ID for identity
    73  @"lang": preferred languageID for communication with this ID (default: @"en")
    74  @"fpr": fingerprint of key to use for communication with this ID
    75  @"comm_type": communication type code (usually not needed)
    76  @"me": YES if this is an identity of our user, NO if it is one of a communication partner (default: NO)
    77  
    78  As an example:
    79  
    80  User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
    81  
    82  NSDictionary *ident = [NSDictionary dictionaryWithObjectsAndKeys:
    83  @"Dipul Khatri", @"username", @"dipul@inboxcube.com", @"address", 
    84  @"23", @"user_id", nil];
    85  
    86 */
    87 - (void)mySelf:(nonnull NSMutableDictionary<NSString *, id> *)identity;
    88 
    89 /**
    90  Supplement missing information for an arbitrary identity (used for communication partners).
    91  See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
    92  */
    93 - (void)updateIdentity:(nonnull NSMutableDictionary<NSString *, id> *)identity;
    94 
    95 /**
    96  Mark a key as trusted with a person.
    97  See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
    98  */
    99 - (void)trustPersonalKey:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   100 
   101 /**
   102  if a key is not trusted by the user tell this using this message
   103  See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
   104  */
   105 - (void)keyMistrusted:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   106 
   107 /**
   108  Use this to undo keyCompromized or trustPersonalKey
   109  See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
   110 */
   111 - (void)keyResetTrust:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   112 
   113 #pragma mark -- Internal API (testing etc.)
   114 
   115 /** For testing purpose, manual key import */
   116 - (void)importKey:(nonnull NSString *)keydata;
   117 
   118 - (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
   119      description:(nullable NSString *)description comment:(nullable NSString *)comment;
   120 
   121 /**
   122  Retrieves the log from the engine.
   123  */
   124 - (nonnull NSString *)getLog;
   125 
   126 /** Determine trustwords for two identities */
   127 - (nullable NSString *)getTrustwordsIdentity1:(nonnull NSDictionary<NSString *, id> *)identity1
   128                                     identity2:(nonnull NSDictionary<NSString *, id> *)identity2
   129                                      language:(nullable NSString *)language
   130                                          full:(BOOL)full;
   131 
   132 /**
   133  @returns The list of supported languages for trustwords.
   134  */
   135 - (NSArray<PEPLanguage *> * _Nonnull)languageList;
   136 
   137 @end