Add a class for aligned buffers
This simplifies the core crypto routines, especially the error handling. In fact there was already one error path where we were failing to call free().
This commit is contained in:
committed by
Keith Winstein
parent
c19bce27e6
commit
0734640e14
@@ -23,6 +23,7 @@
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -37,6 +38,28 @@ namespace Crypto {
|
||||
: text( s_text ), fatal( s_fatal ) {};
|
||||
};
|
||||
|
||||
/* 16-byte-aligned buffer, with length. */
|
||||
class AlignedBuffer {
|
||||
private:
|
||||
size_t m_len;
|
||||
char *m_data;
|
||||
|
||||
public:
|
||||
AlignedBuffer( size_t len, const char *data = NULL );
|
||||
|
||||
~AlignedBuffer() {
|
||||
free( m_data );
|
||||
}
|
||||
|
||||
char * data( void ) const { return m_data; }
|
||||
size_t len( void ) const { return m_len; }
|
||||
|
||||
private:
|
||||
/* Not implemented */
|
||||
AlignedBuffer( const AlignedBuffer& );
|
||||
AlignedBuffer& operator=( const AlignedBuffer& );
|
||||
};
|
||||
|
||||
class Base64Key {
|
||||
private:
|
||||
unsigned char key[ 16 ];
|
||||
|
||||
Reference in New Issue
Block a user