Kea 1.5.0
botan1_link.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2018 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/botan.h>
15#include <botan/init.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
23private:
24 Botan::LibraryInitializer botan_init_;
25};
26
27CryptoLink::~CryptoLink() {
28 rng_.reset();
29 delete impl_;
30}
31
33class RNGImpl : public RNG {
34public:
36 rng.reset(new Botan::AutoSeeded_RNG());
37 }
38
40 }
41
42private:
43 std::vector<uint8_t> random(size_t len) {
44 std::vector<uint8_t> data;
45 if (len > 0) {
46 data.resize(len);
47 try {
48 rng->randomize(&data[0], len);
49 } catch (const Botan::Exception& ex) {
51 "Botan error: " << ex.what());
52 }
53 }
54 return (data);
55 }
56
57 boost::shared_ptr<Botan::RandomNumberGenerator> rng;
58};
59
60void
62 CryptoLink& c = getCryptoLinkInternal();
63 if (!c.impl_) {
64 try {
65 c.impl_ = new CryptoLinkImpl();
66 } catch (const Botan::Exception& ex) {
67 isc_throw(InitializationError, "Botan error: " << ex.what());
68 }
69 }
70 if (!c.rng_) {
71 try {
72 c.rng_.reset(new RNGImpl());
73 } catch (const Botan::Exception& ex) {
74 isc_throw(InitializationError, "Botan error: " << ex.what());
75 }
76 }
77}
78
79std::string
81 return (Botan::version_string());
82}
83
84} // namespace cryptolink
85} // namespace isc
86
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-dhcp-ddns.