ResourceTraitsOpenssl.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <openssl/bio.h>
  3. #include <openssl/rsa.h>
  4. namespace ARL::ResourceTraits {
  5. struct OpensslBIO {
  6. using HandleType = BIO*;
  7. static inline const HandleType InvalidValue = nullptr;
  8. [[nodiscard]]
  9. static bool IsValid(const HandleType& Handle) noexcept {
  10. return Handle != InvalidValue;
  11. }
  12. static void Release(const HandleType& Handle) noexcept {
  13. BIO_free(Handle);
  14. }
  15. };
  16. struct OpensslBIOChain {
  17. using HandleType = BIO*;
  18. static inline const HandleType InvalidValue = nullptr;
  19. [[nodiscard]]
  20. static bool IsValid(const HandleType& Handle) noexcept {
  21. return Handle != InvalidValue;
  22. }
  23. static void Release(const HandleType& Handle) noexcept {
  24. BIO_free_all(Handle);
  25. }
  26. };
  27. struct OpensslBIGNUM {
  28. using HandleType = BIGNUM*;
  29. static inline const HandleType InvalidValue = nullptr;
  30. [[nodiscard]]
  31. static bool IsValid(const HandleType& Handle) noexcept {
  32. return Handle != InvalidValue;
  33. }
  34. static void Release(const HandleType& Handle) noexcept {
  35. BN_free(Handle);
  36. }
  37. };
  38. struct OpensslRSA {
  39. using HandleType = RSA*;
  40. static inline const HandleType InvalidValue = nullptr;
  41. [[nodiscard]]
  42. static bool IsValid(const HandleType& Handle) noexcept {
  43. return Handle != InvalidValue;
  44. }
  45. static void Release(const HandleType& Handle) noexcept {
  46. RSA_free(Handle);
  47. }
  48. };
  49. }