Skip to content

Commit

Permalink
Merge pull request #133 from s-vincent/openssl1.1.0
Browse files Browse the repository at this point in the history
Fixes compilation with Openssl1.0.x.
  • Loading branch information
s-vincent authored Aug 8, 2017
2 parents 58cfad7 + c004509 commit 51b983a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
4 changes: 4 additions & 0 deletions libs/cryptoplus/include/cryptoplus/asn1/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ namespace cryptoplus
}
inline const unsigned char* string::data()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
return ASN1_STRING_data(ptr().get());
#else
return ASN1_STRING_get0_data(ptr().get());
#endif
}
inline void string::set_data(const void* _data, size_t data_len) const
{
Expand Down
10 changes: 10 additions & 0 deletions libs/cryptoplus/include/cryptoplus/bio/bio_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ namespace cryptoplus
*/
explicit bio_chain(const BIO_METHOD* type);

/**
* \brief Create a new bio_chain from a BIO_METHOD.
* \param type The type.
*/
explicit bio_chain(BIO_METHOD* type);

/**
* \brief Create a new bio_chain by taking ownership of an existing BIO pointer.
* \param bio The BIO pointer. Cannot be NULL.
Expand All @@ -93,7 +99,11 @@ namespace cryptoplus
boost::shared_ptr<BIO> m_bio;
};

#if OPENSSL_VERSION_NUMBER < 0x10100000L
inline bio_chain::bio_chain(BIO_METHOD* _type) : m_bio(BIO_new(_type), BIO_free_all)
#else
inline bio_chain::bio_chain(const BIO_METHOD* _type) : m_bio(BIO_new(_type), BIO_free_all)
#endif
{
throw_error_if_not(m_bio != NULL);
}
Expand Down
22 changes: 20 additions & 2 deletions libs/cryptoplus/include/cryptoplus/hash/hmac_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,24 @@ namespace cryptoplus
HMAC_CTX* m_ctx;
};

inline hmac_context::hmac_context() : m_ctx(HMAC_CTX_new()) {}
inline hmac_context::hmac_context()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
m_ctx = new HMAC_CTX;
HMAC_CTX_init(m_ctx);
#else
m_ctx = HMAC_CTX_new();
#endif
}

inline hmac_context::~hmac_context()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX_cleanup(m_ctx);
delete m_ctx;
#else
HMAC_CTX_free(m_ctx);
#endif
}

inline void hmac_context::update(const void* data, size_t len)
Expand Down Expand Up @@ -179,7 +192,12 @@ namespace cryptoplus

inline message_digest_algorithm hmac_context::algorithm() const
{
return HMAC_CTX_get_md(m_ctx);
#if OPENSSL_VERSION_NUMBER < 0x10100000L
//WARNING: Here we directly use the undocumented HMAC_CTX.md field.
return message_digest_algorithm(m_ctx->md);
#else
return HMAC_CTX_get_md(m_ctx);
#endif
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ namespace cryptoplus
/**
* \brief Create a new message_digest_context.
*/
message_digest_context() : m_ctx(EVP_MD_CTX_new()) {}
message_digest_context()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
m_ctx = new EVP_MD_CTX;
EVP_MD_CTX_init(m_ctx);
#else
m_ctx = EVP_MD_CTX_new();
#endif
}

/**
* \brief Copy a message_digest_context.
Expand All @@ -89,7 +97,12 @@ namespace cryptoplus
*/
~message_digest_context()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_MD_CTX_cleanup(m_ctx);
delete m_ctx;
#else
EVP_MD_CTX_free(m_ctx);
#endif
}

/**
Expand Down

0 comments on commit 51b983a

Please sign in to comment.