src/pEpEngine.h
author vb
Mon, 11 Aug 2014 16:49:42 +0200
changeset 20 63ff31d0cfbd
parent 15 98a6c1cc9160
child 23 dba569e54163
permissions -rw-r--r--
use first key in keylist to sign a message
vb@0
     1
#ifdef __cplusplus
vb@0
     2
extern "C" {
vb@0
     3
#endif
vb@0
     4
vb@0
     5
#include <stdint.h>
vb@0
     6
#include <stdbool.h>
vb@0
     7
vb@0
     8
#ifdef WIN32
vb@0
     9
#ifdef _EXPORT_PEP_ENGINE_DLL
vb@0
    10
#define DYNAMIC_API __declspec(dllexport)
vb@0
    11
#else
vb@0
    12
#define DYNAMIC_API __declspec(dllimport)
vb@0
    13
#endif
vb@0
    14
#else
vb@0
    15
#define DYNAMIC_API
vb@0
    16
#endif
vb@0
    17
vb@0
    18
vb@0
    19
// pEp Engine API
vb@0
    20
vb@0
    21
//  caveat:
vb@0
    22
//      Unicode data has to be normalized to NFC before calling
vb@0
    23
//      UTF-8 strings are UTF-8 encoded C strings (zero terminated)
vb@0
    24
vb@0
    25
vb@0
    26
typedef void * PEP_SESSION;
vb@0
    27
vb@0
    28
typedef enum {
vb@0
    29
	PEP_STATUS_OK									= 0,
vb@0
    30
vb@0
    31
	PEP_INIT_CANNOT_LOAD_GPGME						= 0x0110,
vb@0
    32
	PEP_INIT_GPGME_INIT_FAILED						= 0x0111,
vb@0
    33
vb@0
    34
	PEP_INIT_SQLITE3_WITHOUT_MUTEX					= 0x0120,
vb@0
    35
	PEP_INIT_CANNOT_OPEN_DB							= 0x0121,
vb@0
    36
	PEP_INIT_CANNOT_OPEN_SYSTEM_DB					= 0x0122,
vb@0
    37
	
vb@0
    38
	PEP_KEY_NOT_FOUND						        = 0x0201,
vb@0
    39
	PEP_KEY_HAS_AMBIG_NAME					        = 0x0202,
vb@0
    40
	PEP_GET_KEY_FAILED						        = 0x0203,
vb@0
    41
	
vb@0
    42
	PEP_CANNOT_FIND_IDENTITY						= 0x0301,
vb@0
    43
	PEP_CANNOT_SET_PERSON							= 0x0381,
vb@0
    44
	PEP_CANNOT_SET_PGP_KEYPAIR						= 0x0382,
vb@0
    45
	PEP_CANNOT_SET_IDENTITY							= 0x0383,
vb@0
    46
	
vb@0
    47
	PEP_UNENCRYPTED									= 0x0400,
vb@0
    48
	PEP_VERIFIED									= 0x0401,
vb@0
    49
	PEP_DECRYPTED									= 0x0402,
vb@0
    50
	PEP_DECRYPTED_AND_VERIFIED						= 0x0403,
vb@0
    51
	PEP_DECRYPT_WRONG_FORMAT						= 0x0404,
vb@0
    52
	PEP_DECRYPT_NO_KEY								= 0x0405,
vb@0
    53
	PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH			= 0x0406,
vb@0
    54
    PEP_VERIFY_NO_KEY                               = 0x0407,
vb@0
    55
    PEP_VERIFIED_AND_TRUSTED                        = 0x0408,
vb@0
    56
	PEP_CANNOT_DECRYPT_UNKNOWN						= 0x04ff,
vb@0
    57
vb@0
    58
	PEP_SAFEWORD_NOT_FOUND							= 0x0501,
vb@0
    59
vb@0
    60
    PEP_CANNOT_CREATE_KEY                           = 0x0601,
vb@0
    61
    PEP_CANNOT_SEND_KEY                             = 0x0602,
vb@0
    62
vb@0
    63
	PEP_COMMIT_FAILED								= 0xff01,
vb@0
    64
vb@0
    65
    PEP_ILLEGAL_VALUE                               = -4,
vb@0
    66
    PEP_BUFFER_TOO_SMALL                            = -3,
vb@0
    67
	PEP_OUT_OF_MEMORY								= -2,
vb@0
    68
	PEP_UNKNOWN_ERROR								= -1
vb@0
    69
} PEP_STATUS;
vb@0
    70
vb@0
    71
vb@0
    72
// INIT_STATUS init() - initialize pEpEngine for a thread
vb@0
    73
//
vb@0
    74
//  parameters:
vb@0
    75
//		session (out)	init() allocates session memory and returns a pointer
vb@0
    76
//		                as a handle
vb@0
    77
//
vb@0
    78
//  return value:
vb@0
    79
//		PEP_STATUS_OK = 0					if init() succeeds
vb@0
    80
//		PEP_INIT_SQLITE3_WITHOUT_MUTEX		if SQLite3 was compiled with
vb@0
    81
//		                                    SQLITE_THREADSAFE 0
vb@0
    82
//		PEP_INIT_CANNOT_LOAD_GPGME			if libgpgme.dll cannot be found
vb@0
    83
//		PEP_INIT_GPGME_INIT_FAILED			if GPGME init fails
vb@0
    84
//		PEP_INIT_CANNOT_OPEN_DB				if user's management db cannot be
vb@0
    85
//		                                    opened
vb@0
    86
//		PEP_INIT_CANNOT_OPEN_SYSTEM_DB		if system's management db cannot be
vb@0
    87
//		                                    opened
vb@0
    88
//
vb@0
    89
//  caveat:
vb@0
    90
//      the pointer is valid only if the return value is PEP_STATUS_OK
vb@0
    91
//      in other case a NULL pointer will be returned; a valid handle must
vb@0
    92
//      be released using release() when it's no longer needed
vb@0
    93
vb@0
    94
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session);
vb@0
    95
