cryptocommon.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef CRYPTOCOMMON_HPP
  14. #define CRYPTOCOMMON_HPP
  15. #if defined(_USE_OPENSSL) && !defined(_WIN32)
  16. #include <openssl/pem.h>
  17. #include <openssl/evp.h>
  18. #include <openssl/err.h>
  19. #include "jiface.hpp"
  20. #include "jbuff.hpp"
  21. namespace cryptohelper
  22. {
  23. jlib_decl IException *makeEVPException(int code, const char *msg);
  24. jlib_decl IException *makeEVPExceptionV(int code, const char *format, ...) __attribute__((format(printf, 2, 3)));
  25. jlib_decl void throwEVPException(int code, const char *format);
  26. jlib_decl void throwEVPExceptionV(int code, const char *format, ...) __attribute__((format(printf, 2, 3)));
  27. inline void voidBIOfree(BIO *bio) { BIO_free(bio); }
  28. inline void voidOpenSSLFree(void *m) { OPENSSL_free(m); }
  29. typedef OwnedPtrCustomFree<BIO, voidBIOfree> OwnedEVPBio;
  30. typedef OwnedPtrCustomFree<EVP_PKEY, EVP_PKEY_free> OwnedEVPPkey;
  31. typedef OwnedPtrCustomFree<EVP_PKEY_CTX, EVP_PKEY_CTX_free> OwnedEVPPkeyCtx;
  32. typedef OwnedPtrCustomFree<void, voidOpenSSLFree> OwnedEVPMemory;
  33. typedef OwnedPtrCustomFree<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free> OwnedEVPCipherCtx;
  34. typedef OwnedPtrCustomFree<RSA, RSA_free> OwnedEVPRSA;
  35. #if OPENSSL_VERSION_NUMBER < 0x10100000L
  36. typedef OwnedPtrCustomFree<EVP_MD_CTX, EVP_MD_CTX_destroy> OwnedEVPMdCtx;
  37. #else
  38. typedef OwnedPtrCustomFree<EVP_MD_CTX, EVP_MD_CTX_free> OwnedEVPMdCtx;
  39. #endif
  40. } // end of namespace cryptohelper
  41. #endif // end of #if defined(_USE_OPENSSL) && !defined(_WIN32)
  42. #endif // CRYPTOCOMMON_HPP