12#if defined(HAVE_CONFIG_H)
22#include "openssl/evp.h"
25# if defined(WIN32) && !defined(__GNUC__)
26# pragma warning( disable : 4355 )
34 std::memset(mBuf, 0,
sizeof(mBuf));
35 setp(mBuf, mBuf +
sizeof(mBuf));
37 mContext.reset(EVP_MD_CTX_new());
39 throw std::bad_alloc();
40 int res = EVP_DigestInit_ex(mContext.get(), EVP_sha1(), NULL);
42 throw std::runtime_error(
"Failed to initialize SHA1 context");
52 std::size_t len = pptr() - pbase();
55 EVP_DigestUpdate(mContext.get(),
reinterpret_cast<unsigned const char*
>(pbase()), len);
57 setp(mBuf, mBuf +
sizeof(mBuf));
79 unsigned char md_value[EVP_MAX_MD_SIZE];
80 unsigned int md_len = 0u;
81 EVP_DigestFinal_ex(mContext.get(), md_value, &md_len);
93 unsigned char md_value[EVP_MAX_MD_SIZE];
94 unsigned int md_len = 0u;
95 EVP_DigestFinal_ex(mContext.get(), md_value, &md_len);
97 unsigned int len = std::min(
bits / 8u, md_len);
98 return Data(md_value + (md_len - len), len);
static Data digest("digest")
#define resip_assert(x)
This file needs to work for both C and C++ code.
DEPRECATED - Use DigestStream.hxx instead.
Handles cross-platform sockets compatibility.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * c_str() const
Returns a null-terminated string representing.
@ Share
The Data instance will use the buffer in a read-only mode.
Data hex() const
Returns a hexadecimal representation of the contents of this Data.
virtual int overflow(int c=-1)
Data getBin(unsigned int bits)
Data getBin(unsigned int bits=160)
Calls flush() on itself and returns the SHA1 data in binary format.
Data getHex()
Calls flush() on itself and returns the SHA1 data in hex format.
uint32_t getUInt32()
Calls getBin(32) and converts to a UInt32.
dcm! – add UnusedChecking(_enum) below;