Kea 2.5.8
isc::cryptolink::CryptoLink Class Reference

Singleton entry point and factory class. More...

#include <cryptolink.h>

+ Inheritance diagram for isc::cryptolink::CryptoLink:

Public Member Functions

HashcreateHash (const HashAlgorithm hash_algorithm)
 Factory function for Hash objects.
 
HMACcreateHMAC (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 CryptoLinkgetCryptoLink ()
 Returns a reference to the singleton instance.
 
static std::string getVersion ()
 Get version string.
 

Detailed Description

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.

Note
All other classes within cryptolink should have private constructors as well, and should have a factory function from CryptoLink, and a deleter function.

Definition at line 137 of file cryptolink.h.

Member Function Documentation

◆ createHash()

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

Exceptions
UnsupportedAlgorithmExceptionif the given algorithm is unknown or not supported by the underlying library
LibraryErrorif there was any unexpected exception in the underlying library
Parameters
hash_algorithmThe hash algorithm

Definition at line 23 of file cryptolink.cc.

◆ createHMAC()

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

Exceptions
UnsupportedAlgorithmExceptionif the given algorithm is unknown or not supported by the underlying library
InvalidKeyLengthif the given key secret_len is bad
LibraryErrorif there was any unexpected exception in the underlying library
Parameters
secretThe secret to sign with
secret_lenThe length of the secret
hash_algorithmThe hash algorithm

Definition at line 28 of file cryptolink.cc.

◆ getCryptoLink()

CryptoLink & isc::cryptolink::CryptoLink::getCryptoLink ( )
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.

Exceptions
InitializationErrorif initialization fails
Returns
Reference to the singleton instance

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().

◆ getRNG()

RNGPtr const & isc::cryptolink::CryptoLink::getRNG ( ) const
virtual

Get the global RNG.

Exceptions
NotImplementedif the method was not implemented in a derived class
LibraryErrorif there was any unexpected exception in the underlying library

Definition at line 34 of file cryptolink.cc.

◆ getVersion()

std::string isc::cryptolink::CryptoLink::getVersion ( )
static

The documentation for this class was generated from the following files: