3 * $Id: key.h,v 1.3 1999/12/22 15:47:48 mdw Exp $
5 * Simple key management
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.3 1999/12/22 15:47:48 mdw
34 * Major key-management revision.
36 * Revision 1.2 1999/12/10 23:29:48 mdw
37 * Change header file guard names.
39 * Revision 1.1 1999/09/03 08:41:12 mdw
44 #ifndef CATACOMB_KEY_H
45 #define CATACOMB_KEY_H
51 /*----- Header files ------------------------------------------------------*/
56 #include <mLib/bits.h>
57 #include <mLib/dstr.h>
58 #include <mLib/hash.h>
65 /*----- Data structures ---------------------------------------------------*/
67 /* --- Key attributes --- *
69 * Each attribute is stored as a symbol in a symbol table. The value is
70 * the plain (not url-encoded) text to be written to the the file. If the
71 * value is binary data, then by this point it's base-64 encoded.
74 typedef struct key_attr
{
75 sym_base _b
; /* Symbol table data */
76 char *p
; /* Pointer to attribute value */
79 /* --- Key data structure --- */
81 typedef struct key_data
{
82 unsigned e
; /* Encoding type for key data */
85 /* --- Plain binary key data --- *
87 * Also used for encrypted key types.
91 octet
*k
; /* Actual key data */
92 size_t sz
; /* Size of the key data */
93 } k
; /* Plain binary key */
95 /* --- Multiprecision integer keys --- */
97 mp
*m
; /* Multiprecision integer */
99 /* --- Structured key data --- */
101 sym_table s
; /* Structured key data */
105 typedef struct key_struct
{
110 /* --- Key binary encoding --- *
112 * The binary encoding consists of a header containing a 16-bit encoding type
113 * and a 16-bit length, followed immediately by the key data, followed by
114 * between zero and three zero bytes to make the total length a multiple of
115 * four. The format of the following data depends on the encoding type:
117 * @KENC_BINARY@ Binary data.
119 * @KENC_MP@ Octet array interpreted in big-endian byte order.
121 * @KENC_STRUCT@ An array of pairs, each containing a string (8-bit
122 * length followed by data and zero-padding to 4-byte
123 * boundary) and key binary encodings.
125 * @KENC_ENCRYPT@ Binary data, format
128 /* --- Key encoding methods and other flags--- */
132 /* --- Bottom two bits are the encoding type --- */
134 KF_ENCMASK
= 0x03, /* Encoding mask */
135 KENC_BINARY
= 0x00, /* Plain binary key (@k@) */
136 KENC_MP
= 0x01, /* Multiprecision integer (@i@) */
137 KENC_STRUCT
= 0x02, /* Structured key data (@s@) */
138 KENC_ENCRYPT
= 0x03, /* Encrypted key type (@k@) */
140 /* --- Key category bits --- */
142 KF_CATMASK
= 0x0c, /* Category mask */
143 KCAT_SYMM
= 0x00, /* Symmetric encryption key */
144 KCAT_PRIV
= 0x04, /* Private (asymmetric) key */
145 KCAT_PUB
= 0x08, /* Public (asymmetric) key */
146 KCAT_SHARE
= 0x0c, /* Shared (asymmetric) key */
147 KF_NONSECRET
= 0x08, /* Bit flag for non-secret keys */
149 /* --- Other flags --- */
151 KF_BURN
= 0x10, /* Burn key after use */
153 /* --- Tag end --- */
155 KENC_MAX
/* Dummy limit constant */
158 /* --- Key flag filtering --- */
160 typedef struct key_filter
{
165 /* --- Matching aginst key selection --- */
167 #define KEY_MATCH(kd, kf) \
169 ((kd)->e & KF_ENCMASK) == KENC_STRUCT || \
170 ((kd)->e & (kf)->m) == (kf)->f)
172 /* --- Main key structure --- *
174 * Each key is stored in two symbol tables, one indexed by keyid, and the
175 * other indexed by type. Because many keys can have the same type, the type
176 * table contains a list of keys, sorted in descending order of expiry.
181 /* --- Hashtable management --- */
183 hash_base _b
; /* Symbol table data */
184 struct key
*next
; /* Next key of the same type */
186 /* --- Basic key attributes --- */
188 uint32 id
; /* Key id used to name it */
189 char *tag
; /* Textual tag name */
190 char *type
; /* Textual key type */
191 time_t exp
, del
; /* Expiry times for keys */
193 /* --- The key data itself --- */
195 key_data k
; /* The actual key data */
197 /* --- Other attributes and commentary --- */
199 sym_table a
; /* Hashtable of key attributes */
200 char *c
; /* Any additional comments */
203 /* --- The keys-by-type entries --- */
205 typedef struct key_ref
{
206 sym_base _b
; /* Symbol table data */
207 key
*k
; /* Pointer to first key in list */
210 /* --- A key file --- */
212 typedef struct key_file
{
213 FILE *fp
; /* File pointer open on file */
214 char *name
; /* Filename used to create it */
215 unsigned f
; /* Various useful flags */
216 hash_table byid
; /* Table of keys by keyid */
217 sym_table bytype
; /* Table of keys by type */
218 sym_table bytag
; /* Table of keys by tag */
219 size_t idload
; /* Loading on id table */
222 /* --- Key file flags --- */
225 KF_WRITE
= 1, /* File opened for writing */
226 KF_MODIFIED
= 2 /* File has been modified */
229 /* --- Iterating over keys --- *
231 * Both of these are simple symbol table iterators, but they're made distinct
232 * types for the dubious benefits that type safety brings.
235 typedef struct { hash_iter i
; time_t t
; } key_iter
;
236 typedef struct { sym_iter i
; } key_attriter
;
238 /* --- File opening options --- */
245 /* --- Various other magic numbers --- */
247 #define KEXP_FOREVER ((time_t)-1) /* Never expire this key */
248 #define KEXP_EXPIRE ((time_t)-2) /* Expire this key when unused */
250 /* --- Key error codes --- */
253 KERR_OK
, /* No error */
254 KERR_BADTAG
= -1, /* Malformed tag string */
255 KERR_BADTYPE
= -2, /* Malformed type string */
256 KERR_BADCOMMENT
= -3, /* Malformed comment string */
257 KERR_DUPID
= -4, /* Duplicate keyid */
258 KERR_DUPTAG
= -5, /* Duplicate key tag string */
259 KERR_READONLY
= -6, /* Key file is read-only */
260 KERR_WILLEXPIRE
= -7, /* Key will eventually expire */
261 KERR_EXPIRED
= -8, /* Key has already expired */
262 KERR_BADFLAGS
= -9, /* Error in flags string */
263 KERR_MAX
/* Largest possible error */
266 /* --- Write error codes --- */
269 KWRITE_OK
, /* Everything went fine */
270 KWRITE_FAIL
= -1, /* Close attempt failed */
271 KWRITE_BROKEN
= -2 /* Key ring needs manual fixing */
274 /* --- Error reporting functions for @key_merge@ and @key_open@ --- */
276 typedef void key_reporter(const char */
*file*/
, int /*line*/,
277 const char */
*err*/
, void */
*p*/
);
279 /* --- Macros for testing expiry --- */
281 #define KEY_EXPIRED(now, exp) \
282 ((exp) == KEXP_EXPIRE || ((exp) != KEXP_FOREVER && (exp) < (now)))
284 /*----- Key data manipulation ---------------------------------------------*/
286 /* --- @key_destroy@ --- *
288 * Arguments: @key_data *k@ = pointer to key data to destroy
292 * Use: Destroys a lump of key data.
295 extern void key_destroy(key_data */
*k*/
);
297 /* --- @key_readflags@ --- *
299 * Arguments: @const char *p@ = pointer to string to read
300 * @char **pp@ = where to store the end pointer
301 * @unsigned *ff@ = where to store the flags
302 * @unsigned *mm@ = where to store the mask
304 * Returns: Zero if all went well, nonzero if there was an error.
306 * Use: Reads a flag string.
309 extern int key_readflags(const char */
*p*/
, char **/
*pp*/
,
310 unsigned */
*ff*/
, unsigned */
*mm*/
);
312 /* --- @key_writeflags@ --- *
314 * Arguments: @unsigned f@ = flags to write
315 * @dstr *d@ = pointer to destination string
319 * Use: Emits a flags word as a string representation.
322 extern void key_writeflags(unsigned /*f*/, dstr */
*d*/
);
324 /* --- @key_binary@ --- *
326 * Arguments: @key_data *k@ = pointer to key data block
327 * @const void *p@ = pointer to key data
328 * @size_t sz@ = size of the key data
332 * Use: Sets a binary key in a key data block.
335 extern void key_binary(key_data */
*k*/
, const void */
*p*/
, size_t /*sz*/);
337 /* --- @key_encrypted@ --- *
339 * Arguments: @key_data *k@ = pointer to key data block
340 * @const void *p@ = pointer to key data
341 * @size_t sz@ = size of the key data
345 * Use: Sets an encrypted key in a key data block.
348 extern void key_encrypted(key_data */
*k*/
, const void */
*p*/
, size_t /*sz*/);
350 /* --- @key_mp@ --- *
352 * Arguments: @key_data *k@ = pointer to key data block
353 * @mp *m@ = pointer to the value to set
357 * Use: Sets a multiprecision integer key in a key block.
360 extern void key_mp(key_data */
*k*/
, mp */
*m*/
);
362 /* --- @key_structure@ --- *
364 * Arguments: @key_data *k@ = pointer to key data block
368 * Use: Initializes a structured key type.
371 extern void key_structure(key_data */
*k*/
);
373 /* --- @key_structfind@ --- *
375 * Arguments: @key_data *k@ = pointer to key data block
376 * @const char *tag@ = pointer to tag string
378 * Returns: Pointer to key data block, or null.
380 * Use: Looks up the tag in a structured key.
383 extern key_data
*key_structfind(key_data */
*k*/
, const char */
*tag*/
);
385 /* --- @key_structcreate@ --- *
387 * Arguments: @key_data *k@ = pointer to key data block
388 * @const char *tag@ = pointer to tag string
390 * Returns: Pointer to newly created key data.
392 * Use: Creates a new uninitialized subkey.
395 extern key_data
*key_structcreate(key_data */
*k*/
, const char */
*tag*/
);
397 /* --- @key_match@ --- *
399 * Arguments: @key_data *k@ = pointer to key data block
400 * @const key_filter *kf@ = pointer to filter block
402 * Returns: Nonzero if the key matches the filter.
404 * Use: Checks whether a key matches a filter.
407 extern int key_match(key_data */
*k*/
, const key_filter */
*kf*/
);
409 /* --- @key_do@ --- *
411 * Arguments: @key_data *k@ = pointer to key data block
412 * @const key_filter *kf@ = pointer to filter block
413 * @dstr *d@ = pointer to base string
414 * @int (*func)(key_data *kd, dstr *d, void *p@ = function
415 * @void *p@ = argument to function
417 * Returns: Nonzero return code from function, or zero.
419 * Use: Runs a function over all the leaves of a key.
422 extern int key_do(key_data */
*k*/
, const key_filter */
*kf*/
, dstr */
*d*/
,
423 int (*/
*func*/
)(key_data */
*kd*/
,
424 dstr */
*d*/
, void */
*p*/
),
427 /* --- @key_copy@ --- *
429 * Arguments: @key_data *kd@ = pointer to destination data block
430 * @key_data *k@ = pointer to source data block
431 * @const key_filter *kf@ = pointer to filter block
433 * Returns: Nonzero if an item was actually copied.
435 * Use: Copies a chunk of key data from one place to another.
438 extern int key_copy(key_data */
*kd*/
, key_data */
*k*/
,
439 const key_filter */
*kf*/
);
441 /* --- @key_read@ --- *
443 * Arguments: @const char *p@ = pointer to textual key representation
444 * @key_data *k@ = pointer to output block for key data
445 * @char **pp@ = where to store the end pointer
447 * Returns: Zero if all went well, nonzero if there was a problem.
449 * Use: Parses a textual key description.
452 extern int key_read(const char */
*p*/
, key_data */
*k*/
, char **/
*pp*/
);
454 /* --- @key_write@ --- *
456 * Arguments: @key_data *k@ = pointer to key data
457 * @dstr *d@ = destination string to write on
458 * @const key_filter *kf@ = pointer to key selection block
460 * Returns: Nonzero if any items were actually written.
462 * Use: Writes a key in a textual encoding.
465 extern int key_write(key_data */
*k*/
, dstr */
*d*/
,
466 const key_filter */
*kf*/
);
468 /* --- @key_decode@ --- *
470 * Arguments: @const void *p@ = pointer to buffer to read
471 * @size_t sz@ = size of the buffer
472 * @key_data *k@ = pointer to key data block to write to
474 * Returns: Zero if everything worked, nonzero otherwise.
476 * Use: Decodes a binary representation of a key.
479 extern int key_decode(const void */
*p*/
, size_t /*sz*/, key_data */
*k*/
);
481 /* --- @key_encode@ --- *
483 * Arguments: @key_data *k@ = pointer to key data block
484 * @dstr *d@ = pointer to destination string
485 * @const key_filter *kf@ = pointer to key selection block
487 * Returns: Nonzero if any items were actually written.
489 * Use: Encodes a key block as binary data.
492 extern int key_encode(key_data */
*k*/
, dstr */
*d*/
,
493 const key_filter */
*kf*/
);
495 /* --- @key_plock@ --- *
497 * Arguments: @const char *tag@ = tag to use for passphrase
498 * @key_data *k@ = source key data block
499 * @key_data *kt@ = target key data block
501 * Returns: Zero if successful, nonzero if there was a problem.
503 * Use: Locks a key by encrypting it with a passphrase.
506 extern int key_plock(const char */
*tag*/
, key_data */
*k*/
, key_data */
*kt*/
);
508 /* --- @key_punlock@ --- *
510 * Arguments: @const char *tag@ = tag to use for passphrase
511 * @key_data *k@ = source key data block
512 * @key_data *kt@ = target key data block
514 * Returns: Zero if it worked, nonzero if it didn't.
516 * Use: Unlocks a passphrase-locked key.
519 extern int key_punlock(const char */
*tag*/
,
520 key_data */
*k*/
, key_data */
*kt*/
);
522 /*----- Reading and writing keys and files --------------------------------*/
524 /* --- @key_merge@ --- *
526 * Arguments: @key_file *f@ = pointer to file structure
527 * @const char *file@ = name of file (for error messages)
528 * @FILE *fp@ = file handle to read from
529 * @key_reporter *rep@ = error reporting function
530 * @void *arg@ = argument for function
532 * Returns: Error code (one of the @KERR@ constants).
534 * Use: Reads keys from a file, and inserts them into the file.
537 extern int key_merge(key_file */
*f*/
, const char */
*file*/
, FILE */
*fp*/
,
538 key_reporter */
*rep*/
, void */
*arg*/
);
540 /* --- @key_extract@ --- *
542 * Arguments: @key_file *f@ = pointer to file structure
543 * @key *k@ = key to extract
544 * @FILE *fp@ = file to write on
545 * @const key_filter *kf@ = pointer to key selection block
547 * Returns: Zero if OK, EOF on error.
549 * Use: Extracts a key to an ouptut file.
552 extern int key_extract(key_file */
*f*/
, key */
*k*/
, FILE */
*fp*/
,
553 const key_filter */
*kf*/
);
555 /* --- @key_open@ --- *
557 * Arguments: @key_file *f@ = pointer to file structure to initialize
558 * @const char *file@ = pointer to the file name
559 * @int how@ = opening options (@KOPEN_*@).
560 * @key_reporter *rep@ = error reporting function
561 * @void *arg@ = argument for function
563 * Returns: Zero if it worked, nonzero otherwise.
565 * Use: Opens a key file, reads its contents, and stores them in a
566 * structure. The file is locked appropriately until closed
567 * using @key_close@. On an error, everything is cleared away
568 * tidily. If the file is opened with @KOPEN_WRITE@, it's
569 * created if necessary, with read and write permissions for its
573 extern int key_open(key_file */
*f*/
, const char */
*file*/
, int /*how*/,
574 key_reporter */
*rep*/
, void */
*arg*/
);
576 /* --- @key_close@ --- *
578 * Arguments: @key_file *f@ = pointer to key file block
580 * Returns: A @KWRITE_@ code indicating how it went.
582 * Use: Frees all the key data, writes any changes. Make sure that
583 * all hell breaks loose if this returns @KWRITE_BROKEN@.
586 extern int key_close(key_file */
*f*/
);
588 /* --- @key_save@ --- *
590 * Arguments: @key_file *f@ = pointer to key file block
592 * Returns: A @KWRITE_@ code indicating how well it worked.
594 * Use: Writes a key file's data back to the actual file. This code
595 * is extremely careful about error handling. It should usually
596 * be able to back out somewhere sensible, but it can tell when
597 * it's got itself into a real pickle and starts leaving well
600 * Callers, please make sure that you ring alarm bells when this
601 * function returns @KWRITE_BROKEN@.
604 extern int key_save(key_file */
*f*/
);
606 /* --- @key_lockfile@ --- *
608 * Arguments: @key_file *f@ = pointer to file structure to initialize
609 * @const char *file@ = pointer to the file name
610 * @int how@ = opening options (@KOPEN_*@).
612 * Returns: Zero if it worked, nonzero otherwise.
614 * Use: Opens a keyfile and stores the information needed for
615 * continued access in the structure.
617 * If the file is opened with @KOPEN_WRITE@, it's created if
618 * necessary with read and write permissions for owner only, and
619 * locked for update while it's open.
621 * This is a system-dependent routine, and only really intended
622 * for the private use of @key_open@.
625 extern int key_lockfile(key_file */
*f*/
, const char */
*file*/
, int /*how*/);
627 /*----- Creating and manipulating keys ------------------------------------*/
631 * Arguments: @key_file *f@ = pointer to key file
632 * @uint32 id@ = keyid to set
633 * @const char *type@ = the type of this key
634 * @time_t exp@ = when the key expires
635 * @int *err@ = where to store the error condition
637 * Returns: Key block containing new data, or null if it couldn't be
640 * Use: Attaches a new key to a key file. You must have a writable
641 * key file for this to work.
643 * The type is a key type string. This interface doesn't care
644 * about how type strings are formatted: it just treats them as
645 * opaque gobs of text. Clients are advised to choose some
646 * standard for representing key types, though.
648 * The expiry time should either be a time in the future, or the
649 * magic value @KEXP_FOREVER@ which means `never expire this
650 * key'. Be careful with `forever' keys. If I were you, I'd
651 * use a more sophisticated key management system than this for
654 * You have to set the actual key yourself.
657 extern key
*key_new(key_file */
*f*/
, uint32
/*id*/, const char */
*type*/
,
658 time_t /*exp*/, int */
*err*/
);
660 /* --- @key_delete@ --- *
662 * Arguments: @key_file *f@ = pointer to file block
663 * @key *k@ = key to delete
665 * Returns: Error code (one of the @KERR@ constants).
667 * Use: Removes the given key from the list. The key file must be
668 * writable. (Due to the horridness of the data structures,
669 * deleted keys aren't actually removed, just marked so that
670 * they can't be looked up or iterated over. One upshot of
671 * this is that they don't get written back to the file when
675 extern int key_delete(key_file */
*f*/
, key */
*k*/
);
677 /* --- @key_expire@ --- *
679 * Arguments: @key_file *f@ = pointer to file block
680 * @key *k@ = pointer to key block
682 * Returns: Error code (one of the @KERR@ constants).
684 * Use: Immediately marks the key as expired. It may be removed
685 * immediately, if it is no longer required, and will be removed
686 * by a tidy operation when it is no longer required. The key
687 * file must be writable.
690 extern int key_expire(key_file */
*f*/
, key */
*k*/
);
692 /* --- @key_used@ --- *
694 * Arguments: @key_file *f@ = pointer to key file
695 * @key *k@ = pointer to key block
696 * @time_t t@ = when key can be removed
698 * Returns: Zero if OK, nonzero on failure.
700 * Use: Marks a key as being required until a given time. Even
701 * though the key may expire before then (and won't be returned
702 * by type after that time), it will still be available when
703 * requested explicitly by id. The key file must be writable.
705 * The only (current) reason for failure is attempting to use
706 * a key which can expire for something which can't.
709 extern int key_used(key_file */
*f*/
, key */
*k*/
, time_t /*t*/);
711 /*----- Setting and reading attributes ------------------------------------*/
713 /* --- @key_chkident@ --- *
715 * Arguments: @const char *p@ = pointer to a type string
717 * Returns: Zero if OK, -1 on error.
719 * Use: Checks whether an identification component string is OK.
722 extern int key_chkident(const char */
*p*/
);
724 /* --- @key_chkcomment@ --- *
726 * Arguments: @const char *p@ = pointer to a comment string
728 * Returns: Zero if OK, -1 on error.
730 * Use: Checks whether a comment string is OK.
733 extern int key_chkcomment(const char */
*p*/
);
735 /* --- @key_setcomment@ --- *
737 * Arguments: @key_file *f@ = pointer to key file block
738 * @key *k@ = pointer to key block
739 * @const char *c@ = pointer to comment to set, or zero
741 * Returns: Error code (one of the @KERR@ constants).
743 * Use: Replaces the key's current comment with a new one.
746 extern int key_setcomment(key_file */
*f*/
, key */
*k*/
, const char */
*c*/
);
748 /* --- @key_settag@ --- *
750 * Arguments: @key_file *f@ = pointer to key file block
751 * @key *k@ = pointer to key block
752 * @const char *tag@ = pointer to comment to set, or zero
754 * Returns: Error code (one of the @KERR@ constants).
756 * Use: Replaces the key's current tag with a new one.
759 extern int key_settag(key_file */
*f*/
, key */
*k*/
, const char */
*tag*/
);
761 /* --- @key_fulltag@ --- *
763 * Arguments: @key *k@ = pointer to key
764 * @dstr *d@ = pointer to destination string
768 * Use: Emits the key's full tag, which has the form
769 * `ID:TYPE[:TAG]'. This is used in the textual file format,
770 * and to identify passphrases for locked keys.
773 extern void key_fulltag(key */
*k*/
, dstr */
*d*/
);
775 /* --- @key_qtag@ --- *
777 * Arguments: @key_file *f@ = key file to find a key from
778 * @const char *tag@ = pointer to tag string
779 * @dstr *d@ = pointer to string for full tag name
780 * @key **k@ = where to store the key pointer
781 * @key_data **kd@ = where to store the key data pointer
783 * Returns: Zero if OK, nonzero if it failed.
785 * Use: Performs a full lookup on a qualified tag name. The tag is
786 * qualified by the names of subkeys, separated by dots. Hence,
787 * a qualified tag is ID|TAG[.TAG...]. The various result
788 * pointers can be null to indicate that the result isn't
792 extern int key_qtag(key_file */
*f*/
, const char */
*tag*/
,
793 dstr */
*d*/
, key
**/
*k*/
, key_data
**/
*kd*/
);
795 /* --- @key_getattr@ --- *
797 * Arguments: @key_file *f@ = pointer to file
798 * @key *k@ = pointer to key
799 * @const char *n@ = pointer to attribute name
801 * Returns: Pointer to attribute value, or null if not found.
803 * Use: Returns the value of a key attribute.
806 extern const char *key_getattr(key_file */
*f*/
, key */
*k*/
,
809 /* --- @key_putattr@ --- *
811 * Arguments: @key_file *f@ = pointer to file
812 * @key *k@ = pointer to key
813 * @const char *n@ = pointer to attribute name
814 * @const char *v@ = pointer to attribute value or null
816 * Returns: Error code (one of the @KERR@ constants).
818 * Use: Inserts an attribute on a key. If an attribute with the same
819 * name already exists, it is deleted. Setting a null value
820 * removes the attribute.
823 extern int key_putattr(key_file */
*f*/
, key */
*k*/
,
824 const char */
*n*/
, const char */
*v*/
);
826 /* --- @key_mkattriter@ --- *
828 * Arguments: @key_attriter *i@ = pointer to attribute iterator
829 * @key *k@ = pointer to key
833 * Use: Initializes an attribute iterator. The attributes are
834 * returned by @key_nextattr@.
837 extern void key_mkattriter(key_attriter */
*i*/
, key */
*k*/
);
839 /* --- @key_nextattr@ --- *
841 * Arguments: @key_attriter *i@ = pointer to attribute iterator
842 * @const char **n, **v@ = pointers to name and value
844 * Returns: Zero if no attribute available, or nonzero if returned OK.
846 * Use: Returns the next attribute.
849 extern int key_nextattr(key_attriter */
*i*/
,
850 const char **/
*n*/
, const char **/
*v*/
);
852 /*----- Searching and iterating -------------------------------------------*/
854 /* --- @key_bytype@ --- *
856 * Arguments: @key_file *f@ = key file we want a key from
857 * @const char *type@ = type string for desired key
859 * Returns: Pointer to the best key to use, or null.
861 * Use: Looks up a key by its type. Returns the key with the latest
862 * expiry time. This function will not return an expired key.
865 extern key
*key_bytype(key_file */
*f*/
, const char */
*type*/
);
867 /* --- @key_byid@ --- *
869 * Arguments: @key_file *f@ = key file to find a key from
870 * @uint32 id@ = id to look for
872 * Returns: Key with matching id.
874 * Use: Returns a key given its id. This function will return an
875 * expired key, but not a deleted one.
878 extern key
*key_byid(key_file */
*f*/
, uint32
/*id*/);
880 /* --- @key_bytag@ --- *
882 * Arguments: @key_file *f@ = key file to find a key from
883 * @const char *tag@ = pointer to tag string
885 * Returns: Key with matching id or tag.
887 * Use: Returns a key given its tag or id. This function will return
888 * an expired key, but not a deleted one.
891 extern key
*key_bytag(key_file */
*f*/
, const char */
*tag*/
);
893 /* --- @key_mkiter@ --- *
895 * Arguments: @key_iter *i@ = pointer to iterator object
896 * @key_file *f@ = pointer to file structure
900 * Use: Initializes a key iterator. The keys are returned by
904 extern void key_mkiter(key_iter */
*i*/
, key_file */
*f*/
);
906 /* --- @key_next@ --- *
908 * Arguments: @key_iter *i@ = pointer to iterator object
910 * Returns: Pointer to next key, or null.
912 * Use: Returns the next key in some arbitrary sequence.
915 extern key
*key_next(key_iter */
*i*/
);
917 /*----- Other functions ---------------------------------------------------*/
919 /* --- @key_moan@ --- *
921 * Arguments: @const char *file@ = name of the file
922 * @int line@ = line number in file
923 * @const char *msg@ = error message
924 * @void *p@ = argument pointer
928 * Use: Reports an error message about loading a key file.
931 extern void key_moan(const char */
*file*/
, int /*line*/,
932 const char */
*msg*/
, void */
*p*/
);
934 /* --- @key_strerror@ --- *
936 * Arguments: @int err@ = error code from @key_new@
938 * Returns: Pointer to error string.
940 * Use: Translates a @KERR@ error code into a human-readable string.
943 extern const char *key_strerror(int /*err*/);
945 /*----- That's all, folks -------------------------------------------------*/