1 /* keybox-defs.h - internal Keybox definitions
2 * Copyright (C) 2001, 2004 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 #define KEYBOX_DEFS_H 1
23 #ifdef GPG_ERR_SOURCE_DEFAULT
24 # if GPG_ERR_SOURCE_DEFAULT != GPG_ERR_SOURCE_KEYBOX
25 # error GPG_ERR_SOURCE_DEFAULT already defined
28 # define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_KEYBOX
30 #include <gpg-error.h>
31 #define map_assuan_err(a) \
32 map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
34 #include <sys/types.h> /* off_t */
36 #include "../common/util.h"
40 typedef struct keyboxblob *KEYBOXBLOB;
43 typedef struct keybox_name *KB_NAME;
46 /* Link to the next resources, so that we can walk all
50 /* True if this is a keybox with secret keys. */
53 /* A table with all the handles accessing this resources.
54 HANDLE_TABLE_SIZE gives the allocated length of this table unused
55 entrues are set to NULL. HANDLE_TABLE may be NULL. */
56 KEYBOX_HANDLE *handle_table;
57 size_t handle_table_size;
59 /* The lock handle or NULL it not yet initialized. */
68 /* The name of the resource file. */
80 struct keybox_handle {
82 int secret; /* this is for a secret keybox */
87 int for_openpgp; /* Used by gpg. */
88 struct keybox_found_s found;
89 struct keybox_found_s saved_found;
97 /* OpenPGP helper structures. */
98 struct _keybox_openpgp_key_info
100 struct _keybox_openpgp_key_info *next;
103 unsigned char grip[20];
104 unsigned char keyid[8];
105 int fprlen; /* Either 16, 20 or 32 */
106 unsigned char fpr[32];
109 struct _keybox_openpgp_uid_info
111 struct _keybox_openpgp_uid_info *next;
116 struct _keybox_openpgp_info
118 int is_secret; /* True if this is a secret key. */
119 unsigned int nsubkeys;/* Total number of subkeys. */
120 unsigned int nuids; /* Total number of user IDs in the keyblock. */
121 unsigned int nsigs; /* Total number of signatures in the keyblock. */
123 /* Note, we use 2 structs here to better cope with the most common
124 use of having one primary and one subkey - this allows us to
125 statically allocate this structure and only malloc stuff for more
127 struct _keybox_openpgp_key_info primary;
128 struct _keybox_openpgp_key_info subkeys;
129 struct _keybox_openpgp_uid_info uids;
131 typedef struct _keybox_openpgp_info *keybox_openpgp_info_t;
134 /* Don't know whether this is needed: */
135 /* static struct { */
139 /* int preserve_permissions; */
142 /*-- keybox-init.c --*/
143 void _keybox_close_file (KEYBOX_HANDLE hd);
146 /*-- keybox-blob.c --*/
147 gpg_error_t _keybox_create_openpgp_blob (KEYBOXBLOB *r_blob,
148 keybox_openpgp_info_t info,
149 const unsigned char *image,
152 char *_keybox_x509_email_kludge (const char *name);
154 #ifdef KEYBOX_WITH_X509
155 int _keybox_create_x509_blob (KEYBOXBLOB *r_blob, ksba_cert_t cert,
156 unsigned char *sha1_digest, int as_ephemeral);
157 #endif /*KEYBOX_WITH_X509*/
159 int _keybox_new_blob (KEYBOXBLOB *r_blob,
160 unsigned char *image, size_t imagelen,
162 void _keybox_release_blob (KEYBOXBLOB blob);
163 const unsigned char *_keybox_get_blob_image (KEYBOXBLOB blob, size_t *n);
164 off_t _keybox_get_blob_fileoffset (KEYBOXBLOB blob);
165 void _keybox_update_header_blob (KEYBOXBLOB blob, int for_openpgp);
167 /*-- keybox-openpgp.c --*/
168 gpg_error_t _keybox_parse_openpgp (const unsigned char *image, size_t imagelen,
170 keybox_openpgp_info_t info);
171 void _keybox_destroy_openpgp_info (keybox_openpgp_info_t info);
174 /*-- keybox-file.c --*/
175 int _keybox_read_blob (KEYBOXBLOB *r_blob, estream_t fp, int *skipped_deleted);
176 int _keybox_write_blob (KEYBOXBLOB blob, estream_t fp, FILE *outfp);
178 /*-- keybox-search.c --*/
179 gpg_err_code_t _keybox_get_flag_location (const unsigned char *buffer,
182 size_t *flag_off, size_t *flag_size);
185 blob_get_type (KEYBOXBLOB blob)
187 const unsigned char *buffer;
190 buffer = _keybox_get_blob_image (blob, &length);
192 return -1; /* blob too short */
198 /*-- keybox-dump.c --*/
199 int _keybox_dump_blob (KEYBOXBLOB blob, FILE *fp);
200 int _keybox_dump_file (const char *filename, int stats_only, FILE *outfp);
201 int _keybox_dump_find_dups (const char *filename, int print_them, FILE *outfp);
202 int _keybox_dump_cut_records (const char *filename, unsigned long from,
203 unsigned long to, FILE *outfp);
206 /*-- keybox-util.c --*/
209 * A couple of handy macros
213 #endif /*KEYBOX_DEFS_H*/