NeoMutt  2025-12-11-977-g8a21d8
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 "mutt/lib.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...
 

Enumerations

enum  ExpandoDataPgpKey {
  ED_PGK_DATE = 1 , ED_PGK_KEY_ALGORITHM , ED_PGK_KEY_CAPABILITIES , ED_PGK_KEY_FINGERPRINT ,
  ED_PGK_KEY_FLAGS , ED_PGK_KEY_ID , ED_PGK_KEY_LENGTH , ED_PGK_PKEY_ALGORITHM ,
  ED_PGK_PKEY_CAPABILITIES , ED_PGK_PKEY_FINGERPRINT , ED_PGK_PKEY_FLAGS , ED_PGK_PKEY_ID ,
  ED_PGK_PKEY_LENGTH , ED_PGK_PROTOCOL
}
 Expando UIDs for PGP Keys. More...
 

Functions

 ARRAY_HEAD (PgpUidArray, struct PgpUid *)
 
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
  • Pietro Cerutti
  • Richard Russon

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.

Enumeration Type Documentation

◆ ExpandoDataPgpKey

Expando UIDs for PGP Keys.

See also
ED_PGP_KEY, ExpandoDomain
Enumerator
ED_PGK_DATE 

PgpKeyInfo.gen_time.

ED_PGK_KEY_ALGORITHM 

PgpKeyInfo.algorithm.

ED_PGK_KEY_CAPABILITIES 

PgpKeyInfo.flags, pgp_key_abilities()

ED_PGK_KEY_FINGERPRINT 

PgpKeyInfo.fingerprint.

ED_PGK_KEY_FLAGS 

PgpKeyInfo.kflags, pgp_flags()

ED_PGK_KEY_ID 

PgpKeyInfo, pgp_this_keyid()

ED_PGK_KEY_LENGTH 

PgpKeyInfo.keylen.

ED_PGK_PKEY_ALGORITHM 

pgp_principal_key(), PgpKeyInfo.algorithm

ED_PGK_PKEY_CAPABILITIES 

pgp_principal_key(), PgpKeyInfo.flags, pgp_key_abilities()

ED_PGK_PKEY_FINGERPRINT 

pgp_principal_key(), PgpKeyInfo.fingerprint

ED_PGK_PKEY_FLAGS 

pgp_principal_key(), PgpKeyInfo.kflags, pgp_flags()

ED_PGK_PKEY_ID 

pgp_principal_key(), PgpKeyInfo, pgp_this_keyid()

ED_PGK_PKEY_LENGTH 

pgp_principal_key(), PgpKeyInfo.keylen

ED_PGK_PROTOCOL 

PgpKeyInfo.

Definition at line 67 of file pgplib.h.

68{
69 ED_PGK_DATE = 1,
83};
@ ED_PGK_KEY_CAPABILITIES
PgpKeyInfo.flags, pgp_key_abilities()
Definition pgplib.h:71
@ ED_PGK_KEY_FINGERPRINT
PgpKeyInfo.fingerprint.
Definition pgplib.h:72
@ ED_PGK_PKEY_LENGTH
pgp_principal_key(), PgpKeyInfo.keylen
Definition pgplib.h:81
@ ED_PGK_PKEY_ALGORITHM
pgp_principal_key(), PgpKeyInfo.algorithm
Definition pgplib.h:76
@ ED_PGK_DATE
PgpKeyInfo.gen_time.
Definition pgplib.h:69
@ ED_PGK_PKEY_FINGERPRINT
pgp_principal_key(), PgpKeyInfo.fingerprint
Definition pgplib.h:78
@ ED_PGK_KEY_ID
PgpKeyInfo, pgp_this_keyid()
Definition pgplib.h:74
@ ED_PGK_PROTOCOL
PgpKeyInfo.
Definition pgplib.h:82
@ ED_PGK_PKEY_CAPABILITIES
pgp_principal_key(), PgpKeyInfo.flags, pgp_key_abilities()
Definition pgplib.h:77
@ ED_PGK_KEY_FLAGS
PgpKeyInfo.kflags, pgp_flags()
Definition pgplib.h:73
@ ED_PGK_PKEY_ID
pgp_principal_key(), PgpKeyInfo, pgp_this_keyid()
Definition pgplib.h:80
@ ED_PGK_KEY_ALGORITHM
PgpKeyInfo.algorithm.
Definition pgplib.h:70
@ ED_PGK_KEY_LENGTH
PgpKeyInfo.keylen.
Definition pgplib.h:75
@ ED_PGK_PKEY_FLAGS
pgp_principal_key(), PgpKeyInfo.kflags, pgp_flags()
Definition pgplib.h:79

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( PgpUidArray ,
struct PgpUid *  )

◆ 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 42 of file pgplib.c.

43{
44 switch (type)
45 {
46 case 1:
47 return "RSA";
48 case 2:
49 return "RSA";
50 case 3:
51 return "RSA";
52 case 16:
53 return "ElG";
54 case 17:
55 return "DSA";
56 case 20:
57 return "ElG";
58 default:
59 return "unk";
60 }
61}
+ 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 128 of file pgplib.c.

129{
130 struct PgpUid *l = NULL;
131 struct PgpUid **lp = &l;
132
133 for (; up; up = up->next)
134 {
135 *lp = MUTT_MEM_CALLOC(1, struct PgpUid);
136 (*lp)->trust = up->trust;
137 (*lp)->flags = up->flags;
138 (*lp)->addr = mutt_str_dup(up->addr);
139 (*lp)->parent = parent;
140 lp = &(*lp)->next;
141 }
142
143 return l;
144}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
PGP User ID.
Definition pgplib.h:36
short trust
Trust level.
Definition pgplib.h:38
struct PgpKeyInfo * parent
Parent key.
Definition pgplib.h:40
int flags
Flags for this UID.
Definition pgplib.h:39
char * addr
Email address.
Definition pgplib.h:37
struct PgpUid * next
Linked list.
Definition pgplib.h:41
+ 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 68 of file pgplib.c.

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

◆ 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 87 of file pgplib.c.

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

◆ 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 204 of file pgplib.c.

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

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

◆ pgp_keyinfo_new()

struct PgpKeyInfo * pgp_keyinfo_new ( void )