ExceptionOpenssl.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include "Exception.hpp"
  3. #include <openssl/err.h>
  4. namespace ARL {
  5. class OpensslError final : public Exception {
  6. private:
  7. unsigned long m_ErrorCode;
  8. public:
  9. template<typename... __ArgTypes>
  10. OpensslError(const char* SourceFile, size_t SourceLine, unsigned long ErrorCode, const char* Format, __ArgTypes&&... Args) noexcept :
  11. Exception(SourceFile, SourceLine, Format, std::forward<__ArgTypes>(Args)...),
  12. m_ErrorCode(ErrorCode) {}
  13. [[nodiscard]]
  14. // NOLINTNEXTLINE: mark "virtual" explicitly for more readability
  15. virtual bool HasErrorCode() const noexcept override {
  16. return true;
  17. }
  18. [[nodiscard]]
  19. // NOLINTNEXTLINE: mark "virtual" explicitly for more readability
  20. virtual intptr_t ErrorCode() const noexcept override {
  21. return m_ErrorCode;
  22. }
  23. [[nodiscard]]
  24. // NOLINTNEXTLINE: mark "virtual" explicitly for more readability
  25. virtual const char* ErrorString() const noexcept override {
  26. static bool loaded = false;
  27. if (loaded == false) {
  28. ERR_load_crypto_strings();
  29. loaded = true;
  30. }
  31. return ERR_reason_error_string(m_ErrorCode);
  32. }
  33. };
  34. }