Kea 2.7.6
botan_link.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
13
14#include <botan/exceptn.h>
15#include <botan/version.h>
16#include <botan/auto_rng.h>
17
18namespace isc {
19namespace cryptolink {
20
21// For Botan, we use the CryptoLink class object in RAII style
22class CryptoLinkImpl {
23 // empty class
24};
25
26CryptoLink::~CryptoLink() {
27}
28
30class RNGImpl : public RNG {
31public:
33 rng.reset(new Botan::AutoSeeded_RNG());
34 }
35
37 }
38
39private:
40 std::vector<uint8_t> random(size_t len) {
41 std::vector<uint8_t> data;
42 if (len > 0) {
43 data.resize(len);
44 try {
45 rng->randomize(&data[0], len);
46 } catch (const Botan::Exception& ex) {
48 "Botan error: " << ex.what());
49 }
50 }
51 return (data);
52 }
53
54 boost::shared_ptr<Botan::RandomNumberGenerator> rng;
55};
56
57void
58CryptoLink::initialize(CryptoLink& c) {
59 if (!c.impl_) {
60 try {
61 c.impl_.reset(new CryptoLinkImpl());
62 } catch (const Botan::Exception& ex) {
63 isc_throw(InitializationError, "Botan error: " << ex.what());
64 }
65 }
66 if (!c.rng_) {
67 try {
68 c.rng_.reset(new RNGImpl());
69 } catch (const Botan::Exception& ex) {
70 isc_throw(InitializationError, "Botan error: " << ex.what());
71 }
72 }
73}
74
75std::string
77 return (Botan::version_string());
78}
79
80} // namespace cryptolink
81} // namespace isc
82
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.