vb@0
    96
vb@0
    97
// void release() - release thread session handle
vb@0
    98
//
vb@0
    99
//  parameters:
vb@0
   100
//		session (in)	session handle to release
vb@0
   101
vb@0
   102
DYNAMIC_API void release(PEP_SESSION session);
vb@0
   103
vb@0
   104
vb@0
   105
typedef struct _stringlist_t {
vb@0
   106
    char *value;
vb@0
   107
    struct _stringlist_t *next;
vb@0
   108
} stringlist_t;
vb@0
   109
vb@0
   110
vb@0
   111
// new_stringlist() - allocate a new stringlist
vb@0
   112
//
vb@0
   113
//  parameters:
vb@0
   114
//      value (in)        initial value as C string or NULL for empty list
vb@0
   115
//
vb@0
   116
//  return value:
vb@0
   117
//      pointer to stringlist_t object or NULL if out of memory
vb@0
   118
//
vb@0
   119
//  caveat:
vb@0
   120
//      the value is being copied before being added to the list
vb@0
   121
//      the original string is still being owned by the caller
vb@0
   122
vb@0
   123
DYNAMIC_API stringlist_t *new_stringlist(const char *value);
vb@0
   124
vb@0
   125
vb@0
   126
// stringlist_add() - add key to stringlist
vb@0
   127
//
vb@0
   128
//  parameters:
vb@0
   129
//      stringlist (in)     stringlist struct or NULL to create a new one
vb@0
   130
//      value (in)          value as C string
vb@0
   131
//
vb@0
   132
//  return value:
vb@0
   133
//      pointer to last element in stringlist or NULL if out of memory
vb@0
   134
//
vb@0
   135
//  caveat:
vb@0
   136
//      the value is being copied before being added to the list
vb@0
   137
//      the original string is still being owned by the caller
vb@0
   138
vb@0
   139
DYNAMIC_API stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value);
vb@0
   140
vb@0
   141
vb@0
   142
// stringlist_length() - get length of stringlist
vb@0
   143
//
vb@0
   144
//  parameters:
vb@0
   145
//      stringlist (in)     stringlist struct to determine length of
vb@0
   146
//
vb@0
   147
//  return value:
vb@0
   148
//      length of stringlist in number of elements
vb@0
   149
vb@0
   150
DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
vb@0
   151
vb@0
   152
vb@0
   153
// free_stringlist() - free memory occupied by stringlist
vb@0
   154
//
vb@0
   155
//  parameters:
vb@0
   156
//      stringlist (in)    stringlist to free
vb@0
   157
vb@0
   158
DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
vb@0
   159
vb@0
   160
vb@0
   161
// decrypt_and_verify() - decrypt and/or verify a message
vb@0
   162
//
vb@0
   163
//	parameters:
vb@0
   164
//		session (in)	session handle
vb@0
   165
//		ctext (in)		cipher text to decrypt and/or verify
vb@0
   166
//		csize (in)		size of cipher text
vb@0
   167
//		ptext (out)		pointer to internal buffer with plain text
vb@0
   168
//		psize (out)		size of plain text
vb@15
   169
//		keylist (out)	list of key ids which where used to encrypt
vb@0
   170
//
vb@0
   171
//	return value:
vb@0
   172
//		PEP_UNENCRYPTED				message was unencrypted and not signed
vb@0
   173
//		PEP_VERIFIED				message was unencrypted, signature matches
vb@0
   174
//		PEP_DECRYPTED				message is decrypted now, no signature
vb@0
   175
//		PEP_DECRYPTED_AND_VERIFIED	message is decrypted now and verified
vb@0
   176
//		PEP_DECRYPT_WRONG_FORMAT	message has wrong format to handle
vb@0
   177
//		PEP_DECRYPT_NO_KEY			key not available to decrypt and/or verify
vb@0
   178
//		PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH	wrong signature
vb@0
   179
//
vb@0
   180
//	caveat:
vb@0
   181
//	    the ownerships of ptext as well as keylist are going to the caller
vb@0
   182
//	    the caller must use free() (or an Windoze pEp_free()) and
vb@0
   183
//	    free_stringlist() to free them
vb@15
   184
//
vb@15
   185
//      if this function failes an error message may be the first element of
vb@15
   186
//      keylist and the other elements may be the keys used for encryption
vb@0
   187
vb@0
   188
DYNAMIC_API PEP_STATUS decrypt_and_verify(
vb@0
   189
        PEP_SESSION session, const char *ctext, size_t csize,
vb@0
   190
        char **ptext, size_t *psize, stringlist_t **keylist
vb@0
   191
    );
vb@0
   192
vb@0
   193
vb@0
   194
// verify_text() - verfy plain text with a digital signature
vb@0
   195
//
vb@0
   196
//  parameters:
vb@0
   197
//      session (in)    session handle
vb@0
   198
//      text (in)       text to verify
vb@0
   199
//      size (in)       size of text
vb@0
   200
//      signature (in)  signature text
vb@0
   201
//      sig_size (in)   size of signature
vb@6
   202
//		keylist (out)	list of key ids which where used to encrypt or NULL on
vb@0
   203
//		                error
vb@0
   204
//
vb@0
   205
//  return value:
vb@0
   206
//		PEP_VERIFIED				message was unencrypted, signature matches
vb@0
   207
//		PEP_DECRYPT_NO_KEY			key not available to decrypt and/or verify
vb@0
   208
//		PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH	wrong signature
vb@0
   209
vb@0
   210
DYNAMIC_API PEP_STATUS verify_text(
vb@0
   211
        PEP_SESSION session, const char *text, size_t size,
vb@0
   212
        const char *signature, size_t sig_size, stringlist_t **keylist
vb@0
   213
    );
vb@0
   214
vb@0
   215
vb@0
   216
// encrypt_and_sign() - encrypt and sign a message
vb@0
   217
//
vb@0
   218
//	parameters:
vb@0
   219
//		session (in)	session handle
vb@6
   220
//		keylist (in)	list of key ids to encrypt with as C strings
vb@0
   221
//		ptext (in)		plain text to decrypt and/or verify
vb@0
   222
//		psize (in)		size of plain text
vb@0
   223
//		ctext (out)		pointer to internal buffer with cipher text
vb@0
   224
//		csize (out)		size of cipher text
vb@0
   225
//
vb@0
   226
//	return value:
vb@0
   227
