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)
37 short pgp_canencrypt (unsigned char type)
50 short pgp_cansign (unsigned char type)
70 short pgp_get_abilities (unsigned char type)
72 return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
75 static void pgp_free_sig (pgp_sig_t ** sigp)
82 for (sp = *sigp; sp; sp = q) {
90 static void pgp_free_uid (pgp_uid_t ** upp)
96 for (up = *upp; up; up = q) {
98 pgp_free_sig (&up->sigs);
106 pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent)
111 for (; up; up = up->next) {
112 *lp = p_new(pgp_uid_t, 1);
113 (*lp)->trust = up->trust;
114 (*lp)->flags = up->flags;
115 (*lp)->addr = m_strdup(up->addr);
116 (*lp)->parent = parent;
123 static void _pgp_free_key (pgp_key_t * kpp)
132 pgp_free_uid (&kp->address);
133 p_delete(&kp->keyid);
137 pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
142 if (!klist || !*klist || !key)
145 if (key->parent && key->parent != key)
149 for (p = *klist; p && p != key; p = p->next)
155 for (q = p->next, r = p; q && q->parent == p; q = q->next)
165 void pgp_free_key (pgp_key_t * kpp)
172 if ((*kpp)->parent && (*kpp)->parent != *kpp)
173 *kpp = (*kpp)->parent;
175 /* Order is important here:
177 * - First free all children.
178 * - If we are an orphan (i.e., our parent was not in the key list),
183 for (p = *kpp; p; p = q) {
184 for (q = p->next; q && q->parent == p; q = r) {
189 _pgp_free_key (&p->parent);