NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
pgplib.c File Reference

Misc PGP helper routines. More...

#include "config.h"
#include <stdbool.h>
#include "mutt/lib.h"
#include "pgplib.h"
+ Include dependency graph for pgplib.c:

Go to the source code of this file.

Functions

const char * pgp_pkalgbytype (unsigned char type)
 Get the name of the algorithm from its ID. More...
 
bool pgp_canencrypt (unsigned char type)
 Does this algorithm ID support encryption? More...
 
bool pgp_cansign (unsigned char type)
 Does this algorithm ID support signing? More...
 
static void pgp_uid_free (struct PgpUid **upp)
 Free a PGP UID. More...
 
struct PgpUidpgp_copy_uids (struct PgpUid *up, struct PgpKeyInfo *parent)
 Copy a list of PGP UIDs. More...
 
static void key_free (struct PgpKeyInfo **kpp)
 Free a PGP Key info. More...
 
struct PgpKeyInfopgp_remove_key (struct PgpKeyInfo **klist, struct PgpKeyInfo *key)
 Remove a PGP key from a list. More...
 
void pgp_key_free (struct PgpKeyInfo **kpp)
 Free a PGP key info. More...
 

Detailed Description

Misc PGP helper routines.

Authors
  • Thomas Roessler

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file pgplib.c.

Function Documentation

◆ pgp_pkalgbytype()

const char * pgp_pkalgbytype ( unsigned char  type)

Get the name of the algorithm from its ID.

Parameters
typeAlgorithm ID
Return values
ptrAlgorithm name

Definition at line 41 of file pgplib.c.

42{
43 switch (type)
44 {
45 case 1:
46 return "RSA";
47 case 2:
48 return "RSA";
49 case 3:
50 return "RSA";
51 case 16:
52 return "ElG";
53 case 17:
54 return "DSA";
55 case 20:
56 return "ElG";
57 default:
58 return "unk";
59 }
60}
+ Here is the caller graph for this function:

◆ pgp_canencrypt()

bool pgp_canencrypt ( unsigned char  type)

Does this algorithm ID support encryption?

Parameters
typeAlgorithm ID
Return values
trueAlgorithm does support encryption

Definition at line 67 of file pgplib.c.

68{
69 switch (type)
70 {
71 case 1:
72 case 2:
73 case 16:
74 case 20:
75 return true;
76 default:
77 return false;
78 }
79}

◆ pgp_cansign()

bool pgp_cansign ( unsigned char  type)

Does this algorithm ID support signing?

Parameters
typeAlgorithm ID
Return values
trueAlgorithm does support signing

Definition at line 86 of file pgplib.c.

87{
88 switch (type)
89 {
90 case 1:
91 case 3:
92 case 17:
93 case 20:
94 return true;
95 default:
96 return false;
97 }
98}

◆ pgp_uid_free()

static void pgp_uid_free ( struct PgpUid **  upp)
static

Free a PGP UID.

Parameters
[out]uppPGP UID to free

Definition at line 104 of file pgplib.c.

105{
106 struct PgpUid *up = NULL, *q = NULL;
107
108 if (!upp || !*upp)
109 return;
110 for (up = *upp; up; up = q)
111 {
112 q = up->next;
113 FREE(&up->addr);
114 FREE(&up);
115 }
116
117 *upp = NULL;
118}
#define FREE(x)
Definition: memory.h:43
PGP User ID.
Definition: pgplib.h:35
char * addr
Definition: pgplib.h:36
struct PgpUid * next
Linked list.
Definition: pgplib.h:40
+ Here is the caller graph for this function:

◆ pgp_copy_uids()

struct PgpUid * pgp_copy_uids ( struct PgpUid up,
struct PgpKeyInfo parent 
)

Copy a list of PGP UIDs.

Parameters
upList of PGP UIDs
parentParent PGP key
Return values
ptrNew list of PGP UIDs

