/* -*-c-*-
*
- * $Id: key-misc.c,v 1.4 2004/04/08 01:02:49 mdw Exp $
+ * $Id$
*
* Simple key management
*
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: key-misc.c,v $
- * Revision 1.4 2004/04/08 01:02:49 mdw
- * key-binary.c
- *
- * Revision 1.3 2001/06/22 19:39:12 mdw
- * New interface to find out whether a key has expired. Also, a bug fix
- * to @key_bytag@ so that it finds expired keys correctly.
- *
- * Revision 1.2 2000/02/12 18:21:02 mdw
- * Overhaul of key management (again).
- *
- * Revision 1.1 1999/12/22 15:47:48 mdw
- * Major key-management revision.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
* @const char *tag@ = pointer to tag string
* @dstr *d@ = pointer to string for full tag name
* @key **k@ = where to store the key pointer
- * @key_data **kd@ = where to store the key data pointer
+ * @key_data ***kd@ = where to store the key data pointer
*
* Returns: Zero if OK, nonzero if it failed.
*
* qualified by the names of subkeys, separated by dots. Hence,
* a qualified tag is ID|TAG[.TAG...]. The various result
* pointers can be null to indicate that the result isn't
- * interesting.
+ * interesting.
*/
-int key_qtag(key_file *f, const char *tag, dstr *d, key **k, key_data **kd)
+int key_qtag(key_file *f, const char *tag, dstr *d, key **k, key_data ***kd)
{
dstr dd = DSTR_INIT;
const char *q;
key *kk;
- key_data *kkd;
+ key_data **kkd;
/* --- Find the end of the base tag --- */
/* --- Now dig through the rest of the tag --- */
- while (q && *q) {
-
- /* --- Stick on the next bit of the fullqtag --- */
-
- DRESET(&dd);
- while (*q && *q != '.') {
- DPUTC(&dd, *q);
- q++;
- }
- DPUTZ(&dd);
- if (d) {
- DPUTC(d, '.');
- DPUTD(d, &dd);
- }
-
- /* --- Look up the subkey --- */
-
- if (kkd->e != KENC_STRUCT) {
- kkd = 0;
- break;
+ if (q) {
+ while (*q) {
+ key_struct *ks;
+
+ /* --- Stick on the next bit of the fullqtag --- */
+
+ DRESET(&dd);
+ while (*q && *q != '.') {
+ DPUTC(&dd, *q);
+ q++;
+ }
+ DPUTZ(&dd);
+ if (d) {
+ DPUTC(d, '.');
+ DPUTD(d, &dd);
+ }
+
+ /* --- Look up the subkey --- */
+
+ if ((*kkd)->e != KENC_STRUCT) {
+ kkd = 0;
+ break;
+ }
+ if ((ks = sym_find(&(*kkd)->u.s, dd.buf, -1, 0, 0)) == 0) {
+ kkd = 0;
+ break;
+ }
+ kkd = &ks->k;
}
- if ((kkd = key_structfind(kkd, dd.buf)) == 0)
- break;
}
/* --- Return the results --- */
+ dstr_destroy(&dd);
if (!kkd)
return (-1);
- dstr_destroy(&dd);
if (kd)
*kd = kkd;
return (0);
dstr d = DSTR_INIT;
int rc = 0;
key_attr *a, **v;
- size_t n, i, len;
- octet b[2];
+ size_t n, i;
sym_iter ai;
- if (!key_encode(&k->k, &d, kf))
+ if (!key_encode(k->k, &d, kf))
goto done;
rc = 1;
+ GH_HASHSTR(h, "catacomb-key-fingerprint:");
+ GH_HASHU32(h, k->id);
+ GH_HASHSTR8(h, k->type);
GH_HASH(h, d.buf, d.len);
for (n = 0, sym_mkiter(&ai, &k->a); (a = sym_next(&ai)) != 0; n++);
if (n) {
for (i = 0, sym_mkiter(&ai, &k->a); (a = sym_next(&ai)) != 0; i++)
v[i] = a;
qsort(v, n, sizeof(*v), abyname);
- len = strlen(k->type); STORE8(b, len);
- GH_HASH(h, b, 1); GH_HASH(h, k->type, len);
for (i = 0; i < n; i++) {
- a = v[i];
- len = strlen(SYM_NAME(a)); STORE8(b, len);
- GH_HASH(h, b, 1); GH_HASH(h, SYM_NAME(a), len);
- len = strlen(a->p); STORE16(b, len);
- GH_HASH(h, b, 2); GH_HASH(h, a->p, len);
+ GH_HASHSTR8(h, SYM_NAME(v[i]));
+ GH_HASHSTR16(h, v[i]->p);
}
xfree(v);
}