ssl-common.h 678 B

1234567891011121314151617181920212223242526272829303132
  1. /* SPDX-License-Identifier: LGPL-2.1+ */
  2. /*
  3. * SSL helper functions shared by sign-file and extract-cert.
  4. */
  5. static void drain_openssl_errors(int l, int silent)
  6. {
  7. const char *file;
  8. char buf[120];
  9. int e, line;
  10. if (ERR_peek_error() == 0)
  11. return;
  12. if (!silent)
  13. fprintf(stderr, "At main.c:%d:\n", l);
  14. while ((e = ERR_peek_error_line(&file, &line))) {
  15. ERR_error_string(e, buf);
  16. if (!silent)
  17. fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
  18. ERR_get_error();
  19. }
  20. }
  21. #define ERR(cond, fmt, ...) \
  22. do { \
  23. bool __cond = (cond); \
  24. drain_openssl_errors(__LINE__, 0); \
  25. if (__cond) { \
  26. errx(1, fmt, ## __VA_ARGS__); \
  27. } \
  28. } while (0)