Parse the 'pub' line from the pgp output.
135{
136 struct PgpUid *uid = NULL;
137 int field = 0;
138 bool is_uid = false;
139 bool is_pub = false;
140 bool is_fpr = false;
141 char *pend = NULL, *p = NULL;
144 char tstr[11] = { 0 };
145
146 *is_subkey = false;
147 if (*buf == '\0')
148 return NULL;
149
150
151
152
154 if (k)
155 memcpy(&tmp, k, sizeof(tmp));
156
158
160 for (p = buf; p; p = pend)
161 {
162 pend = strchr(p, ':');
163 if (pend)
164 *pend++ = 0;
165 field++;
166 if ((*p == '\0') && (field != 1) && (field != 10))
167 continue;
168
169 if (is_fpr && (field != 10))
170 continue;
171
172 switch (field)
173 {
174 case 1:
175 {
177
179 is_pub = true;
181 *is_subkey = true;
183 ;
185 *is_subkey = true;
187 is_uid = true;
189 is_fpr = true;
190 else
191 return NULL;
192
193 if (!(is_uid || is_fpr || (*is_subkey && c_pgp_ignore_subkeys)))
194 memset(&tmp, 0, sizeof(tmp));
195
196 break;
197 }
198 case 2:
199 {
201
202 switch (*p)
203 {
204 case 'd':
206 break;
207 case 'e':
209 break;
210 case 'f':
211 trust = 3;
212 break;
213 case 'm':
214 trust = 2;
215 break;
216 case 'n':
217 trust = 1;
218 break;
219 case 'r':
221 break;
222 case 'u':
223 trust = 3;
224 break;
225 }
226
227 if (!is_uid && !(*is_subkey && c_pgp_ignore_subkeys))
229
230 break;
231 }
232 case 3:
233 {
235
236 if (!(*is_subkey && c_pgp_ignore_subkeys) && !mutt_str_atos_full(p, &tmp.
keylen))
237 {
238 goto bail;
239 }
240 break;
241 }
242 case 4:
243 {
245
246 if (!(*is_subkey && c_pgp_ignore_subkeys))
247 {
248 int x = 0;
249 if (!mutt_str_atoi_full(p, &x))
250 goto bail;
253 }
254 break;
255 }
256 case 5:
257 {
259
260 if (!(*is_subkey && c_pgp_ignore_subkeys))
262 break;
263 }
264 case 6:
265 {
267
268 if (strchr(p, '-'))
269 {
270 struct tm time = { 0 };
271
272 time.tm_sec = 0;
273 time.tm_min = 0;
274 time.tm_hour = 12;
275 strncpy(tstr, p, 11);
276 tstr[4] = '\0';
277 tstr[7] = '\0';
278 if (!mutt_str_atoi_full(tstr, &time.tm_year))
279 {
280 p = tstr;
281 goto bail;
282 }
283 time.tm_year -= 1900;
284 if (!mutt_str_atoi_full(tstr + 5, &time.tm_mon))
285 {
286 p = tstr + 5;
287 goto bail;
288 }
289 time.tm_mon -= 1;
290 if (!mutt_str_atoi_full(tstr + 8, &time.tm_mday))
291 {
292 p = tstr + 8;
293 goto bail;
294 }
296 }
297 else
298 {
299 unsigned long long secs;
300
302 goto bail;
304 }
305 break;
306 }
307 case 7:
308 break;
309 case 8:
310 break;
311 case 9:
312 break;
313 case 10:
314 {
315
316
317
318
319
320 if (!(pend && (*p || is_pub)))
321 break;
322
323 if (is_fpr)
324 {
325
328 break;
329 }
330
331
332 if (!is_uid && (*is_subkey && c_pgp_ignore_subkeys))
333 break;
334
336
344
345 if (strstr(p, "ENCR"))
347 if (strstr(p, "SIGN"))
349
350 break;
351 }
352 case 11:
353 break;
354 case 12:
356
357 while (*p)
358 {
359 switch (*p++)
360 {
361 case 'D':
363 break;
364
365 case 'e':
367 break;
368
369 case 's':
371 break;
372 }
373 }
374
375 if (!is_uid && (!*is_subkey || !c_pgp_ignore_subkeys ||
378 {
380 }
381
382 break;
383
384 default:
385 break;
386 }
387 }
388
389
390 if (!(is_uid || is_fpr || (*is_subkey && c_pgp_ignore_subkeys)))
392 if (!k)
393 return NULL;
394 memcpy(k, &tmp, sizeof(*k));
395
396
398 {
401 }
402
403 return k;
404
405bail:
407 return NULL;
408}
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.