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;
102 unsigned char keyid[8];
103 int fprlen; /* Either 16 or 20 */
104 unsigned char fpr[20];
107 struct _keybox_openpgp_uid_info
109 struct _keybox_openpgp_uid_info *next;
114 struct _keybox_openpgp_info
116 int is_secret; /* True if this is a secret key. */
117 unsigned int nsubkeys;/* Total number of subkeys. */
118 unsigned int nuids; /* Total number of user IDs in the keyblock. */
119 unsigned int nsigs; /* Total number of signatures in the keyblock. */
121 /* Note, we use 2 structs here to better cope with the most common
122 use of having one primary and one subkey - this allows us to
123 statically allocate this structure and only malloc stuff for more
125 struct _keybox_openpgp_key_info primary;
126 struct _keybox_openpgp_key_info subkeys;
127 struct _keybox_openpgp_uid_info uids;
129 typedef struct _keybox_openpgp_info *keybox_openpgp_info_t;
132 /* Don't know whether this is needed: */
133 /* static struct { */
137 /* int preserve_permissions; */
140 /*-- keybox-init.c --*/
141 void _keybox_close_file (KEYBOX_HANDLE hd);
144 /*-- keybox-blob.c --*/
145 gpg_error_t _keybox_create_openpgp_blob (KEYBOXBLOB *r_blob,
146 keybox_openpgp_info_t info,
147 const unsigned char *image,
150 #ifdef KEYBOX_WITH_X509
151 int _keybox_create_x509_blob (KEYBOXBLOB *r_blob, ksba_cert_t cert,
152 unsigned char *sha1_digest, int as_ephemeral);
153 #endif /*KEYBOX_WITH_X509*/
155 int _keybox_new_blob (KEYBOXBLOB *r_blob,
156 unsigned char *image, size_t imagelen,
158 void _keybox_release_blob (KEYBOXBLOB blob);
159 const unsigned char *_keybox_get_blob_image (KEYBOXBLOB blob, size_t *n);
160 off_t _keybox_get_blob_fileoffset (KEYBOXBLOB blob);
161 void _keybox_update_header_blob (KEYBOXBLOB blob, int for_openpgp);
163 /*-- keybox-openpgp.c --*/
164 gpg_error_t _keybox_parse_openpgp (const unsigned char *image, size_t imagelen,
166 keybox_openpgp_info_t info);
167 void _keybox_destroy_openpgp_info (keybox_openpgp_info_t info);
170 /*-- keybox-file.c --*/
171 int _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted);
172 int _keybox_write_blob (KEYBOXBLOB blob, FILE *fp);
174 /*-- keybox-search.c --*/
175 gpg_err_code_t _keybox_get_flag_location (const unsigned char *buffer,
178 size_t *flag_off, size_t *flag_size);
181 blob_get_type (KEYBOXBLOB blob)
183 const unsigned char *buffer;
186 buffer = _keybox_get_blob_image (blob, &length);
188 return -1; /* blob too short */
194 /*-- keybox-dump.c --*/
195 int _keybox_dump_blob (KEYBOXBLOB blob, FILE *fp);
196 int _keybox_dump_file (const char *filename, int stats_only, FILE *outfp);
197 int _keybox_dump_find_dups (const char *filename, int print_them, FILE *outfp);
198 int _keybox_dump_cut_records (const char *filename, unsigned long from,
199 unsigned long to, FILE *outfp);
202 /*-- keybox-util.c --*/
205 * A couple of handy macros
209 #endif /*KEYBOX_DEFS_H*/