1 // Copyright (C) 2021 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 #ifndef D2_TSIG_KEY_H 8 #define D2_TSIG_KEY_H 9 10 #include <dns/name.h> 11 #include <dns/tsig.h> 12 #include <boost/shared_ptr.hpp> 13 14 namespace isc { 15 namespace d2 { 16 17 /// @brief Statistics keeping extension of the DNS TSIGKey class. 18 /// 19 /// Implements a TSIGKey derived class which can be used as the value 20 /// of TSIGKeyPtr so with minimal or no update to the DNS++ library. 21 class D2TsigKey : public dns::TSIGKey { 22 public: 23 /// @brief Constructor. 24 /// 25 /// Initialize the key statistics. 26 /// 27 /// @param key_spec Specification of the key 28 /// (name:secret[:algorithm][:digestbits]) 29 explicit D2TsigKey(const std::string& key_spec); 30 31 /// @brief Constructor. 32 /// 33 /// Initialize the key statistics. 34 /// 35 /// @param key_name The name of the key as a domain name. 36 /// @param algorithm_name The hash algorithm used for this key in the 37 /// form of domain name. 38 /// @param secret Point to a binary sequence of the shared secret to be 39 /// used for this key. 40 /// @param secret_len The size of the binary %data (@c secret) in bytes. 41 /// @param digestbits The number of bits to include in the digest 42 /// (0 means to include all) 43 D2TsigKey(const dns::Name& key_name, const dns::Name& algorithm_name, 44 const void* secret, size_t secret_len, size_t digestbits = 0); 45 46 /// @brief Destructor. 47 /// 48 /// Remove the key statistics. 49 virtual ~D2TsigKey(); 50 51 /// @brief Reset statistics. 52 /// 53 virtual void resetStats(); 54 55 /// @brief Create TSIG context. 56 /// 57 /// @note Derived classes can implement their own specific context. 58 /// 59 /// @return The specific @ref dns::TSIGContext of the @ref dns::TSIGKey. 60 virtual dns::TSIGContextPtr createContext(); 61 62 private: 63 /// @brief Initialize key statistics. 64 void initStats(); 65 66 /// @brief Remove key statistics. 67 void removeStats(); 68 }; 69 70 /// @brief Type of pointer to a D2 TSIG key. 71 typedef boost::shared_ptr<D2TsigKey> D2TsigKeyPtr; 72 73 } // namespace d2 74 } // namespace isc 75 76 #endif // D2_TSIG_KEY_H 77