Kea 2.7.5
|
Singleton entry point and factory class. More...
#include <cryptolink.h>
Public Member Functions | |
Hash * | createHash (const HashAlgorithm hash_algorithm) |
Factory function for Hash objects. | |
HMAC * | createHMAC (const void *secret, size_t secret_len, const HashAlgorithm hash_algorithm) |
Factory function for HMAC objects. | |
virtual RNGPtr const & | getRNG () const |
Get the global RNG. | |
Static Public Member Functions | |
static CryptoLink & | getCryptoLink () |
Returns a reference to the singleton instance. | |
static std::string | getVersion () |
Get version string. | |
Singleton entry point and factory class.
This is a singleton class that serves as the entry point to the underlying cryptography library, and as a factory for objects within the cryptolink library.
There is only one way to access it, through getCryptoLink(), which returns a reference to the initialized library. On the first call, it will be initialized automatically.
In order for the CryptoLink library to be sure that the underlying library has been initialized, and because we do not want to add such a check to every class and function within it, we have made the constructors of all classes within cryptolink private. This way a caller cannot instantiate an object before the library is initialized, but must use CryptoLink's create method (e.g. createHMAC()), which enforces (automatic) initialization.
In order for the CryptoLink class to be able to create objects that have private constructors, it is declared a friend class of these classes.
Since these factory functions return bare pointers, we also provide deleter functions for them (e.g. deleteHMAC()), so that a caller can use that to make sure it uses the correct delete operator (the one defined at compilation time of this library). A way to make sure you do not forget this, is to place the result of the create functions in a shared_ptr with the corresponding deleter function.
Internal note: we can use this class later to initialize and manage dynamic (PKCS#11) libs.
Definition at line 136 of file cryptolink.h.
Hash * isc::cryptolink::CryptoLink::createHash | ( | const HashAlgorithm | hash_algorithm | ) |
Factory function for Hash objects.
CryptoLink objects cannot be constructed directly. This function creates a new Hash object usable for signing or verification.
The caller is responsible for deleting the object, and it is therefore highly recommended to place the return value of this function in a scoped_ptr or shared_ptr.
If you want to safely delete objects created with this method, you can use the function deleteHash() as defined in crypto_hash.h.
UnsupportedAlgorithmException | if the given algorithm is unknown or not supported by the underlying library. |
LibraryError | if there was any unexpected exception in the underlying library. |
hash_algorithm | The hash algorithm. |
Definition at line 23 of file cryptolink.cc.
HMAC * isc::cryptolink::CryptoLink::createHMAC | ( | const void * | secret, |
size_t | secret_len, | ||
const HashAlgorithm | hash_algorithm ) |
Factory function for HMAC objects.
CryptoLink objects cannot be constructed directly. This function creates a new HMAC object usable for signing or verification.
The caller is responsible for deleting the object, and it is therefore highly recommended to place the return value of this function in a scoped_ptr or shared_ptr.
Notes: if the secret is longer than the block size of its algorithm, the constructor will run it through the hash algorithm, and use the digest as the secret for this HMAC operation.
If you want to safely delete objects created with this method, you can use the function deleteHMAC() as defined in crypto_hmac.h.
UnsupportedAlgorithmException | if the given algorithm is unknown or not supported by the underlying library. |
InvalidKeyLength | if the given key secret_len is bad. |
LibraryError | if there was any unexpected exception in the underlying library. |
secret | The secret to sign with |
secret_len | The length of the secret |
hash_algorithm | The hash algorithm |
Definition at line 28 of file cryptolink.cc.
|
static |
Returns a reference to the singleton instance.
If the library has not been initialized yet, it will be initialized with some default values.
Since this class is noncopyable, you must use the return value directly, or store it in a reference variable.
InitializationError | if initialization fails. |
Definition at line 17 of file cryptolink.cc.
Referenced by isc::dns::TSIGContext::TSIGContextImpl::TSIGContextImpl(), isc::dns::TSIGContext::TSIGContextImpl::createHMAC(), isc::cryptolink::digest(), isc::cryptolink::random(), isc::cryptolink::signHMAC(), and isc::cryptolink::verifyHMAC().
|
virtual |
Get the global RNG.
NotImplemented | if the method was not implemented in a derived class. |
LibraryError | if there was any unexpected exception in the underlying library. |
Definition at line 34 of file cryptolink.cc.
|
static |
Get version string.
Definition at line 76 of file botan_link.cc.
Referenced by isc::dhcp::Dhcpv4Srv::getVersion(), isc::dhcp::Dhcpv6Srv::getVersion(), and isc::process::DControllerBase::getVersion().