23 #include "../../encoding/buffer.hpp"
24 #include "../detail/openssl.hpp"
35 ,
m_md(BIO_new(BIO_f_md()))
36 ,
m_sink(BIO_new(BIO_s_null()))
54 : m_impl(new
Impl(key))
58 if (!BIO_set_md(m_impl->m_md, EVP_sha256()))
59 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Cannot set digest"));
64 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Digest algorithm is not supported"));
69 SignerFilter::convert(
const uint8_t* buf,
size_t size)
71 int wLen = BIO_write(m_impl->m_md, buf, size);
74 if (!BIO_should_retry(m_impl->m_md)) {
76 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Failed to accept more input"));
86 SignerFilter::finalize()
88 EVP_PKEY* key =
reinterpret_cast<EVP_PKEY*
>(m_impl->m_key.getEvpPkey());
89 auto buffer = make_unique<OBuffer>(EVP_PKEY_size(key));
90 unsigned int sigLen = 0;
92 EVP_MD_CTX* ctx =
nullptr;
93 BIO_get_md_ctx(m_impl->m_md, &ctx);
94 EVP_SignFinal(ctx, &(*buffer)[0], &sigLen, key);
96 buffer->erase(buffer->begin() + sigLen, buffer->end());
102 unique_ptr<Transform>
105 return make_unique<SignerFilter>(algo, key);
Copyright (c) 2013-2016 Regents of the University of California.
Use the SHA256 hash of the public key as the key id.