File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -57,4 +57,28 @@ struct secure_allocator {
5757// TODO: Consider finding a way to make incoming RPC request.params[i] mlock()ed as well
5858typedef std::basic_string<char , std::char_traits<char >, secure_allocator<char > > SecureString;
5959
60+ template <typename T>
61+ struct SecureUniqueDeleter {
62+ void operator ()(T* t) noexcept {
63+ secure_allocator<T>().deallocate (t, 1 );
64+ }
65+ };
66+
67+ template <typename T>
68+ using secure_unique_ptr = std::unique_ptr<T, SecureUniqueDeleter<T>>;
69+
70+ template <typename T, typename ... Args>
71+ secure_unique_ptr<T> make_secure_unique (Args&&... as)
72+ {
73+ T* p = secure_allocator<T>().allocate (1 );
74+
75+ // initialize in place, and return as secure_unique_ptr
76+ try {
77+ return secure_unique_ptr<T>(new (p) T (std::forward (as)...));
78+ } catch (...) {
79+ secure_allocator<T>().deallocate (p, 1 );
80+ throw ;
81+ }
82+ }
83+
6084#endif // BITCOIN_SUPPORT_ALLOCATORS_SECURE_H
You can’t perform that action at this time.
0 commit comments