xref: /linux/scripts/ssl-common.h (revision 300e6d4116f956b035281ec94297dc4dc8d4e1d3)
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /*
3  * SSL helper functions shared by sign-file and extract-cert.
4  */
5 
6 static void display_openssl_errors(int l)
7 {
8 	const char *file;
9 	char buf[120];
10 	int e, line;
11 
12 	if (ERR_peek_error() == 0)
13 		return;
14 	fprintf(stderr, "At main.c:%d:\n", l);
15 
16 	while ((e = ERR_get_error_line(&file, &line))) {
17 		ERR_error_string(e, buf);
18 		fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
19 	}
20 }
21 
22 static void drain_openssl_errors(void)
23 {
24 	const char *file;
25 	int line;
26 
27 	if (ERR_peek_error() == 0)
28 		return;
29 	while (ERR_get_error_line(&file, &line)) {}
30 }
31 
32 #define ERR(cond, fmt, ...)				\
33 	do {						\
34 		bool __cond = (cond);			\
35 		display_openssl_errors(__LINE__);	\
36 		if (__cond) {				\
37 			errx(1, fmt, ## __VA_ARGS__);	\
38 		}					\
39 	} while (0)
40