d03ab969 |
1 | /* -*-c-*- |
2 | * |
b817bfc6 |
3 | * $Id: key.h,v 1.11 2004/04/08 01:36:15 mdw Exp $ |
d03ab969 |
4 | * |
5 | * Simple key management |
6 | * |
d11a0bf7 |
7 | * (c) 1999 Straylight/Edgeware |
d03ab969 |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
b3f05084 |
30 | #ifndef CATACOMB_KEY_H |
31 | #define CATACOMB_KEY_H |
d03ab969 |
32 | |
33 | #ifdef __cplusplus |
34 | extern "C" { |
35 | #endif |
36 | |
37 | /*----- Header files ------------------------------------------------------*/ |
38 | |
39 | #include <stdio.h> |
40 | #include <time.h> |
41 | |
42 | #include <mLib/bits.h> |
d11a0bf7 |
43 | #include <mLib/dstr.h> |
d03ab969 |
44 | #include <mLib/hash.h> |
45 | #include <mLib/sym.h> |
46 | |
052b36d0 |
47 | #ifndef CATACOMB_KEY_DATA_H |
48 | # include "key-data.h" |
49 | #endif |
50 | |
981bf127 |
51 | #ifndef CATACOMB_GHASH_H |
52 | # include "ghash.h" |
53 | #endif |
54 | |
d11a0bf7 |
55 | #ifndef CATACOMB_MP_H |
56 | # include "mp.h" |
57 | #endif |
58 | |
d03ab969 |
59 | /*----- Data structures ---------------------------------------------------*/ |
60 | |
61 | /* --- Key attributes --- * |
62 | * |
63 | * Each attribute is stored as a symbol in a symbol table. The value is |
64 | * the plain (not url-encoded) text to be written to the the file. If the |
65 | * value is binary data, then by this point it's base-64 encoded. |
66 | */ |
67 | |
68 | typedef struct key_attr { |
69 | sym_base _b; /* Symbol table data */ |
70 | char *p; /* Pointer to attribute value */ |
71 | } key_attr; |
72 | |
73 | /* --- Main key structure --- * |
74 | * |
75 | * Each key is stored in two symbol tables, one indexed by keyid, and the |
76 | * other indexed by type. Because many keys can have the same type, the type |
77 | * table contains a list of keys, sorted in descending order of expiry. |
78 | */ |
79 | |
80 | typedef struct key { |
d11a0bf7 |
81 | |
82 | /* --- Hashtable management --- */ |
83 | |
d03ab969 |
84 | hash_base _b; /* Symbol table data */ |
85 | struct key *next; /* Next key of the same type */ |
d11a0bf7 |
86 | |
87 | /* --- Basic key attributes --- */ |
88 | |
d03ab969 |
89 | uint32 id; /* Key id used to name it */ |
d11a0bf7 |
90 | char *tag; /* Textual tag name */ |
d03ab969 |
91 | char *type; /* Textual key type */ |
d03ab969 |
92 | time_t exp, del; /* Expiry times for keys */ |
d11a0bf7 |
93 | |
94 | /* --- The key data itself --- */ |
95 | |
96 | key_data k; /* The actual key data */ |
97 | |
98 | /* --- Other attributes and commentary --- */ |
99 | |
d03ab969 |
100 | sym_table a; /* Hashtable of key attributes */ |
101 | char *c; /* Any additional comments */ |
102 | } key; |
103 | |
104 | /* --- The keys-by-type entries --- */ |
105 | |
d11a0bf7 |
106 | typedef struct key_ref { |
d03ab969 |
107 | sym_base _b; /* Symbol table data */ |
108 | key *k; /* Pointer to first key in list */ |
d11a0bf7 |
109 | } key_ref; |
d03ab969 |
110 | |
111 | /* --- A key file --- */ |
112 | |
113 | typedef struct key_file { |
114 | FILE *fp; /* File pointer open on file */ |
d03ab969 |
115 | char *name; /* Filename used to create it */ |
116 | unsigned f; /* Various useful flags */ |
117 | hash_table byid; /* Table of keys by keyid */ |
118 | sym_table bytype; /* Table of keys by type */ |
d11a0bf7 |
119 | sym_table bytag; /* Table of keys by tag */ |
d03ab969 |
120 | size_t idload; /* Loading on id table */ |
121 | } key_file; |
122 | |
123 | /* --- Key file flags --- */ |
124 | |
16efd15b |
125 | #define KF_WRITE 1u /* File opened for writing */ |
126 | #define KF_MODIFIED 2u /* File has been modified */ |
d03ab969 |
127 | |
128 | /* --- Iterating over keys --- * |
129 | * |
130 | * Both of these are simple symbol table iterators, but they're made distinct |
131 | * types for the dubious benefits that type safety brings. |
132 | */ |
133 | |
134 | typedef struct { hash_iter i; time_t t; } key_iter; |
135 | typedef struct { sym_iter i; } key_attriter; |
136 | |
cae5cb8e |
137 | /* --- Key fetching --- */ |
138 | |
139 | typedef struct key_fetchdef { |
140 | char *name; /* Name of item */ |
141 | size_t off; /* Offset into target structure */ |
142 | unsigned e; /* Flags for the item */ |
143 | const struct key_fetchdef *kf; /* Substructure pointer */ |
144 | } key_fetchdef; |
145 | |
d03ab969 |
146 | /* --- File opening options --- */ |
147 | |
9f1b58fe |
148 | #define KOPEN_READ 0u |
149 | #define KOPEN_WRITE 1u |
150 | #define KOPEN_MASK 0xff |
151 | #define KOPEN_NOFILE 0x100 |
d03ab969 |
152 | |
153 | /* --- Various other magic numbers --- */ |
154 | |
d03ab969 |
155 | #define KEXP_FOREVER ((time_t)-1) /* Never expire this key */ |
156 | #define KEXP_EXPIRE ((time_t)-2) /* Expire this key when unused */ |
157 | |
d11a0bf7 |
158 | /* --- Key error codes --- */ |
159 | |
160 | enum { |
052b36d0 |
161 | KERR_OK = 0, /* No error */ |
d11a0bf7 |
162 | KERR_BADTAG = -1, /* Malformed tag string */ |
163 | KERR_BADTYPE = -2, /* Malformed type string */ |
164 | KERR_BADCOMMENT = -3, /* Malformed comment string */ |
165 | KERR_DUPID = -4, /* Duplicate keyid */ |
166 | KERR_DUPTAG = -5, /* Duplicate key tag string */ |
167 | KERR_READONLY = -6, /* Key file is read-only */ |
168 | KERR_WILLEXPIRE = -7, /* Key will eventually expire */ |
169 | KERR_EXPIRED = -8, /* Key has already expired */ |
170 | KERR_BADFLAGS = -9, /* Error in flags string */ |
052b36d0 |
171 | KERR_BADPASS = -10, /* Error decrypting locked key */ |
86a47753 |
172 | KERR_WRONGTYPE = -11, /* Key has incorrect type */ |
052b36d0 |
173 | KERR_NOTFOUND = -12, /* Key couldn't be found */ |
981bf127 |
174 | KERR_BADATTR = -13, /* Malformed attribute name */ |
d11a0bf7 |
175 | KERR_MAX /* Largest possible error */ |
176 | }; |
177 | |
178 | /* --- Write error codes --- */ |
d03ab969 |
179 | |
180 | enum { |
181 | KWRITE_OK, /* Everything went fine */ |
182 | KWRITE_FAIL = -1, /* Close attempt failed */ |
183 | KWRITE_BROKEN = -2 /* Key ring needs manual fixing */ |
184 | }; |
185 | |
d11a0bf7 |
186 | /* --- Error reporting functions for @key_merge@ and @key_open@ --- */ |
187 | |
188 | typedef void key_reporter(const char */*file*/, int /*line*/, |
189 | const char */*err*/, void */*p*/); |
190 | |
d03ab969 |
191 | /* --- Macros for testing expiry --- */ |
192 | |
193 | #define KEY_EXPIRED(now, exp) \ |
194 | ((exp) == KEXP_EXPIRE || ((exp) != KEXP_FOREVER && (exp) < (now))) |
195 | |
d11a0bf7 |
196 | /*----- Reading and writing keys and files --------------------------------*/ |
d03ab969 |
197 | |
198 | /* --- @key_merge@ --- * |
199 | * |
200 | * Arguments: @key_file *f@ = pointer to file structure |
201 | * @const char *file@ = name of file (for error messages) |
202 | * @FILE *fp@ = file handle to read from |
d11a0bf7 |
203 | * @key_reporter *rep@ = error reporting function |
204 | * @void *arg@ = argument for function |
d03ab969 |
205 | * |
d11a0bf7 |
206 | * Returns: Error code (one of the @KERR@ constants). |
d03ab969 |
207 | * |
208 | * Use: Reads keys from a file, and inserts them into the file. |
209 | */ |
210 | |
d11a0bf7 |
211 | extern int key_merge(key_file */*f*/, const char */*file*/, FILE */*fp*/, |
212 | key_reporter */*rep*/, void */*arg*/); |
d03ab969 |
213 | |
214 | /* --- @key_extract@ --- * |
215 | * |
216 | * Arguments: @key_file *f@ = pointer to file structure |
217 | * @key *k@ = key to extract |
218 | * @FILE *fp@ = file to write on |
d11a0bf7 |
219 | * @const key_filter *kf@ = pointer to key selection block |
d03ab969 |
220 | * |
221 | * Returns: Zero if OK, EOF on error. |
222 | * |
223 | * Use: Extracts a key to an ouptut file. |
224 | */ |
225 | |
d11a0bf7 |
226 | extern int key_extract(key_file */*f*/, key */*k*/, FILE */*fp*/, |
227 | const key_filter */*kf*/); |
d03ab969 |
228 | |
229 | /* --- @key_open@ --- * |
230 | * |
231 | * Arguments: @key_file *f@ = pointer to file structure to initialize |
232 | * @const char *file@ = pointer to the file name |
9f1b58fe |
233 | * @unsigned how@ = opening options (@KOPEN_*@). |
d11a0bf7 |
234 | * @key_reporter *rep@ = error reporting function |
235 | * @void *arg@ = argument for function |
d03ab969 |
236 | * |
237 | * Returns: Zero if it worked, nonzero otherwise. |
238 | * |
239 | * Use: Opens a key file, reads its contents, and stores them in a |
240 | * structure. The file is locked appropriately until closed |
241 | * using @key_close@. On an error, everything is cleared away |
242 | * tidily. If the file is opened with @KOPEN_WRITE@, it's |
243 | * created if necessary, with read and write permissions for its |
244 | * owner only. |
245 | */ |
246 | |
9f1b58fe |
247 | extern int key_open(key_file */*f*/, const char */*file*/, unsigned /*how*/, |
d11a0bf7 |
248 | key_reporter */*rep*/, void */*arg*/); |
d03ab969 |
249 | |
250 | /* --- @key_close@ --- * |
251 | * |
252 | * Arguments: @key_file *f@ = pointer to key file block |
253 | * |
254 | * Returns: A @KWRITE_@ code indicating how it went. |
255 | * |
256 | * Use: Frees all the key data, writes any changes. Make sure that |
257 | * all hell breaks loose if this returns @KWRITE_BROKEN@. |
258 | */ |
259 | |
260 | extern int key_close(key_file */*f*/); |
261 | |
d11a0bf7 |
262 | /* --- @key_save@ --- * |
263 | * |
264 | * Arguments: @key_file *f@ = pointer to key file block |
265 | * |
266 | * Returns: A @KWRITE_@ code indicating how well it worked. |
267 | * |
268 | * Use: Writes a key file's data back to the actual file. This code |
269 | * is extremely careful about error handling. It should usually |
270 | * be able to back out somewhere sensible, but it can tell when |
271 | * it's got itself into a real pickle and starts leaving well |
272 | * alone. |
273 | * |
274 | * Callers, please make sure that you ring alarm bells when this |
275 | * function returns @KWRITE_BROKEN@. |
276 | */ |
277 | |
278 | extern int key_save(key_file */*f*/); |
279 | |
280 | /* --- @key_lockfile@ --- * |
281 | * |
282 | * Arguments: @key_file *f@ = pointer to file structure to initialize |
283 | * @const char *file@ = pointer to the file name |
9f1b58fe |
284 | * @unsigned how@ = opening options (@KOPEN_*@). |
d11a0bf7 |
285 | * |
286 | * Returns: Zero if it worked, nonzero otherwise. |
287 | * |
288 | * Use: Opens a keyfile and stores the information needed for |
289 | * continued access in the structure. |
290 | * |
291 | * If the file is opened with @KOPEN_WRITE@, it's created if |
292 | * necessary with read and write permissions for owner only, and |
293 | * locked for update while it's open. |
294 | * |
295 | * This is a system-dependent routine, and only really intended |
296 | * for the private use of @key_open@. |
297 | */ |
298 | |
9f1b58fe |
299 | extern int key_lockfile(key_file */*f*/, const char */*file*/, |
300 | unsigned /*how*/); |
d11a0bf7 |
301 | |
302 | /*----- Creating and manipulating keys ------------------------------------*/ |
303 | |
d03ab969 |
304 | /* --- @key_new@ --- |
305 | * |
306 | * Arguments: @key_file *f@ = pointer to key file |
d11a0bf7 |
307 | * @uint32 id@ = keyid to set |
d03ab969 |
308 | * @const char *type@ = the type of this key |
d03ab969 |
309 | * @time_t exp@ = when the key expires |
d11a0bf7 |
310 | * @int *err@ = where to store the error condition |
d03ab969 |
311 | * |
312 | * Returns: Key block containing new data, or null if it couldn't be |
313 | * done. |
314 | * |
315 | * Use: Attaches a new key to a key file. You must have a writable |
316 | * key file for this to work. |
317 | * |
318 | * The type is a key type string. This interface doesn't care |
319 | * about how type strings are formatted: it just treats them as |
320 | * opaque gobs of text. Clients are advised to choose some |
321 | * standard for representing key types, though. |
322 | * |
d03ab969 |
323 | * The expiry time should either be a time in the future, or the |
324 | * magic value @KEXP_FOREVER@ which means `never expire this |
325 | * key'. Be careful with `forever' keys. If I were you, I'd |
326 | * use a more sophisticated key management system than this for |
327 | * them. |
328 | * |
d11a0bf7 |
329 | * You have to set the actual key yourself. |
d03ab969 |
330 | */ |
331 | |
d11a0bf7 |
332 | extern key *key_new(key_file */*f*/, uint32 /*id*/, const char */*type*/, |
333 | time_t /*exp*/, int */*err*/); |
d03ab969 |
334 | |
335 | /* --- @key_delete@ --- * |
336 | * |
337 | * Arguments: @key_file *f@ = pointer to file block |
338 | * @key *k@ = key to delete |
339 | * |
d11a0bf7 |
340 | * Returns: Error code (one of the @KERR@ constants). |
d03ab969 |
341 | * |
342 | * Use: Removes the given key from the list. The key file must be |
343 | * writable. (Due to the horridness of the data structures, |
344 | * deleted keys aren't actually removed, just marked so that |
345 | * they can't be looked up or iterated over. One upshot of |
346 | * this is that they don't get written back to the file when |
347 | * it's closed.) |
348 | */ |
349 | |
d11a0bf7 |
350 | extern int key_delete(key_file */*f*/, key */*k*/); |
d03ab969 |
351 | |
9313a3d5 |
352 | /* --- @key_expired@ --- * |
353 | * |
354 | * Arguments: @key *k@ = pointer to key block |
355 | * |
356 | * Returns: Zero if the key is OK, nonzero if it's expired. |
357 | */ |
358 | |
359 | int key_expired(key */*k*/); |
360 | |
d03ab969 |
361 | /* --- @key_expire@ --- * |
362 | * |
363 | * Arguments: @key_file *f@ = pointer to file block |
364 | * @key *k@ = pointer to key block |
365 | * |
d11a0bf7 |
366 | * Returns: Error code (one of the @KERR@ constants). |
d03ab969 |
367 | * |
368 | * Use: Immediately marks the key as expired. It may be removed |
369 | * immediately, if it is no longer required, and will be removed |
370 | * by a tidy operation when it is no longer required. The key |
371 | * file must be writable. |
372 | */ |
373 | |
d11a0bf7 |
374 | extern int key_expire(key_file */*f*/, key */*k*/); |
d03ab969 |
375 | |
376 | /* --- @key_used@ --- * |
377 | * |
378 | * Arguments: @key_file *f@ = pointer to key file |
379 | * @key *k@ = pointer to key block |
380 | * @time_t t@ = when key can be removed |
381 | * |
382 | * Returns: Zero if OK, nonzero on failure. |
383 | * |
384 | * Use: Marks a key as being required until a given time. Even |
385 | * though the key may expire before then (and won't be returned |
386 | * by type after that time), it will still be available when |
387 | * requested explicitly by id. The key file must be writable. |
388 | * |
389 | * The only (current) reason for failure is attempting to use |
390 | * a key which can expire for something which can't. |
391 | */ |
392 | |
393 | extern int key_used(key_file */*f*/, key */*k*/, time_t /*t*/); |
394 | |
981bf127 |
395 | /* --- @key_fingerprint@ --- * |
396 | * |
397 | * Arguments: @key *k@ = the key to fingerprint |
398 | * @ghash *h@ = the hash to use |
399 | * @const key_filter *kf@ = filter to apply |
400 | * |
401 | * Returns: Nonzero if the key slightly matched the filter. |
402 | * |
403 | * Use: Updates the hash context with the key contents. |
404 | */ |
405 | |
406 | extern int key_fingerprint(key */*k*/, ghash */*h*/, |
407 | const key_filter */*kf*/); |
408 | |
d11a0bf7 |
409 | /*----- Setting and reading attributes ------------------------------------*/ |
410 | |
411 | /* --- @key_chkident@ --- * |
412 | * |
413 | * Arguments: @const char *p@ = pointer to a type string |
414 | * |
415 | * Returns: Zero if OK, -1 on error. |
416 | * |
417 | * Use: Checks whether an identification component string is OK. |
418 | */ |
419 | |
420 | extern int key_chkident(const char */*p*/); |
421 | |
422 | /* --- @key_chkcomment@ --- * |
423 | * |
424 | * Arguments: @const char *p@ = pointer to a comment string |
425 | * |
426 | * Returns: Zero if OK, -1 on error. |
427 | * |
428 | * Use: Checks whether a comment string is OK. |
429 | */ |
430 | |
431 | extern int key_chkcomment(const char */*p*/); |
432 | |
433 | /* --- @key_setcomment@ --- * |
434 | * |
435 | * Arguments: @key_file *f@ = pointer to key file block |
436 | * @key *k@ = pointer to key block |
437 | * @const char *c@ = pointer to comment to set, or zero |
438 | * |
439 | * Returns: Error code (one of the @KERR@ constants). |
440 | * |
441 | * Use: Replaces the key's current comment with a new one. |
442 | */ |
443 | |
444 | extern int key_setcomment(key_file */*f*/, key */*k*/, const char */*c*/); |
445 | |
446 | /* --- @key_settag@ --- * |
447 | * |
448 | * Arguments: @key_file *f@ = pointer to key file block |
449 | * @key *k@ = pointer to key block |
450 | * @const char *tag@ = pointer to comment to set, or zero |
451 | * |
452 | * Returns: Error code (one of the @KERR@ constants). |
453 | * |
454 | * Use: Replaces the key's current tag with a new one. |
455 | */ |
456 | |
457 | extern int key_settag(key_file */*f*/, key */*k*/, const char */*tag*/); |
458 | |
459 | /* --- @key_fulltag@ --- * |
460 | * |
461 | * Arguments: @key *k@ = pointer to key |
462 | * @dstr *d@ = pointer to destination string |
463 | * |
464 | * Returns: --- |
465 | * |
466 | * Use: Emits the key's full tag, which has the form |
467 | * `ID:TYPE[:TAG]'. This is used in the textual file format, |
468 | * and to identify passphrases for locked keys. |
469 | */ |
470 | |
471 | extern void key_fulltag(key */*k*/, dstr */*d*/); |
472 | |
473 | /* --- @key_qtag@ --- * |
474 | * |
475 | * Arguments: @key_file *f@ = key file to find a key from |
476 | * @const char *tag@ = pointer to tag string |
477 | * @dstr *d@ = pointer to string for full tag name |
478 | * @key **k@ = where to store the key pointer |
479 | * @key_data **kd@ = where to store the key data pointer |
480 | * |
481 | * Returns: Zero if OK, nonzero if it failed. |
482 | * |
483 | * Use: Performs a full lookup on a qualified tag name. The tag is |
484 | * qualified by the names of subkeys, separated by dots. Hence, |
485 | * a qualified tag is ID|TAG[.TAG...]. The various result |
486 | * pointers can be null to indicate that the result isn't |
487 | * interesting. |
488 | */ |
489 | |
490 | extern int key_qtag(key_file */*f*/, const char */*tag*/, |
491 | dstr */*d*/, key **/*k*/, key_data **/*kd*/); |
492 | |
493 | /* --- @key_getattr@ --- * |
494 | * |
495 | * Arguments: @key_file *f@ = pointer to file |
496 | * @key *k@ = pointer to key |
497 | * @const char *n@ = pointer to attribute name |
498 | * |
499 | * Returns: Pointer to attribute value, or null if not found. |
500 | * |
501 | * Use: Returns the value of a key attribute. |
502 | */ |
503 | |
504 | extern const char *key_getattr(key_file */*f*/, key */*k*/, |
505 | const char */*n*/); |
506 | |
507 | /* --- @key_putattr@ --- * |
508 | * |
509 | * Arguments: @key_file *f@ = pointer to file |
510 | * @key *k@ = pointer to key |
511 | * @const char *n@ = pointer to attribute name |
512 | * @const char *v@ = pointer to attribute value or null |
513 | * |
514 | * Returns: Error code (one of the @KERR@ constants). |
515 | * |
516 | * Use: Inserts an attribute on a key. If an attribute with the same |
517 | * name already exists, it is deleted. Setting a null value |
518 | * removes the attribute. |
519 | */ |
520 | |
521 | extern int key_putattr(key_file */*f*/, key */*k*/, |
522 | const char */*n*/, const char */*v*/); |
523 | |
524 | /* --- @key_mkattriter@ --- * |
525 | * |
526 | * Arguments: @key_attriter *i@ = pointer to attribute iterator |
527 | * @key *k@ = pointer to key |
528 | * |
529 | * Returns: --- |
530 | * |
531 | * Use: Initializes an attribute iterator. The attributes are |
532 | * returned by @key_nextattr@. |
533 | */ |
534 | |
535 | extern void key_mkattriter(key_attriter */*i*/, key */*k*/); |
536 | |
537 | /* --- @key_nextattr@ --- * |
538 | * |
539 | * Arguments: @key_attriter *i@ = pointer to attribute iterator |
540 | * @const char **n, **v@ = pointers to name and value |
541 | * |
542 | * Returns: Zero if no attribute available, or nonzero if returned OK. |
543 | * |
544 | * Use: Returns the next attribute. |
545 | */ |
546 | |
547 | extern int key_nextattr(key_attriter */*i*/, |
548 | const char **/*n*/, const char **/*v*/); |
549 | |
550 | /*----- Searching and iterating -------------------------------------------*/ |
551 | |
552 | /* --- @key_bytype@ --- * |
553 | * |
554 | * Arguments: @key_file *f@ = key file we want a key from |
555 | * @const char *type@ = type string for desired key |
556 | * |
557 | * Returns: Pointer to the best key to use, or null. |
558 | * |
559 | * Use: Looks up a key by its type. Returns the key with the latest |
560 | * expiry time. This function will not return an expired key. |
561 | */ |
562 | |
563 | extern key *key_bytype(key_file */*f*/, const char */*type*/); |
564 | |
565 | /* --- @key_byid@ --- * |
566 | * |
567 | * Arguments: @key_file *f@ = key file to find a key from |
568 | * @uint32 id@ = id to look for |
569 | * |
570 | * Returns: Key with matching id. |
571 | * |
572 | * Use: Returns a key given its id. This function will return an |
573 | * expired key, but not a deleted one. |
574 | */ |
575 | |
576 | extern key *key_byid(key_file */*f*/, uint32 /*id*/); |
577 | |
578 | /* --- @key_bytag@ --- * |
579 | * |
580 | * Arguments: @key_file *f@ = key file to find a key from |
581 | * @const char *tag@ = pointer to tag string |
582 | * |
583 | * Returns: Key with matching id or tag. |
584 | * |
585 | * Use: Returns a key given its tag or id. This function will return |
586 | * an expired key, but not a deleted one. |
587 | */ |
588 | |
589 | extern key *key_bytag(key_file */*f*/, const char */*tag*/); |
590 | |
591 | /* --- @key_mkiter@ --- * |
592 | * |
593 | * Arguments: @key_iter *i@ = pointer to iterator object |
594 | * @key_file *f@ = pointer to file structure |
595 | * |
596 | * Returns: --- |
597 | * |
598 | * Use: Initializes a key iterator. The keys are returned by |
599 | * @key_next@. |
600 | */ |
601 | |
602 | extern void key_mkiter(key_iter */*i*/, key_file */*f*/); |
603 | |
604 | /* --- @key_next@ --- * |
605 | * |
606 | * Arguments: @key_iter *i@ = pointer to iterator object |
607 | * |
608 | * Returns: Pointer to next key, or null. |
609 | * |
610 | * Use: Returns the next key in some arbitrary sequence. |
611 | */ |
612 | |
613 | extern key *key_next(key_iter */*i*/); |
614 | |
cae5cb8e |
615 | /*----- Fetching key data conveniently ------------------------------------*/ |
616 | |
617 | /* --- @key_fetchinit@ --- * |
618 | * |
619 | * Arguments: @const key_fetchdef *kf@ = pointer to base definition |
620 | * @key_packstruct *kps@ = pointer to destination packing def |
621 | * @void *p@ = pointer to destination block |
622 | * |
623 | * Returns: Pointer to packing definition. |
624 | * |
625 | * Use: Initializes a packing definition (@key_packdef@ structure). |
626 | * If @kps@ is null on entry, an appropriately sized block is |
627 | * allocated automatically. Otherwise it must be large enough. |
628 | */ |
629 | |
630 | extern key_packdef *key_fetchinit(const key_fetchdef */*kf*/, |
631 | key_packstruct */*kp*/, void */*p*/); |
632 | |
633 | /* --- @key_fetch@ --- * |
634 | * |
635 | * Arguments: @key_packdef *kp@ = pointer to packing structure |
636 | * @key *k@ = key file containing desired key |
637 | * |
638 | * Returns: Error code, or zero. |
639 | * |
640 | * Use: Fetches an unpacked key from a packed one. |
641 | */ |
642 | |
643 | extern int key_fetch(key_packdef */*kp*/, key */*k*/); |
644 | |
645 | /* --- @key_fetchbyname@ --- * |
646 | * |
647 | * Arguments: @key_packdef *kp@ = pointer to packing structure |
648 | * @key_file *kf@ = key file containing desired key |
649 | * @const char *tag@ = user's tag describing the key |
650 | * |
651 | * Returns: Error code, or zero. |
652 | * |
653 | * Use: Fetches a named key from a key file and unpacks it |
654 | * conveniently. |
655 | */ |
656 | |
657 | extern int key_fetchbyname(key_packdef */*kp*/, |
658 | key_file */*kf*/, const char */*tag*/); |
659 | |
660 | /* --- @key_fetchdone@ --- * |
661 | * |
662 | * Arguments: @key_packdef *kp@ = pointer to packing structure |
663 | * |
664 | * Returns: --- |
665 | * |
666 | * Use: Frees a packing structure. If the structure was allocated by |
667 | * @key_fetchinit@ then it is freed. |
668 | */ |
669 | |
670 | extern void key_fetchdone(key_packdef */*kp*/); |
671 | |
d11a0bf7 |
672 | /*----- Other functions ---------------------------------------------------*/ |
673 | |
674 | /* --- @key_moan@ --- * |
675 | * |
676 | * Arguments: @const char *file@ = name of the file |
677 | * @int line@ = line number in file |
678 | * @const char *msg@ = error message |
679 | * @void *p@ = argument pointer |
680 | * |
681 | * Returns: --- |
682 | * |
683 | * Use: Reports an error message about loading a key file. |
684 | */ |
685 | |
686 | extern void key_moan(const char */*file*/, int /*line*/, |
687 | const char */*msg*/, void */*p*/); |
688 | |
689 | /* --- @key_strerror@ --- * |
690 | * |
691 | * Arguments: @int err@ = error code from @key_new@ |
692 | * |
693 | * Returns: Pointer to error string. |
694 | * |
695 | * Use: Translates a @KERR@ error code into a human-readable string. |
696 | */ |
697 | |
698 | extern const char *key_strerror(int /*err*/); |
699 | |
d03ab969 |
700 | /*----- That's all, folks -------------------------------------------------*/ |
701 | |
702 | #ifdef __cplusplus |
703 | } |
704 | #endif |
705 | |
706 | #endif |