Delta Chat Core C-API
mrkey.h
1 /*******************************************************************************
2  *
3  * Delta Chat Core
4  * Copyright (C) 2017 Björn Petersen
5  * Contact: r10s@b44t.com, http://b44t.com
6  *
7  * This program is free software: you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later
10  * version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program. If not, see http://www.gnu.org/licenses/ .
19  *
20  ******************************************************************************/
21 
22 
23 #ifndef __MRKEY_H__
24 #define __MRKEY_H__
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 
30 typedef struct _mrmailbox mrmailbox_t;
31 typedef struct sqlite3_stmt sqlite3_stmt;
32 
33 
34 #define MR_PUBLIC 0
35 #define MR_PRIVATE 1
36 
37 
41 typedef struct mrkey_t
42 {
43  void* m_binary;
44  int m_bytes;
45  int m_type;
46 
48  int _m_heap_refcnt; /* !=0 for objects created with mrkey_new(), 0 for stack objects */
49 } mrkey_t;
50 
51 
52 mrkey_t* mrkey_new ();
53 mrkey_t* mrkey_ref (mrkey_t*);
54 void mrkey_unref (mrkey_t*);
55 
56 int mrkey_set_from_binary (mrkey_t*, const void* data, int bytes, int type);
57 int mrkey_set_from_key (mrkey_t*, const mrkey_t*);
58 int mrkey_set_from_stmt (mrkey_t*, sqlite3_stmt*, int index, int type);
59 int mrkey_set_from_base64 (mrkey_t*, const char* base64, int type);
60 int mrkey_set_from_file (mrkey_t*, const char* file, mrmailbox_t* mailbox);
61 
62 int mrkey_equals (const mrkey_t*, const mrkey_t*);
63 
64 int mrkey_save_self_keypair__(const mrkey_t* public_key, const mrkey_t* private_key, const char* addr, int is_default, mrsqlite3_t* sql);
65 int mrkey_load_self_public__ (mrkey_t*, const char* self_addr, mrsqlite3_t* sql);
66 int mrkey_load_self_private__(mrkey_t*, const char* self_addr, mrsqlite3_t* sql);
67 
68 char* mr_render_base64 (const void* buf, size_t buf_bytes, int break_every, const char* break_chars, int add_checksum); /* the result must be freed */
69 char* mrkey_render_base64(const mrkey_t* ths, int break_every, const char* break_chars, int add_checksum); /* the result must be freed */
70 char* mrkey_render_asc (const mrkey_t*, const char* add_header_lines); /* each header line must be terminated by \r\n, the result must be freed */
71 int mrkey_render_asc_to_file(const mrkey_t*, const char* file, mrmailbox_t* mailbox);
72 char* mrkey_render_fingerprint(const mrkey_t*, mrmailbox_t* mailbox);
73 char* mr_render_fingerprint(const uint8_t* data, size_t bytes);
74 void mr_wipe_secret_mem(void* buf, size_t buf_bytes);
75 
76 
77 #ifdef __cplusplus
78 } /* /extern "C" */
79 #endif
80 #endif /* __MRKEY_H__ */
81 
An object representing a single mailbox.