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. */
12 #include <lib-lib/lib-lib.h>
17 const char *pgp_pkalgbytype (unsigned char type)
43 static const char *hashalgbytype (unsigned char type)
61 short pgp_canencrypt (unsigned char type)
74 short pgp_cansign (unsigned char type)
94 short pgp_get_abilities (unsigned char type)
96 return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
99 static void pgp_free_sig (pgp_sig_t ** sigp)
106 for (sp = *sigp; sp; sp = q) {
114 static void pgp_free_uid (pgp_uid_t ** upp)
120 for (up = *upp; up; up = q) {
122 pgp_free_sig (&up->sigs);
130 pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent)
135 for (; up; up = up->next) {
136 *lp = p_new(pgp_uid_t, 1);
137 (*lp)->trust = up->trust;
138 (*lp)->flags = up->flags;
139 (*lp)->addr = m_strdup(up->addr);
140 (*lp)->parent = parent;
147 static void _pgp_free_key (pgp_key_t * kpp)
156 pgp_free_uid (&kp->address);
157 p_delete(&kp->keyid);
161 pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
166 if (!klist || !*klist || !key)
169 if (key->parent && key->parent != key)
173 for (p = *klist; p && p != key; p = p->next)
179 for (q = p->next, r = p; q && q->parent == p; q = q->next)
189 void pgp_free_key (pgp_key_t * kpp)
196 if ((*kpp)->parent && (*kpp)->parent != *kpp)
197 *kpp = (*kpp)->parent;
199 /* Order is important here:
201 * - First free all children.
202 * - If we are an orphan (i.e., our parent was not in the key list),
207 for (p = *kpp; p; p = q) {
208 for (q = p->next; q && q->parent == p; q = r) {
213 _pgp_free_key (&p->parent);