2 * Copyright (C) 1997-2002 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., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, 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);
186 /* mutt_crypt.h: 'typedef struct pgp_keyinfo *pgp_key_t;' */
187 FREE (kpp); /* __FREE_CHECKED__ */
190 pgp_key_t pgp_remove_key (pgp_key_t *klist, pgp_key_t key)
195 if (!klist || !*klist || !key)
198 if (key->parent && key->parent != key)
202 for (p = *klist; p && p != key; p = p->next)
208 for (q = p->next, r = p; q && q->parent == p; q = q->next)
218 void pgp_free_key (pgp_key_t *kpp)
225 if ((*kpp)->parent && (*kpp)->parent != *kpp)
226 *kpp = (*kpp)->parent;
228 /* Order is important here:
230 * - First free all children.
231 * - If we are an orphan (i.e., our parent was not in the key list),
236 for (p = *kpp; p; p = q)
238 for (q = p->next; q && q->parent == p; q = r)
244 _pgp_free_key (&p->parent);