#ifndef INCLUDED_BOBCAT_ISYMCRYPTSTREAMBUF_
#define INCLUDED_BOBCAT_ISYMCRYPTSTREAMBUF_

#include "../symcryptstreambufbase/symcryptstreambufbase"
#include <bobcat/fbb>

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::SymCryptStreambufBase
{
    public:
        ISymCryptStreambuf(                                     // 1.f
                    std::istream &in,        
                    char const *cipherName,
                    std::string const &key,  
                    std::string const &iv,
                    size_t bufSize = 100,
                    size_t filterBufSize = 1000
        );
};

template <>
class ISymCryptStreambuf<DECRYPT>: public IUO::SymCryptStreambufBase
{
    public:
        ISymCryptStreambuf(                                     // 2.f
                    std::istream &in,       
                    char const *cipherName,
                    std::string const &key, 
                    std::string const &iv,
                    size_t bufSize = 100,   
                    size_t filterBufSize = 1000
        );
};

inline ISymCryptStreambuf<ENCRYPT>::ISymCryptStreambuf(
                    std::istream &in,       char const *cipherName,
                    std::string const &key, std::string const &iv,
                    size_t bufSize,         size_t filterBufSize
        )
:
    SymCryptStreambufBase(
        &EVP_EncryptInit_ex2,  &EVP_EncryptUpdate, &EVP_EncryptFinal_ex,
        in,      cipherName, 
        key,     iv,
        bufSize, filterBufSize,
        0
    )
{}
inline ISymCryptStreambuf<DECRYPT>::ISymCryptStreambuf(
            std::istream &in, char const *cipherName,
            std::string const &key, std::string const &iv, 
            size_t bufSize, size_t filterBufSize
        )
:
    SymCryptStreambufBase(
        &EVP_DecryptInit_ex2, &EVP_DecryptUpdate, &EVP_DecryptFinal_ex, 
        in,      cipherName, 
        key,     iv,
        bufSize, filterBufSize, 
        0
    )
{}

}   // namespace FBB

#endif