//		PEP_STATUS_OK = 0				encryption and signing succeeded
vb@0
   228
//		PEP_KEY_NOT_FOUND	            at least one of the receipient keys
vb@0
   229
//		                                could not be found
vb@0
   230
//		PEP_KEY_HAS_AMBIG_NAME          at least one of the receipient keys has
vb@0
   231
//		                                an ambiguous name
vb@0
   232
//		PEP_GET_KEY_FAILED		        cannot retrieve key
vb@0
   233
//
vb@0
   234
//	caveat:
vb@0
   235
//	    the ownership of ctext is going to the caller
vb@0
   236
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@20
   237
//      the first key in keylist is being used to sign the message
vb@20
   238
//      this implies there has to be a private key for that keypair
vb@0
   239
vb@0
   240
DYNAMIC_API PEP_STATUS encrypt_and_sign(
vb@0
   241
        PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
vb@0
   242
        size_t psize, char **ctext, size_t *csize
vb@0
   243
    );
vb@0
   244
vb@0
   245
vb@0
   246
// log_event() - log a user defined event defined by UTF-8 encoded strings into
vb@0
   247
// management log
vb@0
   248
//
vb@0
   249
//	parameters:
vb@0
   250
//		session (in)		session handle
vb@0
   251
//		title (in)			C string with event name
vb@0
   252
//		entity (in)			C string with name of entity which is logging
vb@0
   253
//		description (in)	C string with long description for event or NULL if
vb@0
   254
//		                    omitted
vb@0
   255
//		comment (in)		C string with user defined comment or NULL if
vb@0
   256
//		                    omitted
vb@0
   257
//
vb@0
   258
//	return value:
vb@0
   259
//	    PEP_STATUS_OK       log entry created
vb@0
   260
vb@0
   261
DYNAMIC_API PEP_STATUS log_event(
vb@0
   262
        PEP_SESSION session, const char *title, const char *entity,
vb@0
   263
        const char *description, const char *comment
vb@0
   264
    );
vb@0
   265
vb@0
   266
vb@0
   267
// safeword() - get the corresponding safeword for a 16 bit value
vb@0
   268
//
vb@0
   269
//	parameters:
vb@0
   270
//		session (in)		    session handle
vb@0
   271
//		value (in)			    value to find a safeword for
vb@0
   272
//		lang (in)			    C string with ISO 3166-1 ALPHA-2 language code
vb@0
   273
//		word (out)			    pointer to C string with safeword UTF-8 encoded
vb@0
   274
//							    NULL if language is not supported or safeword
vb@0
   275
//							    wordlist is damaged or unavailable
vb@0
   276
//		wsize (out)			    length of safeword
vb@0
   277
//
vb@0
   278
//	return value:
vb@0
   279
//	    PEP_STATUS_OK           safeword retrieved
vb@0
   280
//	    PEP_SAFEWORD_NOT_FOUND  safeword not found
vb@0
   281
//
vb@0
   282
//	caveat:
vb@0
   283
//		the word pointer goes to the ownership of the caller
vb@0
   284
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   285
vb@0
   286
DYNAMIC_API PEP_STATUS safeword(
vb@0
   287
            PEP_SESSION session, uint16_t value, const char *lang,
vb@0
   288
            char **word, size_t *wsize
vb@0
   289
        );
vb@0
   290
vb@0
   291
vb@0
   292
// safewords() - get safewords for a string of hex values of a fingerprint
vb@0
   293
//
vb@0
   294
//	parameters:
vb@0
   295
//		session (in)		session handle
vb@0
   296
//		fingerprint (in)	C string with hex values to find safewords for
vb@0
   297
//		lang (in)			C string with ISO 3166-1 ALPHA-2 language code
vb@0
   298
//		words (out)			pointer to C string with safewords UTF-8 encoded,
vb@0
   299
//		                    separated by a blank each
vb@0
   300
//							NULL if language is not supported or safeword
vb@0
   301
//							wordlist is damaged or unavailable
vb@0
   302
//		wsize (out)			length of safewords string
vb@0
   303
//		max_words (in)		only generate a string with max_words;
vb@0
   304
//							if max_words == 0 there is no such limit
vb@0
   305
