Kea 2.0.0
botan_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/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
23 // empty class
24};
25
26CryptoLink::~CryptoLink() {
27 delete impl_;
28}
29
31class RNGImpl : public RNG {
32public:
34 rng.reset(new Botan::AutoSeeded_RNG());
35 }
36
38 }
39
40private:
41 std::vector<uint8_t> random(size_t len) {
42 std::vector<uint8_t> data;
43 if (len > 0) {
44 data.resize(len);
45 try {
46 rng->randomize(&data[0], len);
47 } catch (const Botan::Exception& ex) {
49 "Botan error: " << ex.what());
50 }
51 }
52 return (data);
53 }
54
55 boost::shared_ptr<Botan::RandomNumberGenerator> rng;
56};
57
58void
60 CryptoLink& c = getCryptoLinkInternal();
61 if (!c.impl_) {
62 try {
63 c.impl_ = new CryptoLinkImpl();
64 } catch (const Botan::Exception& ex) {
65 isc_throw(InitializationError, "Botan error: " << ex.what());
66 }
67 }
68 if (!c.rng_) {
69 try {
70 c.rng_.reset(new RNGImpl());
71 } catch (const Botan::Exception& ex) {
72 isc_throw(InitializationError, "Botan error: " << ex.what());
73 }
74 }
75 // A not yet fixed bug makes RNG to be destroyed after memory pool...
76 atexit([]{ getCryptoLink().getRNG().reset(); });
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-lfc.