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)
64 static const char *hashalgbytype (unsigned char type)
82 short pgp_canencrypt (unsigned char type)
95 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) {
135 void pgp_free_uid (pgp_uid_t ** upp)
141 for (up = *upp; up; up = q) {
143 pgp_free_sig (&up->sigs);
151 pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent)
156 for (; up; up = up->next) {
157 *lp = safe_calloc (1, sizeof (pgp_uid_t));
158 (*lp)->trust = up->trust;
159 (*lp)->flags = up->flags;
160 (*lp)->addr = safe_strdup (up->addr);
161 (*lp)->parent = parent;
168 static void _pgp_free_key (pgp_key_t * kpp)
177 pgp_free_uid (&kp->address);
182 pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
187 if (!klist || !*klist || !key)
190 if (key->parent && key->parent != key)
194 for (p = *klist; p && p != key; p = p->next)
200 for (q = p->next, r = p; q && q->parent == p; q = q->next)
210 void pgp_free_key (pgp_key_t * kpp)
217 if ((*kpp)->parent && (*kpp)->parent != *kpp)
218 *kpp = (*kpp)->parent;
220 /* Order is important here:
222 * - First free all children.
223 * - If we are an orphan (i.e., our parent was not in the key list),
228 for (p = *kpp; p; p = q) {
229 for (q = p->next; q && q->parent == p; q = r) {
234 _pgp_free_key (&p->parent);