Parse the 'pub' line from the pgp output.
136{
137 struct PgpUid *uid = NULL;
138 int field = 0;
139 bool is_uid = false;
140 bool is_pub = false;
141 bool is_fpr = false;
142 char *pend = NULL, *p = NULL;
145 char tstr[11] = { 0 };
146
147 *is_subkey = false;
148 if (*buf == '\0')
149 return NULL;
150
151
152
153
155 if (k)
156 memcpy(&tmp, k, sizeof(tmp));
157
159
161 for (p = buf; p; p = pend)
162 {
163 pend = strchr(p, ':');
164 if (pend)
165 *pend++ = 0;
166 field++;
167 if ((*p == '\0') && (field != 1) && (field != 10))
168 continue;
169
170 if (is_fpr && (field != 10))
171 continue;
172
173 switch (field)
174 {
175 case 1:
176 {
178
180 is_pub = true;
182 *is_subkey = true;
184 ;
186 *is_subkey = true;
188 is_uid = true;
190 is_fpr = true;
191 else
192 return NULL;
193
194 if (!(is_uid || is_fpr || (*is_subkey && c_pgp_ignore_subkeys)))
195 memset(&tmp, 0, sizeof(tmp));
196
197 break;
198 }
199 case 2:
200 {
202
203 switch (*p)
204 {
205 case 'd':
207 break;
208 case 'e':
210 break;
211 case 'f':
212 trust = 3;
213 break;
214 case 'm':
215 trust = 2;
216 break;
217 case 'n':
218 trust = 1;
219 break;
220 case 'r':
222 break;
223 case 'u':
224 trust = 3;
225 break;
226 }
227
228 if (!is_uid && !(*is_subkey && c_pgp_ignore_subkeys))
230
231 break;
232 }
233 case 3:
234 {
236
237 if (!(*is_subkey && c_pgp_ignore_subkeys) && !mutt_str_atos_full(p, &tmp.
keylen))
238 {
239 goto bail;
240 }
241 break;
242 }
243 case 4:
244 {
246
247 if (!(*is_subkey && c_pgp_ignore_subkeys))
248 {
249 int x = 0;
250 if (!mutt_str_atoi_full(p, &x))
251 goto bail;
254 }
255 break;
256 }
257 case 5:
258 {
260
261 if (!(*is_subkey && c_pgp_ignore_subkeys))
263 break;
264 }
265 case 6:
266 {
268
269 if (strchr(p, '-'))
270 {
271 struct tm time = { 0 };
272
273 time.tm_sec = 0;
274 time.tm_min = 0;
275 time.tm_hour = 12;
276 strncpy(tstr, p, 11);
277 tstr[4] = '\0';
278 tstr[7] = '\0';
279 if (!mutt_str_atoi_full(tstr, &time.tm_year))
280 {
281 p = tstr;
282 goto bail;
283 }
284 time.tm_year -= 1900;
285 if (!mutt_str_atoi_full(tstr + 5, &time.tm_mon))
286 {
287 p = tstr + 5;
288 goto bail;
289 }
290 time.tm_mon -= 1;
291 if (!mutt_str_atoi_full(tstr + 8, &time.tm_mday))
292 {
293 p = tstr + 8;
294 goto bail;
295 }
297 }
298 else
299 {
300 unsigned long long secs;
301
303 goto bail;
305 }
306 break;
307 }
308 case 7:
309 break;
310 case 8:
311 break;
312 case 9:
313 break;
314 case 10:
315 {
316
317
318
319
320
321 if (!(pend && (*p || is_pub)))
322 break;
323
324 if (is_fpr)
325 {
326
329 break;
330 }
331
332
333 if (!is_uid && (*is_subkey && c_pgp_ignore_subkeys))
334 break;
335
337
345
346 if (strstr(p, "ENCR"))
348 if (strstr(p, "SIGN"))
350
351 break;
352 }
353 case 11:
354 break;
355 case 12:
357
358 while (*p)
359 {
360 switch (*p++)
361 {
362 case 'D':
364 break;
365
366 case 'e':
368 break;
369
370 case 's':
372 break;
373 }
374 }
375
376 if (!is_uid && (!*is_subkey || !c_pgp_ignore_subkeys ||
379 {
381 }
382
383 break;
384
385 default:
386 break;
387 }
388 }
389
390
391 if (!(is_uid || is_fpr || (*is_subkey && c_pgp_ignore_subkeys)))
393 if (!k)
394 return NULL;
395 memcpy(k, &tmp, sizeof(*k));
396
397
399 {
402 }
403
404 return k;
405
406bail:
408 return NULL;
409}
const char * mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
static void fix_uid(char *uid)
Decode backslash-escaped user ids (in place)
#define mutt_debug(LEVEL,...)
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
#define KEYFLAG_EXPIRED
Key is expired.
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
#define KEYFLAG_NO_FLAGS
No flags are set.
#define KEYFLAG_PREFER_SIGNING
Key's owner prefers signing.
#define KEYFLAG_DISABLED
Key is marked disabled.
#define KEYFLAG_REVOKED
Key is revoked.
#define KEYFLAG_PREFER_ENCRYPTION
Key's owner prefers encryption.
#define KEYFLAG_CANSIGN
Key is suitable for signing.
const char * pgp_pkalgbytype(unsigned char type)
Get the name of the algorithm from its ID.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
Information about a PGP key.
struct PgpKeyInfo * parent
Parent key.
struct PgpUid * next
Linked list.