ResourceTraitsOpenssl.hpp 1.4 KB

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