23 #include "../detail/openssl-helper.hpp" 25 #include <boost/lexical_cast.hpp> 31 class DigestFilter::Impl
41 const EVP_MD* md = detail::digestAlgorithmToEvpMd(algo);
43 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Unsupported digest algorithm " +
44 boost::lexical_cast<std::string>(algo)));
46 if (EVP_DigestInit_ex(m_impl->ctx, md,
nullptr) == 0)
47 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Cannot initialize digest " +
48 boost::lexical_cast<std::string>(algo)));
54 DigestFilter::convert(
const uint8_t* buf,
size_t size)
56 if (EVP_DigestUpdate(m_impl->ctx, buf, size) == 0)
57 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Failed to accept more input"));
63 DigestFilter::finalize()
65 auto buffer = make_unique<OBuffer>(EVP_MAX_MD_SIZE);
66 unsigned int mdLen = 0;
68 if (EVP_DigestFinal_ex(m_impl->ctx, buffer->data(), &mdLen) == 0)
69 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Failed to finalize digest"));
71 buffer->erase(buffer->begin() + mdLen, buffer->end());
80 return make_unique<DigestFilter>(algo);
Copyright (c) 2013-2017 Regents of the University of California.
unique_ptr< T > make_unique(Args &&...args)