CppSecurity 1.1.2.0
C++ Security Library
Loading...
Searching...
No Matches
password.h
Go to the documentation of this file.
1
9#ifndef CPPSECURITY_STRING_PASSWORD_H
10#define CPPSECURITY_STRING_PASSWORD_H
11
12#include "memory/memory.h"
13
14#include <string>
15
16namespace CppSecurity {
17
19template <class T>
20class PasswordAllocator : public std::allocator<T>
21{
22public:
23 typedef typename std::allocator<T>::value_type value_type;
24 typedef typename std::allocator<T>::size_type size_type;
25 typedef typename std::allocator<T>::difference_type difference_type;
26
27 template<class U> struct rebind { typedef PasswordAllocator<U> other; };
28
29 PasswordAllocator() throw() {}
31 template <class U> PasswordAllocator(const PasswordAllocator<U>&) throw() {}
32
33 void deallocate(T* p, size_type n)
34 {
35 CppCommon::Memory::ZeroFill(p, n * sizeof(T));
36 std::allocator<T>::deallocate(p, n);
37 }
38};
39
40} // namespace CppSecurity
41
42namespace std {
43
45
52class password : public std::basic_string<char, std::char_traits<char>, CppSecurity::PasswordAllocator<char>>
53{
54public:
55 using basic_string::basic_string;
57 void clear() noexcept { CppCommon::Memory::ZeroFill(data(), size()); }
58};
59
60} // namespace std
61
62#endif // CPPSECURITY_STRING_PASSWORD_H
Password allocator.
Definition password.h:21
PasswordAllocator(const PasswordAllocator< U > &)
Definition password.h:31
std::allocator< T >::size_type size_type
Definition password.h:24
std::allocator< T >::value_type value_type
Definition password.h:23
PasswordAllocator(const PasswordAllocator &)
Definition password.h:30
std::allocator< T >::difference_type difference_type
Definition password.h:25
void deallocate(T *p, size_type n)
Definition password.h:33
Password string.
Definition password.h:53
void clear() noexcept
Definition password.h:57
Definition password.h:42
PasswordAllocator< U > other
Definition password.h:27