//
vb@0
   306
//	return value:
vb@0
   307
//	    PEP_STATUS_OK           safewords retrieved
vb@0
   308
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   309
//	    PEP_SAFEWORD_NOT_FOUND  at least one safeword not found
vb@0
   310
//
vb@0
   311
//	caveat:
vb@0
   312
//		the word pointer goes to the ownership of the caller
vb@0
   313
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   314
//
vb@0
   315
//  DON'T USE THIS FUNCTION FROM HIGH LEVEL LANGUAGES!
vb@0
   316
//
vb@0
   317
//  Better implement a simple one in the adapter yourself using safeword(), and
vb@0
   318
//  return a list of safewords.
vb@0
   319
//  This function is provided for being used by C and C++ programs only.
vb@0
   320
vb@0
   321
DYNAMIC_API PEP_STATUS safewords(
vb@0
   322
        PEP_SESSION session, const char *fingerprint, const char *lang,
vb@0
   323
        char **words, size_t *wsize, int max_words
vb@0
   324
    );
vb@0
   325
vb@0
   326
vb@0
   327
typedef enum _PEP_comm_type {
vb@9
   328
    PEP_ct_unknown = 0,
vb@0
   329
vb@9
   330
    // range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
vb@0
   331
vb@9
   332
    PEP_ct_no_encryption = 0x01,                // generic
vb@9
   333
    PEP_ct_no_encrypted_channel = 0x02,
vb@9
   334
    PEP_ct_key_not_found = 0x03,
vb@9
   335
    PEP_ct_key_expired = 0x04,
vb@9
   336
    PEP_ct_key_revoked = 0x05,
vb@9
   337
    PEP_ct_key_b0rken = 0x06,
vb@9
   338
    PEP_ct_my_key_not_included = 0x09,
vb@9
   339
vb@9
   340
    PEP_ct_security_by_obscurity = 0x0a,
vb@9
   341
    PEP_ct_b0rken_crypto = 0x0b,
vb@9
   342
    PEP_ct_key_too_short = 0x0e,
vb@9
   343
vb@0
   344
    PEP_ct_compromized = 0x0f,                  // known compromized connection
vb@0
   345
vb@9
   346
    // range 0x10 to 0x3f: unconfirmed encryption
vb@0
   347
vb@0
   348
    PEP_ct_unconfirmed_encryption = 0x10,       // generic
vb@9
   349
    PEP_ct_OpenPGP_1024_RSA_unconfirmed = 0x11,	// RSA 1024 is weak
vb@9
   350
    PEP_ct_CMS_unconfirmed = 0x30,
vb@9
   351
    PEP_ct_OpenPGP_unconfirmed = 0x3f,          // key at least 2048 bit RSA
vb@9
   352
    // or 1024 bit DSA
vb@0
   353
vb@9
   354
    // range 0x40 to 0x7f: unconfirmed encryption and anonymization
vb@0
   355
vb@0
   356
    PEP_ct_unconfirmed_enc_anon = 0x40,         // generic
vb@9
   357
    PEP_ct_PEP_unconfirmed = 0x7f,
vb@0
   358
vb@9
   359
    PEP_ct_confirmed = 0x80,                    // this bit decides if trust is confirmed
vb@9
   360
vb@9
   361
    // range 0x81 to 0x8f: reserved
vb@9
   362
    // range 0x90 to 0xbf: confirmed encryption
vb@0
   363
vb@0
   364
    PEP_ct_confirmed_encryption = 0x90,         // generic
vb@0
   365
	PEP_ct_OpenPGP_1024_RSA = 0x91, // RSA 1024 is weak
vb@9
   366
    PEP_ct_CMS = 0xb0,
vb@0
   367
	PEP_ct_OpenPGP = 0xbf, // key at least 2048 bit RSA or 1024 bit DSA
vb@0
   368
vb@0
   369
    // range 0xc0 to 0xff: confirmed encryption and anonymization
vb@0
   370
vb@0
   371
    PEP_ct_confirmed_enc_anon = 0xc0,           // generic
vb@0
   372
	PEP_ct_pEp = 0xff
vb@0
   373
} PEP_comm_type;
vb@0
   374
