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. */
28 const char *pgp_pkalgbytype (unsigned char type)
54 static const char *hashalgbytype (unsigned char type)
72 short pgp_canencrypt (unsigned char type)
85 short pgp_cansign (unsigned char type)
105 short pgp_get_abilities (unsigned char type)
107 return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
110 void pgp_free_sig (pgp_sig_t ** sigp)
117 for (sp = *sigp; sp; sp = q) {
125 void pgp_free_uid (pgp_uid_t ** upp)
131 for (up = *upp; up; up = q) {
133 pgp_free_sig (&up->sigs);
134 mem_free (&up->addr);
141 pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent)
146 for (; up; up = up->next) {
147 *lp = mem_calloc (1, sizeof (pgp_uid_t));
148 (*lp)->trust = up->trust;
149 (*lp)->flags = up->flags;
150 (*lp)->addr = str_dup (up->addr);
151 (*lp)->parent = parent;
158 static void _pgp_free_key (pgp_key_t * kpp)
167 pgp_free_uid (&kp->address);
168 mem_free (&kp->keyid);
172 pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
177 if (!klist || !*klist || !key)
180 if (key->parent && key->parent != key)
184 for (p = *klist; p && p != key; p = p->next)
190 for (q = p->next, r = p; q && q->parent == p; q = q->next)
200 void pgp_free_key (pgp_key_t * kpp)
207 if ((*kpp)->parent && (*kpp)->parent != *kpp)
208 *kpp = (*kpp)->parent;
210 /* Order is important here:
212 * - First free all children.
213 * - If we are an orphan (i.e., our parent was not in the key list),
218 for (p = *kpp; p; p = q) {
219 for (q = p->next; q && q->parent == p; q = r) {
224 _pgp_free_key (&p->parent);