8 #ifndef BOTAN_SECURE_MEMORY_BUFFERS_H_
9 #define BOTAN_SECURE_MEMORY_BUFFERS_H_
11 #include <botan/types.h>
12 #include <botan/mem_ops.h>
16 #include <type_traits>
31 #if !defined(_ITERATOR_DEBUG_LEVEL) || _ITERATOR_DEBUG_LEVEL == 0
32 static_assert(std::is_integral<T>::value,
"secure_allocator supports only integer types");
57 template<
typename T,
typename U>
inline bool
61 template<
typename T,
typename U>
inline bool
65 template<
typename T>
using secure_vector = std::vector<T, secure_allocator<T>>;
66 template<
typename T>
using secure_deque = std::deque<T, secure_allocator<T>>;
74 std::vector<T> out(in.size());
75 copy_mem(out.data(), in.data(), in.size());
79 template<
typename T,
typename Alloc>
86 const size_t to_copy = std::min(input_length, buf.size() - buf_offset);
89 copy_mem(&buf[buf_offset], input, to_copy);
94 template<
typename T,
typename Alloc,
typename Alloc2>
97 const std::vector<T, Alloc2>& input)
100 const size_t to_copy = std::min(input.size(), buf.size() - buf_offset);
103 copy_mem(&buf[buf_offset], input.data(), to_copy);
108 template<
typename T,
typename Alloc,
typename Alloc2>
109 std::vector<T, Alloc>&
111 const std::vector<T, Alloc2>& in)
113 const size_t copy_offset = out.size();
114 out.resize(out.size() + in.size());
117 copy_mem(&out[copy_offset], in.data(), in.size());
122 template<
typename T,
typename Alloc>
123 std::vector<T, Alloc>&
operator+=(std::vector<T, Alloc>& out,
T in)
129 template<
typename T,
typename Alloc,
typename L>
130 std::vector<T, Alloc>&
operator+=(std::vector<T, Alloc>& out,
131 const std::pair<const T*, L>& in)
133 const size_t copy_offset = out.size();
134 out.resize(out.size() + in.second);
137 copy_mem(&out[copy_offset], in.first, in.second);
142 template<
typename T,
typename Alloc,
typename L>
143 std::vector<T, Alloc>&
operator+=(std::vector<T, Alloc>& out,
144 const std::pair<T*, L>& in)
146 const size_t copy_offset = out.size();
147 out.resize(out.size() + in.second);
150 copy_mem(&out[copy_offset], in.first, in.second);
159 template<
typename T,
typename Alloc>
169 template<
typename T,
typename Alloc>
170 void zap(std::vector<T, Alloc>& vec)
void deallocate(T *p, std::size_t n)
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
void zap(std::vector< T, Alloc > &vec)
BOTAN_MALLOC_FN void * allocate_memory(size_t elems, size_t elem_size)
void clear_mem(T *ptr, size_t n)
#define BOTAN_ASSERT_NOMSG(expr)
T * allocate(std::size_t n)
std::deque< T, secure_allocator< T >> secure_deque
secure_allocator() noexcept=default
std::vector< T, secure_allocator< T >> secure_vector
secure_vector< T > SecureVector
void deallocate_memory(void *p, size_t elems, size_t elem_size)
std::vector< T, Alloc > & operator+=(std::vector< T, Alloc > &out, const std::vector< T, Alloc2 > &in)
void copy_mem(T *out, const T *in, size_t n)
std::vector< T > unlock(const secure_vector< T > &in)
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
void zeroise(std::vector< T, Alloc > &vec)