vb@0
   375
typedef struct _pEp_identity {
vb@0
   376
	size_t struct_size;			// size of whole struct
vb@0
   377
	char *address;		        // C string with address UTF-8 encoded
vb@0
   378
	size_t address_size;		// size of address
vb@0
   379
	char *fpr;			        // C string with fingerprint UTF-8 encoded
vb@0
   380
	size_t fpr_size;			// size of fingerprint
vb@0
   381
	char *user_id;		        // C string with user ID UTF-8 encoded
vb@0
   382
	size_t user_id_size;		// size of user ID
vb@0
   383
	char *username;		        // C string with user name UTF-8 encoded
vb@0
   384
	size_t username_size;		// size of user name
vb@0
   385
	PEP_comm_type comm_type;	// type of communication with this ID
vb@0
   386
    char lang[3];				// language of conversation
vb@0
   387
                                // ISO 639-1 ALPHA-2, last byte is 0
vb@0
   388
    bool me;                    // if this is the local user herself/himself
vb@0
   389
} pEp_identity;
vb@0
   390
vb@0
   391
vb@0
   392
// new_identity() - allocate memory and set the string and size fields
vb@0
   393
//
vb@0
   394
//  parameters:
vb@0
   395
//      address (in)        UTF-8 string or NULL 
vb@0
   396
//      fpr (in)            UTF-8 string or NULL 
vb@0
   397
//      user_id (in)        UTF-8 string or NULL 
vb@0
   398
//      username (in)       UTF-8 string or NULL 
vb@0
   399
//
vb@0
   400
//  return value:
vb@0
   401
//      pEp_identity struct with correct size values or NULL if out of memory
vb@0
   402
//
vb@0
   403
//  caveat:
vb@0
   404
//      the strings are copied; the original strings are still being owned by
vb@0
   405
//      the caller
vb@0
   406
vb@0
   407
DYNAMIC_API pEp_identity *new_identity(
vb@0
   408
        const char *address, const char *fpr, const char *user_id,
vb@0
   409
        const char *username
vb@0
   410
    );
vb@0
   411
vb@0
   412
vb@0
   413
// free_identity() - free all memory being occupied by a pEp_identity struct
vb@0
   414
//
vb@0
   415
//  parameters:
vb@0
   416
//      identity (in)       struct to release
vb@0
   417
//
vb@0
   418
//  caveat:
vb@0
   419
//      not only the struct but also all string memory referenced by the
vb@0
   420
//      struct is being freed; all pointers inside are invalid afterwards
vb@0
   421
vb@0
   422
DYNAMIC_API void free_identity(pEp_identity *identity);
vb@0
   423
vb@0
   424
vb@0
   425
// get_identity() - get identity information
vb@0
   426
//
vb@0
   427
//	parameters:
vb@0
   428
//		session (in)		session handle
vb@0
   429
//		address (in)		C string with communication address, UTF-8 encoded
vb@0
   430
//		identity (out)		pointer to pEp_identity structure with results or
vb@0
   431
//		                    NULL if failure
vb@0
   432
//
vb@0
   433
//	caveat:
vb@0
   434
//	    the address string is being copied; the original string remains in the
vb@0
   435
//	    ownership of the caller
vb@0
   436
//		the resulting pEp_identity structure goes to the ownership of the
vb@0
   437
//		caller and has to be freed with free_identity() when not in use any
vb@0
   438
//		more
vb@0
   439
vb@0
   440
DYNAMIC_API PEP_STATUS get_identity(
vb@0
   441
        PEP_SESSION session, const char *address,
vb@0
   442
        pEp_identity **identity
vb@0
   443
    );
vb@0
   444
vb@0
   445
vb@0
   446
// set_identity() - set identity information
vb@0
   447
//
vb@0
   448
//	parameters:
vb@0
   449
//		session (in)		session handle
vb@0
   450
//		identity (in)		pointer to pEp_identity structure
vb@0
   451
//
vb@0
   452
//	return value:
vb@0
   453
//		PEP_STATUS_OK = 0			    encryption and signing succeeded
vb@0
   454
//		PEP_CANNOT_SET_PERSON		    writing to table person failed
vb@0
   455
