Passwordfile library
5.0.12
C++ library to read/write passwords from/to encrypted files
Loading...
Searching...
No Matches
util
opensslrandomdevice.cpp
Go to the documentation of this file.
1
#include "
./opensslrandomdevice.h
"
2
3
#include "
../io/cryptoexception.h
"
4
5
#include <c++utilities/conversion/binaryconversion.h>
6
7
#include <openssl/err.h>
8
#include <openssl/rand.h>
9
10
#include <string>
11
12
using namespace
std;
13
using namespace
CppUtilities
;
14
15
namespace
Util
{
16
25
OpenSslRandomDevice::OpenSslRandomDevice
()
26
{
27
}
28
32
OpenSslRandomDevice::result_type
OpenSslRandomDevice::operator()
()
const
33
{
34
unsigned
char
buf[4];
35
if
(RAND_bytes(buf,
sizeof
(buf))) {
36
return
LE::toUInt32(
reinterpret_cast<
char
*
>
(buf));
37
}
38
39
// handle error case
40
string
errorMsg;
41
while
(
unsigned
long
errorCode = ERR_get_error()) {
42
if
(!errorMsg.empty()) {
43
errorMsg +=
'\n'
;
44
}
45
errorMsg += ERR_error_string(errorCode,
nullptr
);
46
errorCode = ERR_get_error();
47
}
48
throw
Io::CryptoException
(std::move(errorMsg));
49
}
50
54
bool
OpenSslRandomDevice::status
()
const
55
{
56
return
RAND_status();
57
}
58
}
// namespace Util
Io::CryptoException
The exception that is thrown when an encryption/decryption error occurs.
Definition
cryptoexception.h:11
Util::OpenSslRandomDevice::result_type
std::uint32_t result_type
Definition
opensslrandomdevice.h:13
Util::OpenSslRandomDevice::operator()
result_type operator()() const
Generates a new random number.
Definition
opensslrandomdevice.cpp:32
Util::OpenSslRandomDevice::status
bool status() const
Returns the status.
Definition
opensslrandomdevice.cpp:54
Util::OpenSslRandomDevice::OpenSslRandomDevice
OpenSslRandomDevice()
Constructs a new random device.
Definition
opensslrandomdevice.cpp:25
cryptoexception.h
CppUtilities
Definition
utils.h:12
Util
Contains utility classes and functions.
Definition
openssl.h:9
opensslrandomdevice.h
Generated on Tue Aug 6 2024 22:26:30 for Passwordfile library by
1.11.0