X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/d11a0bf77a5230387d222ec727865a898767ff3e..5d01b1b9514a258c5a3c201e944f676cb2c467f0:/key-flags.c diff --git a/key-flags.c b/key-flags.c index f25bb21..bf5b70f 100644 --- a/key-flags.c +++ b/key-flags.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: key-flags.c,v 1.1 1999/12/22 15:47:48 mdw Exp $ + * $Id$ * * Reading and writing key flag strings * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,26 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: key-flags.c,v $ - * Revision 1.1 1999/12/22 15:47:48 mdw - * Major key-management revision. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -60,7 +52,7 @@ typedef struct flagent { unsigned m; } flagent; -static flagent flagtab[] = { +static const flagent flagtab[] = { /* --- Encoding types --- */ @@ -68,6 +60,8 @@ static flagent flagtab[] = { { "integer", KENC_MP, KF_ENCMASK }, { "struct", KENC_STRUCT, KF_ENCMASK }, { "encrypt", KENC_ENCRYPT, KF_ENCMASK }, + { "string", KENC_STRING, KF_ENCMASK }, + { "ec", KENC_EC, KF_ENCMASK }, /* --- Classes of keys --- */ @@ -108,10 +102,12 @@ int key_readflags(const char *p, char **pp, unsigned *ff, unsigned *mm) for (;;) { size_t sz = strcspn(p, ",:"); - flagent *e, *ee = 0; + const flagent *e, *ee = 0; /* --- Look up the string in the flags table --- */ + if (sz == 4 && strncmp(p, "none", 4) == 0) + goto next; for (e = flagtab; e->name; e++) { if (strncmp(e->name, p, sz) == 0) { if (e->name[sz] == 0) { @@ -135,6 +131,7 @@ int key_readflags(const char *p, char **pp, unsigned *ff, unsigned *mm) return (KERR_BADFLAGS); m |= ee->m; f |= ee->f; + next: p += sz; if (*p == 0 || *p == ':') break; @@ -162,7 +159,7 @@ int key_readflags(const char *p, char **pp, unsigned *ff, unsigned *mm) void key_writeflags(unsigned f, dstr *d) { int del = 0; - flagent *e; + const flagent *e; unsigned m = 0; for (e = flagtab; e->name; e++) { @@ -176,4 +173,32 @@ void key_writeflags(unsigned f, dstr *d) } } +/* --- @key_match@ --- * + * + * Arguments: @key_data *k@ = pointer to key data block + * @const key_filter *kf@ = pointer to filter block + * + * Returns: Nonzero if the key matches the filter. + * + * Use: Checks whether a key matches a filter. + */ + +int key_match(key_data *k, const key_filter *kf) +{ + key_subkeyiter i; + const char *tag; + key_data *kd; + + if (!kf) + return (1); + if ((k->e & KF_ENCMASK) != KENC_STRUCT) + return ((k->e & kf->m) == kf->f); + + for (key_mksubkeyiter(&i, k); key_nextsubkey(&i, &tag, &kd); ) { + if (key_match(kd, kf)) + return (1); + } + return (0); +} + /*----- That's all, folks -------------------------------------------------*/