//		PEP_CANNOT_SET_PGP_KEYPAIR	    writing to table pgp_keypair failed
vb@0
   456
//		PEP_CANNOT_SET_IDENTITY		    writing to table identity failed
vb@0
   457
//		PEP_COMMIT_FAILED			    SQL commit failed
vb@0
   458
//
vb@0
   459
//	caveat:
vb@0
   460
//		in the identity structure you need to set the const char * fields to
vb@0
   461
//		UTF-8 C strings
vb@0
   462
//		the size fields are ignored
vb@0
   463
vb@0
   464
DYNAMIC_API PEP_STATUS set_identity(
vb@0
   465
        PEP_SESSION session, const pEp_identity *identity
vb@0
   466
    );
vb@0
   467
vb@0
   468
vb@0
   469
// generate_keypair() - generate a new key pair and add it to the key ring
vb@0
   470
//
vb@0
   471
//  parameters:
vb@0
   472
//      session (in)            session handle
vb@0
   473
//		identity (inout)	    pointer to pEp_identity structure
vb@0
   474
//
vb@0
   475
//	return value:
vb@0
   476
//		PEP_STATUS_OK = 0	    encryption and signing succeeded
vb@0
   477
//		PEP_ILLEGAL_VALUE       illegal values for identity fields given
vb@0
   478
//		PEP_CANNOT_CREATE_KEY   key engine is on strike
vb@0
   479
//
vb@0
   480
//  caveat:
vb@0
   481
//      address and username fields must be set to UTF-8 strings
vb@0
   482
//      the fpr field must be set to NULL
vb@0
   483
//
vb@0
   484
//      this function allocates a string and sets set fpr field of identity
vb@0
   485
//      the caller is responsible to call free() for that string or use
vb@0
   486
//      free_identity() on the struct
vb@0
   487
vb@0
   488
DYNAMIC_API PEP_STATUS generate_keypair(
vb@0
   489
        PEP_SESSION session, pEp_identity *identity
vb@0
   490
    );
vb@0
   491
vb@0
   492
vb@0
   493
// delete_keypair() - delete a public key or a key pair from the key ring
vb@0
   494
//
vb@0
   495
//  parameters:
vb@0
   496
//      session (in)            session handle
vb@0
   497
//      fpr (in)                C string with key id or fingerprint of the
vb@0
   498
//                              public key
vb@0
   499
//
vb@0
   500
//  return value:
vb@0
   501
//      PEP_STATUS_OK = 0       key was successfully deleted
vb@0
   502
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   503
//      PEP_ILLEGAL_VALUE       not a valid key id or fingerprint
vb@0
   504
//      PEP_KEY_HAS_AMBIG_NAME  fpr does not uniquely identify a key
vb@0
   505
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   506
vb@0
   507
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr);
vb@0
   508
vb@0
   509
vb@0
   510
// import_key() - import key from data
vb@0
   511
//
vb@0
   512
//  parameters:
vb@0
   513
//      session (in)            session handle
vb@0
   514
//      key_data (in)           key data, i.e. ASCII armored OpenPGP key
vb@0
   515
//      size (in)               amount of data to handle
vb@0
   516
//
vb@0
   517
//  return value:
vb@0
   518
//      PEP_STATUS_OK = 0       key was successfully imported
vb@0
   519
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   520
//      PEP_ILLEGAL_VALUE       there is no key data to import
vb@0
   521
vb@0
   522
DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size);
vb@0
   523
vb@0
   524
vb@0
   525
// export_key() - export ascii armored key
vb@0
   526
//
vb@0
   527
//  parameters:
vb@0
   528
//      session (in)            session handle
vb@0
   529
//      fpr (in)                key id or fingerprint of key
vb@0
   530
//      key_data (out)          ASCII armored OpenPGP key
vb@0
   531
//      size (out)               amount of data to handle
vb@0
   532
//
vb@0
   533
//  return value:
vb@0
   534
//      PEP_STATUS_OK = 0       key was successfully exported
vb@0
   535
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   536
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   537
//
vb@0
   538
//  caveat:
vb@0
   539
