23 #include "ndn-cxx/security/impl/openssl-helper.hpp" 25 #include <boost/lexical_cast.hpp> 31 class HmacFilter::Impl
51 : m_impl(make_unique<Impl>())
53 BOOST_ASSERT(key !=
nullptr);
54 BOOST_ASSERT(keyLen > 0);
56 const EVP_MD* md = detail::digestAlgorithmToEvpMd(algo);
60 m_impl->key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC,
nullptr, key, static_cast<int>(keyLen));
61 if (m_impl->key ==
nullptr)
64 if (EVP_DigestSignInit(m_impl->ctx,
nullptr, md,
nullptr, m_impl->key) != 1)
66 boost::lexical_cast<std::string>(algo) +
" digest"));
72 HmacFilter::convert(
const uint8_t* buf,
size_t size)
74 if (EVP_DigestSignUpdate(m_impl->ctx, buf, size) != 1)
81 HmacFilter::finalize()
83 auto buffer = make_unique<OBuffer>(EVP_MAX_MD_SIZE);
86 if (EVP_DigestSignFinal(m_impl->ctx, buffer->data(), &hmacLen) != 1)
89 buffer->erase(buffer->begin() + hmacLen, buffer->end());
98 return make_unique<HmacFilter>(algo, key, keyLen);