2 * Copyright notice from original mutt:
3 * Copyright (C) 1997-2000 Thomas Roessler <roessler@does-not-exist.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
10 /* Generally useful, pgp-related functions. */
22 #include <lib-lib/mem.h>
30 const char *pgp_pkalgbytype (unsigned char type)
56 static const char *hashalgbytype (unsigned char type)
74 short pgp_canencrypt (unsigned char type)
87 short pgp_cansign (unsigned char type)
107 short pgp_get_abilities (unsigned char type)
109 return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
112 void pgp_free_sig (pgp_sig_t ** sigp)
119 for (sp = *sigp; sp; sp = q) {
127 void pgp_free_uid (pgp_uid_t ** upp)
133 for (up = *upp; up; up = q) {
135 pgp_free_sig (&up->sigs);
143 pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent)
148 for (; up; up = up->next) {
149 *lp = mem_calloc (1, sizeof (pgp_uid_t));
150 (*lp)->trust = up->trust;
151 (*lp)->flags = up->flags;
152 (*lp)->addr = str_dup (up->addr);
153 (*lp)->parent = parent;
160 static void _pgp_free_key (pgp_key_t * kpp)
169 pgp_free_uid (&kp->address);
170 p_delete(&kp->keyid);
174 pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
179 if (!klist || !*klist || !key)
182 if (key->parent && key->parent != key)
186 for (p = *klist; p && p != key; p = p->next)
192 for (q = p->next, r = p; q && q->parent == p; q = q->next)
202 void pgp_free_key (pgp_key_t * kpp)
209 if ((*kpp)->parent && (*kpp)->parent != *kpp)
210 *kpp = (*kpp)->parent;
212 /* Order is important here:
214 * - First free all children.
215 * - If we are an orphan (i.e., our parent was not in the key list),
220 for (p = *kpp; p; p = q) {
221 for (q = p->next; q && q->parent == p; q = r) {
226 _pgp_free_key (&p->parent);