12 #ifndef OPENSSL_CPP_EVP_H_WRAP_PREDOEHL_UOFARIZONA_VISION
13 #define OPENSSL_CPP_EVP_H_WRAP_PREDOEHL_UOFARIZONA_VISION
17 #ifdef KJB_HAVE_OPENSSL
18 #include <openssl/evp.h>
20 #warning "OpenSSL is required for class OpenSSL_EVP to function properly"
39 typedef unsigned char Unit;
46 #ifdef KJB_HAVE_OPENSSL
67 #ifdef KJB_HAVE_OPENSSL
68 void update(
const void* data,
unsigned long len )
70 ETX_2( m_finalized,
"Cannot write to an already-finalized digest");
71 ETX( 0 == EVP_DigestUpdate( &m_context, data, len ) );
80 void update(
const void*,
unsigned long )
82 using namespace kjb_c;
83 SET_CANT_HAPPEN_BUG();
103 #ifdef KJB_HAVE_OPENSSL
105 : m_digest( EVP_MAX_MD_SIZE ),
108 EVP_MD_CTX_init( &m_context );
109 ETX( 0 == EVP_DigestInit_ex( &m_context, algorithm, 00 ) );
110 m_digest.resize( EVP_MD_CTX_size( &m_context ) );
115 : m_finalized( true )
118 "Missing OpenSSL -- cannot instantiate kjb::OpenSSL_EVP");
125 #ifdef KJB_HAVE_OPENSSL
126 EVP_MD_CTX_cleanup( &m_context );
135 void write(
const void* data,
unsigned long len )
142 template<
typename T >
143 void put(
const T& datum )
145 write( (
const void*) & datum,
sizeof( T ) );
149 template<
typename SeqIterator >
154 for( SeqIterator ppp = begin; ppp !=
end; )
163 return m_digest.size();
177 return m_digest.at( index );
184 return m_digest.begin();
188 Digest::const_iterator
end()
191 return m_digest.end();
Unit operator[](size_t index)
Access one character of the message digest.
Definition: wrap_openssl_evp.h:174
Generic OpenSSL hasher class, the base class for specific derivations.
Definition: wrap_openssl_evp.h:34
#define ETX(a)
Definition: l_exception.h:67
bool is_finalized() const
Return whether the hasher is finalized, i.e., can I write to it?
Definition: wrap_openssl_evp.h:195
OpenSSL_EVP()
ctor must specify the algorithm
Definition: wrap_openssl_evp.h:114
Digest::const_iterator begin()
Return const iterator to start of message digest.
Definition: wrap_openssl_evp.h:181
size_t size() const
Return size of message digest.
Definition: wrap_openssl_evp.h:161
void put(const T &datum)
Hash a single primitive datum, using a "shallow read".
Definition: wrap_openssl_evp.h:143
Digest copy_digest()
Return a copy of the message digest.
Definition: wrap_openssl_evp.h:167
~OpenSSL_EVP()
this thing needs a dtor or it leaks
Definition: wrap_openssl_evp.h:123
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
#define ETX_2(a, msg)
Definition: l_exception.h:78
void write(const void *data, unsigned long len)
Hash an array of bytes; len is the number of bytes.
Definition: wrap_openssl_evp.h:135
std::vector< Unit > Digest
Type of output of the hasher.
Definition: wrap_openssl_evp.h:42
Support for error handling exception classes in libKJB.
Object thrown when a program lacks required resources or libraries.
Definition: l_exception.h:539
void write(SeqIterator begin, SeqIterator end)
Hash a container of primitive data via STL sequential iterators.
Definition: wrap_openssl_evp.h:150
Digest::const_iterator end()
Return const iterator to one-past-last of message digest.
Definition: wrap_openssl_evp.h:188
unsigned char Unit
The basic unit of both input and output for the hasher.
Definition: wrap_openssl_evp.h:39