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. */
34 const char *pgp_pkalgbytype (unsigned char type)
61 static const char *hashalgbytype (unsigned char type)
80 short pgp_canencrypt (unsigned char type)
94 short pgp_cansign (unsigned char type)
115 short pgp_get_abilities (unsigned char type)
117 return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
120 void pgp_free_sig (pgp_sig_t **sigp)
127 for (sp = *sigp; sp; sp = q)
136 void pgp_free_uid (pgp_uid_t ** upp)
142 for (up = *upp; up; up = q)
145 pgp_free_sig (&up->sigs);
153 pgp_uid_t *pgp_copy_uids (pgp_uid_t *up, pgp_key_t parent)
158 for (; up; up = up->next)
160 *lp = safe_calloc (1, sizeof (pgp_uid_t));
161 (*lp)->trust = up->trust;
162 (*lp)->flags = up->flags;
163 (*lp)->addr = safe_strdup (up->addr);
164 (*lp)->parent = parent;
171 static void _pgp_free_key (pgp_key_t *kpp)
180 pgp_free_uid (&kp->address);
185 pgp_key_t pgp_remove_key (pgp_key_t *klist, pgp_key_t key)
190 if (!klist || !*klist || !key)
193 if (key->parent && key->parent != key)
197 for (p = *klist; p && p != key; p = p->next)
203 for (q = p->next, r = p; q && q->parent == p; q = q->next)
213 void pgp_free_key (pgp_key_t *kpp)
220 if ((*kpp)->parent && (*kpp)->parent != *kpp)
221 *kpp = (*kpp)->parent;
223 /* Order is important here:
225 * - First free all children.
226 * - If we are an orphan (i.e., our parent was not in the key list),
231 for (p = *kpp; p; p = q)
233 for (q = p->next; q && q->parent == p; q = r)
239 _pgp_free_key (&p->parent);