24 #include "../detail/openssl-helper.hpp" 26 #include <boost/lexical_cast.hpp> 32 class SignerFilter::Impl
42 const EVP_MD* md = detail::digestAlgorithmToEvpMd(algo);
44 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Unsupported digest algorithm " +
45 boost::lexical_cast<std::string>(algo)));
47 if (EVP_DigestSignInit(m_impl->ctx,
nullptr, md,
nullptr,
48 reinterpret_cast<EVP_PKEY*>(key.getEvpPkey())) != 1)
49 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Failed to initialize signing context with " +
50 boost::lexical_cast<std::string>(algo) +
" digest and " +
51 boost::lexical_cast<std::string>(key.
getKeyType()) +
" key"));
57 SignerFilter::convert(
const uint8_t* buf,
size_t size)
59 if (EVP_DigestSignUpdate(m_impl->ctx, buf, size) != 1)
60 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Failed to accept more input"));
66 SignerFilter::finalize()
69 if (EVP_DigestSignFinal(m_impl->ctx,
nullptr, &sigLen) != 1)
70 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Failed to estimate buffer length"));
72 auto buffer = make_unique<OBuffer>(sigLen);
73 if (EVP_DigestSignFinal(m_impl->ctx, buffer->data(), &sigLen) != 1)
74 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Failed to finalize signature"));
76 buffer->erase(buffer->begin() + sigLen, buffer->end());
85 return make_unique<SignerFilter>(algo, key);
Copyright (c) 2013-2017 Regents of the University of California.
unique_ptr< T > make_unique(Args &&...args)