NeoMutt  2020-09-25
Teaching an old dog new tricks
DOXYGEN
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. More...
 
struct PgpUidpgp_copy_uids (struct PgpUid *up, struct PgpKeyInfo *parent)
 Copy a list of PGP UIDs. 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...
 
void pgp_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...
 
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
struct PgpUid * next
Definition: pgplib.h:40
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
PGP User ID.
Definition: pgplib.h:34
char * addr
Definition: pgplib.h:36
short trust
Definition: pgplib.h:37
struct PgpKeyInfo * parent
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:

◆ pgp_canencrypt()

bool pgp_canencrypt ( unsigned char  type)

Does this algorithm ID support encryption?

Parameters
typeAlgorithm ID
Return values
trueIf it does

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
trueIf it does

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 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 }
struct PgpKeyInfo * next
Definition: pgplib.h:57
Information about a PGP key.
Definition: pgplib.h:46
struct PgpKeyInfo * parent
Definition: pgplib.h:56
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:

◆ 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
Information about a PGP key.
Definition: pgplib.h:46
struct PgpKeyInfo * parent
Definition: pgplib.h:56
+ Here is the caller graph for this function:

◆ pgp_keyinfo_new()

struct PgpKeyInfo* pgp_keyinfo_new ( void  )