Definition at line 126 of file pgplib.c.

127{
128 struct PgpUid *l = NULL;
129 struct PgpUid **lp = &l;
130
131 for (; up; up = up->next)
132 {
133 *lp = mutt_mem_calloc(1, sizeof(struct PgpUid));
134 (*lp)->trust = up->trust;
135 (*lp)->flags = up->flags;
136 (*lp)->addr = mutt_str_dup(up->addr);
137 (*lp)->parent = parent;
138 lp = &(*lp)->next;
139 }
140
141 return l;
142}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
short trust
Definition: pgplib.h:37
struct PgpKeyInfo * parent
Parent key.
Definition: pgplib.h:39
int flags
Definition: pgplib.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ key_free()

static void key_free ( struct PgpKeyInfo **  kpp)
static

Free a PGP Key info.

Parameters
[out]kppPGP Key info to free

Definition at line 148 of file pgplib.c.

149{
150 if (!kpp || !*kpp)
151 return;
152
153 struct PgpKeyInfo *kp = *kpp;
154
155 pgp_uid_free(&kp->address);
156 FREE(&kp->keyid);
157 FREE(&kp->fingerprint);
158 FREE(kpp);
159}
static void pgp_uid_free(struct PgpUid **upp)
Free a PGP UID.
Definition: pgplib.c:104
Information about a PGP key.
Definition: pgplib.h:47
char * keyid
Definition: pgplib.h:48
struct PgpUid * address
Definition: pgplib.h:50
char * fingerprint
Definition: pgplib.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_remove_key()

struct PgpKeyInfo * pgp_remove_key ( struct PgpKeyInfo **  klist,
struct PgpKeyInfo key 
)

Remove a PGP key from a list.

Parameters
[out]klistList of PGP Keys
[in]keyKey to remove
Return values
ptrUpdated list of PGP Keys

Definition at line 167 of file pgplib.c.

168{
169 if (!klist || !*klist || !key)
170 return NULL;
171
172 struct PgpKeyInfo **last = NULL;
173 struct PgpKeyInfo *p = NULL, *q = NULL, *r = NULL;
174
175 if (key->parent && (key->parent != key))
176 key = key->parent;
177
178 last = klist;
179 for (p = *klist; p && p != key; p = p->next)
180 last = &p->next;
181
182 if (!p)
183 return NULL;
184
185 for (q = p->next, r = p; q && q->parent == p; q = q->next)
186 r = q;
187
188 if (r)
189 r->next = NULL;
190
191 *last = q;
192 return q;
193}
struct PgpKeyInfo * next
Definition: pgplib.h:57
struct PgpKeyInfo * parent
Definition: pgplib.h:56
+ Here is the caller graph for this function:

◆ pgp_key_free()

void pgp_key_free ( struct PgpKeyInfo **  kpp)

Free a PGP key info.

Parameters
[out]kppPGP key info to free

Definition at line 199 of file pgplib.c.

200{
201 if (!kpp || !*kpp)
202 return;
203
204 struct PgpKeyInfo *p = NULL, *q = NULL, *r = NULL;
205
206 if ((*kpp)->parent && ((*kpp)->parent != *kpp))
207 *kpp = (*kpp)->parent;
208
209 /* Order is important here:
210 *
211 * - First free all children.
212 * - If we are an orphan (i.e., our parent was not in the key list),
213 * free our parent.
214 * - free ourselves. */
215
216 for (p = *kpp; p; p = q)
217 {
218 for (q = p->next; q && q->parent == p; q = r)
219 {
220 r = q->next;
221 key_free(&q);
222 }
223
224 key_free(&p->parent);
225 key_free(&p);
226 }
227
228 *kpp = NULL;
229}
static void key_free(struct PgpKeyInfo **kpp)
Free a PGP Key info.
Definition: pgplib.c:148
+ Here is the call graph for this function:
+ Here is the caller graph for this function: