blob: d840637dfb3b1bd8d7302574cb2dcb8c4c7fa301 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <boost/noncopyable.hpp>
#include <cryptolink/cryptolink.h>
#ifndef ISC_CRYPTO_RNG_H
#define ISC_CRYPTO_RNG_H
namespace isc {
namespace cryptolink {
/// \brief RNG support
///
/// This class is used to get the RNG.
/// The global instance can be get with CryptoLink::getRNG()
///
class RNG : private boost::noncopyable {
public:
/// \brief Constructor from a Random Number Generator
///
/// \exception LibraryError if there was any unexpected exception
/// in the underlying library
RNG();
/// \brief Destructor
virtual ~RNG();
/// \brief Generate random value.
///
/// The result will be returned as a std::vector<uint8_t>
///
/// \exception LibraryError if there was any unexpected exception
/// in the underlying library
///
/// \param len The number of bytes from the result to generate.
/// \return a vector containing random value.
virtual std::vector<uint8_t> random(size_t len) = 0;
private:
friend RNGPtr const& CryptoLink::getRNG() const;
};
/// \brief Generate random value.
///
/// This is a convenience function that generate random data
/// given a fixed amount of data. Internally it does the same as
/// creating an RNG object and generating the resulting value.
///
/// \exception LibraryError if there was any unexpected exception
/// in the underlying library
///
/// \param len The length of the data
std::vector<uint8_t> random(size_t len);
} // namespace cryptolink
} // namespace isc
#endif // ISC_CRYPTO_RNG_H
|