]>
git.sthu.org Git - pgp-tools.git/blob - keyanalyze/pgpring/pgplib.c
2 * Copyright (C) 1997-2000 Thomas Roessler <roessler@guug.de>
4 * This program is free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later
10 * This program is distributed in the hope that it will be
11 * useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111, USA.
22 /* Generally useful, pgp-related functions. */
33 const char *pgp_pkalgbytype (unsigned char type
)
60 static const char *hashalgbytype (unsigned char type
)
79 short pgp_canencrypt (unsigned char type
)
93 short pgp_cansign (unsigned char type
)
114 short pgp_get_abilities (unsigned char type
)
116 return (pgp_canencrypt (type
) << 1) | pgp_cansign (type
);
119 void pgp_free_sig (pgp_sig_t
**sigp
)
126 for (sp
= *sigp
; sp
; sp
= q
)
135 void pgp_free_uid (pgp_uid_t
** upp
)
141 for (up
= *upp
; up
; up
= q
)
144 pgp_free_sig (&up
->sigs
);
145 safe_free (&up
->addr
);
152 pgp_uid_t
*pgp_copy_uids (pgp_uid_t
*up
, pgp_key_t
*parent
)
157 for (; up
; up
= up
->next
)
159 *lp
= safe_calloc (1, sizeof (pgp_uid_t
));
160 (*lp
)->trust
= up
->trust
;
161 (*lp
)->flags
= up
->flags
;
162 (*lp
)->addr
= safe_strdup (up
->addr
);
163 (*lp
)->parent
= parent
;
170 static void _pgp_free_key (pgp_key_t
** kpp
)
179 pgp_free_uid (&kp
->address
);
180 safe_free (&kp
->keyid
);
184 pgp_key_t
*pgp_remove_key (pgp_key_t
** klist
, pgp_key_t
* key
)
187 pgp_key_t
*p
, *q
, *r
;
189 if (!klist
|| !*klist
|| !key
)
192 if (key
->parent
&& key
->parent
!= key
)
196 for (p
= *klist
; p
&& p
!= key
; p
= p
->next
)
202 for (q
= p
->next
, r
= p
; q
&& q
->parent
== p
; q
= q
->next
)
212 void pgp_free_key (pgp_key_t
** kpp
)
214 pgp_key_t
*p
, *q
, *r
;
219 if ((*kpp
)->parent
&& (*kpp
)->parent
!= *kpp
)
220 *kpp
= (*kpp
)->parent
;
222 /* Order is important here:
224 * - First free all children.
225 * - If we are an orphan (i.e., our parent was not in the key list),
230 for (p
= *kpp
; p
; p
= q
)
232 for (q
= p
->next
; q
&& q
->parent
== p
; q
= r
)
238 _pgp_free_key (&p
->parent
);