2 * Copyright (C) 1997-2000 Thomas Roessler <roessler@does-not-exist.org>
4 * This program is free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later
10 * This program is distributed in the hope that it will be
11 * useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111, USA.
22 /* Generally useful, pgp-related functions. */
38 const char *pgp_pkalgbytype (unsigned char type)
65 static const char *hashalgbytype (unsigned char type)
84 short pgp_canencrypt (unsigned char type)
98 short pgp_cansign (unsigned char type)
119 short pgp_get_abilities (unsigned char type)
121 return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
124 void pgp_free_sig (pgp_sig_t **sigp)
131 for (sp = *sigp; sp; sp = q)
140 void pgp_free_uid (pgp_uid_t ** upp)
146 for (up = *upp; up; up = q)
149 pgp_free_sig (&up->sigs);
157 pgp_uid_t *pgp_copy_uids (pgp_uid_t *up, pgp_key_t parent)
162 for (; up; up = up->next)
164 *lp = safe_calloc (1, sizeof (pgp_uid_t));
165 (*lp)->trust = up->trust;
166 (*lp)->flags = up->flags;
167 (*lp)->addr = safe_strdup (up->addr);
168 (*lp)->parent = parent;
175 static void _pgp_free_key (pgp_key_t *kpp)
184 pgp_free_uid (&kp->address);
189 pgp_key_t pgp_remove_key (pgp_key_t *klist, pgp_key_t key)
194 if (!klist || !*klist || !key)
197 if (key->parent && key->parent != key)
201 for (p = *klist; p && p != key; p = p->next)
207 for (q = p->next, r = p; q && q->parent == p; q = q->next)
217 void pgp_free_key (pgp_key_t *kpp)
224 if ((*kpp)->parent && (*kpp)->parent != *kpp)
225 *kpp = (*kpp)->parent;
227 /* Order is important here:
229 * - First free all children.
230 * - If we are an orphan (i.e., our parent was not in the key list),
235 for (p = *kpp; p; p = q)
237 for (q = p->next; q && q->parent == p; q = r)
243 _pgp_free_key (&p->parent);