//      the key_data goes to the ownership of the caller
vb@0
   540
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   541
vb@0
   542
DYNAMIC_API PEP_STATUS export_key(
vb@0
   543
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
vb@0
   544
    );
vb@0
   545
vb@0
   546
vb@0
   547
// recv_key() - update key(s) from keyserver
vb@0
   548
//
vb@0
   549
//  parameters:
vb@0
   550
//      session (in)            session handle
vb@0
   551
//      pattern (in)            key id, user id or address to search for as
vb@0
   552
//                              UTF-8 string
vb@0
   553
vb@0
   554
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern);
vb@0
   555
vb@0
   556
vb@0
   557
// find_keys() - find keys in keyring
vb@0
   558
//
vb@0
   559
//  parameters:
vb@0
   560
//      session (in)            session handle
vb@0
   561
//      pattern (in)            key id, user id or address to search for as
vb@0
   562
//                              UTF-8 string
vb@0
   563
//      keylist (out)           list of fingerprints found or NULL on error
vb@0
   564
//
vb@0
   565
//  caveat:
vb@0
   566
//	    the ownerships of keylist isgoing to the caller
vb@0
   567
//	    the caller must use free_stringlist() to free it
vb@0
   568
vb@0
   569
vb@0
   570
DYNAMIC_API PEP_STATUS find_keys(
vb@0
   571
        PEP_SESSION session, const char *pattern, stringlist_t **keylist
vb@0
   572
    );
vb@0
   573
vb@0
   574
vb@0
   575
// send_key() - send key(s) to keyserver
vb@0
   576
//
vb@0
   577
//  parameters:
vb@0
   578
//      session (in)            session handle
vb@0
   579
//      pattern (in)            key id, user id or address to search for as
vb@0
   580
//                              UTF-8 string
vb@0
   581
vb@0
   582
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern);
vb@0
   583
vb@0
   584
vb@0
   585
// pEp_free() - free memory allocated by pEp engine
vb@0
   586
//
vb@0
   587
//  parameters:
vb@0
   588
//      p (in)                  pointer to free
vb@0
   589
//
vb@0
   590
//  The reason for this function is that heap management can be a pretty
vb@0
   591
//  complex task with Windoze. This free() version calls the free()
vb@0
   592
//  implementation of the C runtime library which was used to build pEp engine,
vb@0
   593
//  so you're using the correct heap. For more information, see:
vb@0
   594
//  <http://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx>
vb@0
   595
vb@0
   596
DYNAMIC_API void pEp_free(void *p);
vb@0
   597
vb@8
   598
vb@8
   599
// get_trust() - get the trust level a key has for a person
vb@8
   600
//
vb@8
   601
//  parameters:
vb@8
   602
//      session (in)            session handle
vb@8
   603
//      identity (inout)        user_id and fpr to check as UTF-8 strings (in)
vb@8
   604
//                              user_id and comm_type as result (out)
vb@8
   605
//
vb@14
   606
//  this function modifies the given identity struct; the struct remains in
vb@14
   607
// the ownership of the caller
vb@14
   608
//  if the trust level cannot be determined identity->comm_type is set
vb@14
   609
//  to PEP_ct_unknown
vb@8
   610
vb@8
   611
DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity);
vb@8
   612
vb@8
   613
vb@9
   614
// get_key_rating() - get the rating a bare key has
vb@9
   615
//
vb@9
   616
//  parameters:
vb@9
   617
//      session (in)            session handle
vb@9
   618
//      fpr (in)                unique identifyer for key as UTF-8 string
vb@9
   619
//      comm_type (out)         key rating
vb@10
   620
//
vb@14
   621
//  if an error occurs, *comm_type is set to PEP_ct_unknown and an error
vb@10
   622
//  is returned
vb@9
   623
vb@9
   624
DYNAMIC_API PEP_STATUS get_key_rating(
vb@14
   625
        PEP_SESSION session,
vb@14
   626
        const char *fpr,
vb@14
   627
        PEP_comm_type *comm_type
vb@9
   628
    );
vb@9
   629
vb@9
   630
vb@0
   631
#ifdef __cplusplus
vb@0
   632
}
vb@0
   633
#endif