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. */
26 const char *pgp_pkalgbytype (unsigned char type)
52 static const char *hashalgbytype (unsigned char type)
70 short pgp_canencrypt (unsigned char type)
83 short pgp_cansign (unsigned char type)
103 short pgp_get_abilities (unsigned char type)
105 return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
108 void pgp_free_sig (pgp_sig_t ** sigp)
115 for (sp = *sigp; sp; sp = q) {
123 void pgp_free_uid (pgp_uid_t ** upp)
129 for (up = *upp; up; up = q) {
131 pgp_free_sig (&up->sigs);
139 pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent)
144 for (; up; up = up->next) {
145 *lp = safe_calloc (1, sizeof (pgp_uid_t));
146 (*lp)->trust = up->trust;
147 (*lp)->flags = up->flags;
148 (*lp)->addr = safe_strdup (up->addr);
149 (*lp)->parent = parent;
156 static void _pgp_free_key (pgp_key_t * kpp)
165 pgp_free_uid (&kp->address);
170 pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
175 if (!klist || !*klist || !key)
178 if (key->parent && key->parent != key)
182 for (p = *klist; p && p != key; p = p->next)
188 for (q = p->next, r = p; q && q->parent == p; q = q->next)
198 void pgp_free_key (pgp_key_t * kpp)
205 if ((*kpp)->parent && (*kpp)->parent != *kpp)
206 *kpp = (*kpp)->parent;
208 /* Order is important here:
210 * - First free all children.
211 * - If we are an orphan (i.e., our parent was not in the key list),
216 for (p = *kpp; p; p = q) {
217 for (q = p->next; q && q->parent == p; q = r) {
222 _pgp_free_key (&p->parent);