#ifndef INCLUDED_BOBCAT_ISYMCRYPTSTREAMBUF_
#define INCLUDED_BOBCAT_ISYMCRYPTSTREAMBUF_

#include <bobcat/fbb>
#include <bobcat/isymcryptbase>

namespace FBB
{
    // generic class name, only 2 specializations exist: ENCRYPT and DECRYPT
    // defined in FBB::CryptType

template <CryptType>
class ISymCryptStreambuf;

template <>
class ISymCryptStreambuf<ENCRYPT>: public IUO::ISymCryptBase
{
    public:
        template <typename StreamSpec>
        ISymCryptStreambuf(                                     // 1.f
            StreamSpec &streamSpec,
            std::string const &cipherName,
            std::string const &key,
            std::string const &iv,
            size_t bufSize = 100
        );

        // inherits static size_t keyLength(char const *cipherName) and
        // size_t ivLength(char const *cipherName)
};

template <>
class ISymCryptStreambuf<DECRYPT>: public IUO::ISymCryptBase
{
    public:
        template <typename StreamSpec>
        ISymCryptStreambuf(                                     // 2.f
            StreamSpec &streamSpec,
            std::string const &cipherName,
            std::string const &key,
            std::string const &iv,
            size_t bufSize = 100
        );
};

template <typename StreamSpec>
inline ISymCryptStreambuf<ENCRYPT>::ISymCryptStreambuf(
                    StreamSpec &streamSpec,
                    std::string const &cipherName,
                    std::string const &key,
                    std::string const &iv,
                    size_t inBufSize
        )
:
    ISymCryptBase(
        streamSpec,
        cipherName,
        key,
        iv,
        inBufSize,
        0,
        &EVP_EncryptInit_ex2,  &EVP_EncryptUpdate, &EVP_EncryptFinal_ex
    )
{}
template <typename StreamSpec>
inline ISymCryptStreambuf<DECRYPT>::ISymCryptStreambuf(
                    StreamSpec &streamSpec,
                    std::string const &cipherName,
                    std::string const &key,
                    std::string const &iv,
                    size_t inBufSize
        )
:
    ISymCryptBase(
        streamSpec,
        cipherName,
        key,
        iv,
        inBufSize,
        0,
        &EVP_DecryptInit_ex2, &EVP_DecryptUpdate, &EVP_DecryptFinal_ex
    )
{}

}   // namespace FBB

#endif
