Imported Upstream version 2.1.9
[platform/upstream/gpg2.git] / kbx / keybox.h
1 /* keybox.h - Keybox operations
2  * Copyright (C) 2001, 2003, 2012 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GnuPG is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef KEYBOX_H
21 #define KEYBOX_H 1
22 #ifdef __cplusplus
23 extern "C" {
24 #if 0
25  }
26 #endif
27 #endif
28
29 #include "../common/iobuf.h"
30 #include "keybox-search-desc.h"
31
32 #ifdef KEYBOX_WITH_X509
33 # include <ksba.h>
34 #endif
35
36 typedef struct keybox_handle *KEYBOX_HANDLE;
37
38
39 typedef enum
40   {
41     KEYBOX_FLAG_BLOB,       /* The blob flags. */
42     KEYBOX_FLAG_VALIDITY,   /* The validity of the entire key. */
43     KEYBOX_FLAG_OWNERTRUST, /* The assigned ownertrust. */
44     KEYBOX_FLAG_KEY,        /* The key flags; requires a key index. */
45     KEYBOX_FLAG_UID,        /* The user ID flags; requires an uid index. */
46     KEYBOX_FLAG_UID_VALIDITY,/* The validity of a specific uid, requires
47                                an uid index. */
48     KEYBOX_FLAG_CREATED_AT, /* The date the block was created. */
49     KEYBOX_FLAG_SIG_INFO,   /* The signature info block.  */
50   } keybox_flag_t;
51
52 /* Flag values used with KEYBOX_FLAG_BLOB.  */
53 #define KEYBOX_FLAG_BLOB_SECRET     1
54 #define KEYBOX_FLAG_BLOB_EPHEMERAL  2
55
56 /* The keybox blob types.  */
57 typedef enum
58   {
59     KEYBOX_BLOBTYPE_EMPTY  = 0,
60     KEYBOX_BLOBTYPE_HEADER = 1,
61     KEYBOX_BLOBTYPE_PGP    = 2,
62     KEYBOX_BLOBTYPE_X509   = 3
63   } keybox_blobtype_t;
64
65
66 /*-- keybox-init.c --*/
67 void *keybox_register_file (const char *fname, int secret);
68 int keybox_is_writable (void *token);
69
70 KEYBOX_HANDLE keybox_new_openpgp (void *token, int secret);
71 KEYBOX_HANDLE keybox_new_x509 (void *token, int secret);
72 void keybox_release (KEYBOX_HANDLE hd);
73 void keybox_push_found_state (KEYBOX_HANDLE hd);
74 void keybox_pop_found_state (KEYBOX_HANDLE hd);
75 const char *keybox_get_resource_name (KEYBOX_HANDLE hd);
76 int keybox_set_ephemeral (KEYBOX_HANDLE hd, int yes);
77
78 int keybox_lock (KEYBOX_HANDLE hd, int yes);
79
80 /*-- keybox-file.c --*/
81 /* Fixme: This function does not belong here: Provide a better
82    interface to create a new keybox file.  */
83 int _keybox_write_header_blob (FILE *fp, int openpgp_flag);
84
85 /*-- keybox-search.c --*/
86 gpg_error_t keybox_get_keyblock (KEYBOX_HANDLE hd, iobuf_t *r_iobuf,
87                                  int *r_uid_no, int *r_pk_no, u32 **sigstatus);
88 #ifdef KEYBOX_WITH_X509
89 int keybox_get_cert (KEYBOX_HANDLE hd, ksba_cert_t *ret_cert);
90 #endif /*KEYBOX_WITH_X509*/
91 int keybox_get_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int *value);
92
93 int keybox_search_reset (KEYBOX_HANDLE hd);
94 int keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc,
95                    keybox_blobtype_t want_blobtype,
96                    size_t *r_descindex, unsigned long *r_skipped);
97
98
99 /*-- keybox-update.c --*/
100 gpg_error_t keybox_insert_keyblock (KEYBOX_HANDLE hd,
101                                     const void *image, size_t imagelen,
102                                     u32 *sigstatus);
103 gpg_error_t keybox_update_keyblock (KEYBOX_HANDLE hd,
104                                     const void *image, size_t imagelen);
105
106 #ifdef KEYBOX_WITH_X509
107 int keybox_insert_cert (KEYBOX_HANDLE hd, ksba_cert_t cert,
108                         unsigned char *sha1_digest);
109 int keybox_update_cert (KEYBOX_HANDLE hd, ksba_cert_t cert,
110                         unsigned char *sha1_digest);
111 #endif /*KEYBOX_WITH_X509*/
112 int keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value);
113
114 int keybox_delete (KEYBOX_HANDLE hd);
115 int keybox_compress (KEYBOX_HANDLE hd);
116
117
118 /*--  --*/
119
120 #if 0
121 int keybox_locate_writable (KEYBOX_HANDLE hd);
122 int keybox_rebuild_cache (void *);
123 #endif
124
125
126 /*-- keybox-util.c --*/
127 void keybox_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
128                                void *(*new_realloc_func)(void *p, size_t n),
129                                void (*new_free_func)(void*) );
130
131
132 #ifdef __cplusplus
133 }
134 #endif
135 #endif /*KEYBOX_H*/