8 #ifndef BOTAN_SECURE_MEMORY_BUFFERS_H__ 9 #define BOTAN_SECURE_MEMORY_BUFFERS_H__ 11 #include <botan/allocate.h> 12 #include <botan/mem_ops.h> 29 size_t size()
const {
return used; }
35 bool empty()
const {
return (used == 0); }
41 operator T* () {
return buf; }
47 operator const T* ()
const {
return buf; }
65 const T*
begin()
const {
return buf; }
77 const T*
end()
const {
return (buf +
size()); }
93 bool operator<(const MemoryRegion<T>& other)
const;
101 {
return (!(*
this == other)); }
114 this->
copy(&other[0], other.
size());
126 void copy(
const T in[],
size_t n)
140 void copy(
size_t off,
const T in[],
size_t n)
195 void init(
bool locking,
size_t length = 0)
199 T* allocate(
size_t n)
201 return static_cast<T*
>(alloc->
allocate(
sizeof(T)*n));
204 void deallocate(T* p,
size_t n)
205 {
if(alloc && p && n) alloc->
deallocate(p,
sizeof(T)*n); }
227 T* new_buf = allocate(n);
229 deallocate(buf, allocated);
231 allocated = used = n;
244 for(
size_t i = 0; i != min_size; ++i)
246 if(buf[i] < other[i])
248 if(buf[i] > other[i])
253 return (size() < other.
size());
341 this->
copy(&other[0], other.
size());
362 this->
copy(&in[0], n);
378 #if __cplusplus >= 201103 382 using secure_vector = SecureVector<T>;
389 const size_t copy_offset = out.
size();
403 template<
typename T,
typename L>
405 const std::pair<const T*, L>& in)
407 const size_t copy_offset = out.
size();
409 copy_mem(&out[copy_offset], in.first, in.second);
413 template<
typename T,
typename L>
415 const std::pair<T*, L>& in)
417 const size_t copy_offset = out.
size();
419 copy_mem(&out[copy_offset], in.first, in.second);
virtual void deallocate(void *ptr, size_t n)=0
bool same_mem(const T *p1, const T *p2, size_t n)
SecureVector(const T in[], size_t n)
virtual void * allocate(size_t n)=0
void clear_mem(T *ptr, size_t n)
MemoryRegion< T > & operator=(const MemoryRegion< T > &other)
bool operator==(const MemoryRegion< T > &other) const
static Allocator * get(bool locking)
bool operator!=(const MemoryRegion< T > &other) const
void copy(const T in[], size_t n)
void init(bool locking, size_t length=0)
SecureVector< T > & operator=(const MemoryRegion< T > &other)
MemoryVector(const MemoryRegion< T > &in)
MemoryVector< T > & operator=(const MemoryRegion< T > &in)
MemoryVector(const T in[], size_t n)
SecureVector(const MemoryRegion< T > &in)
void copy_mem(T *out, const T *in, size_t n)
MemoryRegion< T > & operator+=(MemoryRegion< T > &out, const MemoryRegion< T > &in)
void swap(MemoryRegion< T > &other)
void swap(Botan::MemoryRegion< T > &x, Botan::MemoryRegion< T > &y)
void copy(size_t off, const T in[], size_t n)
MemoryRegion(const MemoryRegion< T > &other)
void zeroise(MemoryRegion< T > &vec)
bool operator<(const MemoryRegion< T > &other) const