NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
pgplib.h File Reference

Misc PGP helper routines. More...

#include <stdbool.h>
#include <time.h>
#include "lib.h"
+ Include dependency graph for pgplib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PgpUid
 PGP User ID. More...
 
struct  PgpKeyInfo
 Information about a PGP key. More...
 

Functions

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

Detailed Description

Misc PGP helper routines.

Authors
  • Michael R. Elkins
  • 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.h.

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_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:251
PGP User ID.
Definition: pgplib.h:35
short trust
Definition: pgplib.h:37
struct PgpKeyInfo * parent
Parent key.
Definition: pgplib.h:39
int flags
Definition: pgplib.h:38
char * addr
Definition: pgplib.h:36
struct PgpUid * next
Linked list.
Definition: pgplib.h:40
+ Here is the call graph for this function:
+ 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_key_free()

void pgp_key_free ( struct PgpKeyInfo **  kpp)

Free a PGP key info.

Parameters
[out]kppPGP key info to free

Definition at line 200 of file pgplib.c.

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

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

◆ pgp_keyinfo_new()

struct PgpKeyInfo * pgp_keyinfo_new ( void  )