#ifndef INCLUDED_DECRYPTBUF_
#define INCLUDED_DECRYPTBUF_

// https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption

#include <iosfwd>
#include <string>
#include <bobcat/cryptbuf>

namespace FBB
{

class DecryptBuf: public CryptBuf
{
    EVP_CIPHER_CTX *d_ctx;

    std::string     d_decrypted;
    bool            d_eoi = false;

    std::string     d_iv;
    std::string     d_key;

    std::ostream   &d_outStream;

    public:
        DecryptBuf(std::ostream &outStream, char const *type, 
                   std::string const &key, std::string const &iv,
                   size_t bufSize = 1024);
        ~DecryptBuf() override;

        bool setRounds(size_t nRounds);             // RC5 8, 12 or 16

        void eoi();                                 // .f

    protected:
        EVP_CIPHER_CTX *cipherCtx();

    private:
        int overflow(int c) override;
        void eoi_() override;                       // .cc

        void flushBuffer();
};

#include "eoi.f"

}   // FBB
        
#endif



