Botan  2.1.0
Crypto and TLS for C++11
Public Types | Public Member Functions | List of all members
Botan::secure_allocator< T > Class Template Reference

#include <secmem.h>

Public Types

typedef const T * const_pointer
 
typedef const T & const_reference
 
typedef std::ptrdiff_t difference_type
 
typedef T * pointer
 
typedef T & reference
 
typedef std::size_t size_type
 
typedef T value_type
 

Public Member Functions

pointer address (reference x) const BOTAN_NOEXCEPT
 
const_pointer address (const_reference x) const BOTAN_NOEXCEPT
 
pointer allocate (size_type n, const void *=0)
 
template<typename U , typename... Args>
void construct (U *p, Args &&...args)
 
void deallocate (pointer p, size_type n)
 
size_type max_size () const BOTAN_NOEXCEPT
 
secure_allocatoroperator= (const secure_allocator &) BOTAN_NOEXCEPT=default
 
 secure_allocator () BOTAN_NOEXCEPT=default
 
 secure_allocator (const secure_allocator &) BOTAN_NOEXCEPT=default
 
template<typename U >
 secure_allocator (const secure_allocator< U > &) BOTAN_NOEXCEPT
 
 ~secure_allocator () BOTAN_NOEXCEPT=default
 

Detailed Description

template<typename T>
class Botan::secure_allocator< T >

Definition at line 24 of file secmem.h.

Member Typedef Documentation

template<typename T>
typedef const T* Botan::secure_allocator< T >::const_pointer

Definition at line 41 of file secmem.h.

template<typename T>
typedef const T& Botan::secure_allocator< T >::const_reference

Definition at line 44 of file secmem.h.

template<typename T>
typedef std::ptrdiff_t Botan::secure_allocator< T >::difference_type

Definition at line 47 of file secmem.h.

template<typename T>
typedef T* Botan::secure_allocator< T >::pointer

Definition at line 40 of file secmem.h.

template<typename T>
typedef T& Botan::secure_allocator< T >::reference

Definition at line 43 of file secmem.h.

template<typename T>
typedef std::size_t Botan::secure_allocator< T >::size_type

Definition at line 46 of file secmem.h.

template<typename T>
typedef T Botan::secure_allocator< T >::value_type

Definition at line 35 of file secmem.h.

Constructor & Destructor Documentation

template<typename T>
Botan::secure_allocator< T >::secure_allocator ( )
default
template<typename T>
Botan::secure_allocator< T >::secure_allocator ( const secure_allocator< T > &  )
default
template<typename T>
Botan::secure_allocator< T >::~secure_allocator ( )
default
template<typename T>
template<typename U >
Botan::secure_allocator< T >::secure_allocator ( const secure_allocator< U > &  )
inline

Definition at line 62 of file secmem.h.

62 {}

Member Function Documentation

template<typename T>
pointer Botan::secure_allocator< T >::address ( reference  x) const
inline

Definition at line 64 of file secmem.h.

65  { return std::addressof(x); }
template<typename T>
const_pointer Botan::secure_allocator< T >::address ( const_reference  x) const
inline

Definition at line 67 of file secmem.h.

68  { return std::addressof(x); }
template<typename T>
pointer Botan::secure_allocator< T >::allocate ( size_type  n,
const void *  = 0 
)
inline

Definition at line 70 of file secmem.h.

References Botan::clear_mem(), and Botan::mlock_allocator::instance().

71  {
72 #if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
73  if(pointer p = static_cast<pointer>(mlock_allocator::instance().allocate(n, sizeof(T))))
74  return p;
75 #endif
76 
77  pointer p = new T[n];
78  clear_mem(p, n);
79  return p;
80  }
static mlock_allocator & instance()
void clear_mem(T *ptr, size_t n)
Definition: mem_ops.h:57
pointer allocate(size_type n, const void *=0)
Definition: secmem.h:70
template<typename T>
template<typename U , typename... Args>
void Botan::secure_allocator< T >::construct ( U *  p,
Args &&...  args 
)
inline

Definition at line 100 of file secmem.h.

101  {
102  ::new(static_cast<void*>(p)) U(std::forward<Args>(args)...);
103  }
Definition: bigint.h:619
template<typename T>
void Botan::secure_allocator< T >::deallocate ( pointer  p,
size_type  n 
)
inline

Definition at line 82 of file secmem.h.

References Botan::mlock_allocator::instance(), and Botan::secure_scrub_memory().

83  {
84  secure_scrub_memory(p, n);
85 
86 #if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
87  if(mlock_allocator::instance().deallocate(p, n, sizeof(T)))
88  return;
89 #endif
90 
91  delete [] p;
92  }
void secure_scrub_memory(void *ptr, size_t n)
Definition: mem_ops.cpp:17
static mlock_allocator & instance()
void deallocate(pointer p, size_type n)
Definition: secmem.h:82
template<typename T>
size_type Botan::secure_allocator< T >::max_size ( ) const
inline

Definition at line 94 of file secmem.h.

95  {
96  return static_cast<size_type>(-1) / sizeof(T);
97  }
std::size_t size_type
Definition: secmem.h:46
template<typename T>
secure_allocator& Botan::secure_allocator< T >::operator= ( const secure_allocator< T > &  )
default

The documentation for this class was generated from the following file: