#ifndef INCLUDED_BOBCAT_DIGESTBUF_
#define INCLUDED_BOBCAT_DIGESTBUF_

#include <openssl/evp.h>
#include <bobcat/eoibuf>

#include <bobcat/exception>

namespace FBB
{

class DigestBuf: public EoiBuf
{
    friend std::ostream &operator<<(std::ostream &out,
                                    DigestBuf const &digestbuf);
    EVP_MD_CTX   *d_ctx;
    EVP_MD const *d_md;
    std::string   d_digest;

    public:
        explicit DigestBuf(char const *digestName, size_t bufsize = 1024);

        void reset();
        void eoi();

        std::string const &hash() const;

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

inline void DigestBuf::eoi()
{
    eoi_();
}

std::ostream &operator<<(std::ostream &out, DigestBuf const &digestbuf);

}   // FBB

#endif
