rippled
ripple
beast
crypto
secure_erase.h
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of Beast: https://github.com/vinniefalco/Beast
4
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5
6
Permission to use, copy, modify, and/or distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
//==============================================================================
19
20
#ifndef BEAST_CRYPTO_SECURE_ERASE_H_INCLUDED
21
#define BEAST_CRYPTO_SECURE_ERASE_H_INCLUDED
22
23
#include <
cstddef
>
24
#include <
cstdint
>
25
#include <
new
>
26
27
namespace
beast
{
28
29
namespace
detail {
30
31
class
secure_erase_impl
32
{
33
private
:
34
struct
base
35
{
36
virtual
void
37
operator()
(
void
* dest,
std::size_t
bytes)
const
= 0;
38
virtual
~base
() =
default
;
39
base
() =
default
;
40
base
(
base
const
&) =
delete
;
41
base
&
42
operator=
(
base
const
&) =
delete
;
43
};
44
45
struct
impl
:
base
46
{
47
void
48
operator()
(
void
* dest,
std::size_t
bytes)
const override
49
{
50
char
volatile
*
volatile
p =
51
const_cast<
volatile
char
*
>
(
reinterpret_cast<
char
*
>
(dest));
52
if
(bytes == 0)
53
return
;
54
do
55
{
56
*p = 0;
57
}
while
(*p++ == 0 && --bytes);
58
}
59
};
60
61
char
buf_
[
sizeof
(
impl
)];
62
base
&
erase_
;
63
64
public
:
65
secure_erase_impl
() :
erase_
(*new (
buf_
)
impl
)
66
{
67
}
68
69
void
70
operator()
(
void
* dest,
std::size_t
bytes)
const
71
{
72
return
erase_
(dest, bytes);
73
}
74
};
75
76
}
// namespace detail
77
79
template
<
class
=
void
>
80
void
81
secure_erase
(
void
* dest,
std::size_t
bytes)
82
{
83
static
detail::secure_erase_impl
const
erase;
84
erase(dest, bytes);
85
}
86
87
}
// namespace beast
88
89
#endif
beast::detail::secure_erase_impl::buf_
char buf_[sizeof(impl)]
Definition:
secure_erase.h:61
beast::detail::secure_erase_impl::base::operator=
base & operator=(base const &)=delete
beast::detail::secure_erase_impl::erase_
base & erase_
Definition:
secure_erase.h:62
beast::detail::secure_erase_impl::secure_erase_impl
secure_erase_impl()
Definition:
secure_erase.h:65
new
beast::detail::secure_erase_impl::base::~base
virtual ~base()=default
cstddef
beast::detail::secure_erase_impl::base::base
base()=default
beast::detail::secure_erase_impl::impl
Definition:
secure_erase.h:45
cstdint
beast::secure_erase
void secure_erase(void *dest, std::size_t bytes)
Guaranteed to fill memory with zeroes.
Definition:
secure_erase.h:81
beast::detail::secure_erase_impl::operator()
void operator()(void *dest, std::size_t bytes) const
Definition:
secure_erase.h:70
beast::detail::secure_erase_impl::impl::operator()
void operator()(void *dest, std::size_t bytes) const override
Definition:
secure_erase.h:48
beast::detail::secure_erase_impl::base
Definition:
secure_erase.h:34
std::size_t
beast::detail::secure_erase_impl::base::operator()
virtual void operator()(void *dest, std::size_t bytes) const =0
beast::detail::secure_erase_impl
Definition:
secure_erase.h:31
beast
Definition:
base_uint.h:646
Generated by
1.8.17