Jeffrey Walton a 9crit :
Hi All,
Bear with the newbie question. It has been years since I had this in
college.
I'm working with Crypto++. I'm trying to build a base class array, but
the class is templated. Is there anyway to make it happen? I'm hoping
it is a syntax problem on my part.
template<class BASE>
class CipherModeFinalTemplate_ExternalCipher< BASE >
CipherModeFinalTemplate_ExternalCipher* Ciphers[] = {
CipherModeFinalTemplate_ExternalCipher is a template, you cannot create
an array from it; you must specialize it.
new CipherModeFinalTemplate_ExternalCipher< ECB_Mode >,
...
}
The template is defined as follow:
template <class BASE>
class CipherModeFinalTemplate_ExternalCipher : public BASE
{
//...
};
Therefore, the templates specicialisations are likely to be orthogonal
classes (ie. they do not share a common ancestor you can use).
I want to get to SetCipher() of the class so I can dynamically change
it at runtime. Sample code is athttp://cryptopp.pastebin.com/d3a117c6c
A solution is to create a holder making them inheriting from a common
interface:
struct CipherModeInterface
{
virtual void SetCipher (BlockCipher &cipher)=0;
};
template<class BASE>
struct CipherModeHolder: public CipherModeInterface
{
virtual void SetCipher (BlockCipher &cipher)
{
value.SetCipher(cipher);
}
CipherModeFinalTemplate_ExternalCipher<BASE> value;
};
And then you can create;
CipherModeInterface* Ciphers[]={
new CipherModeHolder<ECB_MODE>(),
//...
};
I don't know where you want to use the
CipherModeFinalTemplate_ExternalCipher<> instances but you cannot get
them back unless you know their type and do a dynamic_cast or unless you
they can be used through the common interface CipherModeInterface.
My impression is that your design is not in line with the intent of the
library.
Full library documentation is at
http://www.cryptopp.com/docs/ref/class_cipher_mode_final_template___e...
Michael