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>
18 const char *pgp_pkalgbytype (unsigned char type)
44 static const char *hashalgbytype (unsigned char type)
62 short pgp_canencrypt (unsigned char type)
75 short pgp_cansign (unsigned char type)
95 short pgp_get_abilities (unsigned char type)
97 return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
100 void pgp_free_sig (pgp_sig_t ** sigp)
107 for (sp = *sigp; sp; sp = q) {
115 void pgp_free_uid (pgp_uid_t ** upp)
121 for (up = *upp; up; up = q) {
123 pgp_free_sig (&up->sigs);
131 pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent)
136 for (; up; up = up->next) {
137 *lp = p_new(pgp_uid_t, 1);
138 (*lp)->trust = up->trust;
139 (*lp)->flags = up->flags;
140 (*lp)->addr = m_strdup(up->addr);
141 (*lp)->parent = parent;
148 static void _pgp_free_key (pgp_key_t * kpp)
157 pgp_free_uid (&kp->address);
158 p_delete(&kp->keyid);
162 pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
167 if (!klist || !*klist || !key)
170 if (key->parent && key->parent != key)
174 for (p = *klist; p && p != key; p = p->next)
180 for (q = p->next, r = p; q && q->parent == p; q = q->next)
190 void pgp_free_key (pgp_key_t * kpp)
197 if ((*kpp)->parent && (*kpp)->parent != *kpp)
198 *kpp = (*kpp)->parent;
200 /* Order is important here:
202 * - First free all children.
203 * - If we are an orphan (i.e., our parent was not in the key list),
208 for (p = *kpp; p; p = q) {
209 for (q = p->next; q && q->parent == p; q = r) {
214 _pgp_free_key (&p->parent);