24 #include <openssl/bio.h>
25 #include <openssl/evp.h>
29 class Base64Decode::Impl : boost::noncopyable
33 : m_base64(BIO_new(BIO_f_base64()))
34 , m_source(BIO_new(BIO_s_mem()))
38 BIO_set_mem_eof_return(m_source, -1);
41 BIO_push(m_base64, m_source);
46 BIO_free_all(m_base64);
56 : m_impl(make_unique<Impl>())
58 if (!expectNewlineEvery64Bytes)
59 BIO_set_flags(m_impl->m_base64, BIO_FLAGS_BASE64_NO_NL);
65 Base64Decode::preTransform()
77 Base64Decode::convert(span<const uint8_t> buf)
79 int wLen = BIO_write(m_impl->m_source, buf.data(), buf.size());
82 if (!BIO_should_retry(m_impl->m_source)) {
94 Base64Decode::finalize()
96 BIO_set_mem_eof_return(m_impl->m_source, 0);
108 Base64Decode::fillOutputBuffer()
112 auto buffer = make_unique<OBuffer>(1024);
113 int rLen = BIO_read(m_impl->m_base64, buffer->data(), buffer->size());
117 if (
static_cast<size_t>(rLen) < buffer->size())
118 buffer->erase(buffer->begin() + rLen, buffer->end());
123 unique_ptr<Transform>
126 return make_unique<Base64Decode>(expectNewlineEvery64Bytes);