HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
security_intf.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
8
9#include "../utility/utility.hpp"
10#include "../macros.hpp"
11#include <iterator>
12#include <memory>
13
14hi_export_module(hikogui.security : intf);
15
16
17hi_export namespace hi::inline v1 {
18
26void secure_clear(void *ptr, size_t size) noexcept;
27
34inline void secure_clear(trivially_copyable auto &object) noexcept
35{
36 secure_clear(&object, sizeof(object));
37}
38
46template<typename It>
47void secure_clear(It first, It last) noexcept
48{
49 using value_type = decltype(*first);
50
51 if constexpr (requires { std::distance(first, last); }) {
52 secure_clear(std::addressof(*first), std::distance(first, last) * sizeof(value_type));
53
54 } else {
55 for (auto it = first; it != last; ++it) {
56 secure_clear(*it);
57 }
58 }
59}
60
61void secure_destroy_at(auto *p)
62{
63 std::destroy_at(p);
64 secure_clear(*p);
65}
66
75template<typename It>
76void secure_destroy(It first, It last)
77{
78 std::destroy(first, last);
79 secure_clear(first, last);
80}
81
91template<typename It, typename OutIt>
92void secure_uninitialized_move(It first, It last, OutIt d_first)
93{
94 std::uninitialized_move(first, last, d_first);
95 secure_erase(first, last);
96}
97
98}
99
Rules for working with win32 headers.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
void secure_destroy(It first, It last)
Securely destroy objects.
Definition security_intf.hpp:76
void secure_uninitialized_move(It first, It last, OutIt d_first)
Securely move objects.
Definition security_intf.hpp:92
void secure_clear(void *ptr, size_t size) noexcept
Securely clear memory.
Definition security_win32_impl.hpp:16
T addressof(T... args)
T distance(T... args)