Kea 3.3.4
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
14
15#include <botan/exceptn.h>
16#include <botan/version.h>
17
18namespace isc {
19namespace cryptolink {
20
21// For Botan, we use the CryptoLink class object in RAII style
23 // empty class
24};
25
26CryptoLink::~CryptoLink() {
27}
28
30class RNGImpl : public RNG {
31public:
32 RNGImpl() : rng(new BotanRandomNumberGenerator()) {
33 }
34
36 }
37
38private:
39 std::vector<uint8_t> random(size_t len) {
40 std::vector<uint8_t> data;
41 if (len > 0) {
42 data.resize(len);
43 try {
44 rng->randomize(&data[0], len);
45 } catch (const Botan::Exception& ex) {
47 "Botan error: " << ex.what());
48 }
49 }
50 return (data);
51 }
52
53 boost::shared_ptr<Botan::RandomNumberGenerator> rng;
54};
55
56void
57CryptoLink::initialize(CryptoLink& c) {
58 if (!c.impl_) {
59 try {
60 c.impl_.reset(new CryptoLinkImpl());
61 } catch (const Botan::Exception& ex) {
62 isc_throw(InitializationError, "Botan error: " << ex.what());
63 }
64 }
65 if (!c.rng_) {
66 try {
67 c.rng_.reset(new RNGImpl());
68 } catch (const Botan::Exception& ex) {
69 isc_throw(InitializationError, "Botan error: " << ex.what());
70 }
71 }
72}
73
74std::string
76 return (Botan::version_string());
77}
78
79} // namespace cryptolink
80} // namespace isc
81
Botan ASIO wrapper.
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.