24 #include <openssl/bio.h>
25 #include <openssl/evp.h>
31 class Base64Decode::Impl : boost::noncopyable
35 : m_base64(BIO_new(BIO_f_base64()))
36 , m_source(BIO_new(BIO_s_mem()))
40 BIO_set_mem_eof_return(m_source, -1);
43 BIO_push(m_base64, m_source);
48 BIO_free_all(m_base64);
58 : m_impl(make_unique<Impl>())
60 if (!expectNewlineEvery64Bytes)
61 BIO_set_flags(m_impl->m_base64, BIO_FLAGS_BASE64_NO_NL);
67 Base64Decode::preTransform()
79 Base64Decode::convert(span<const uint8_t> buf)
81 int wLen = BIO_write(m_impl->m_source, buf.data(), buf.size());
84 if (!BIO_should_retry(m_impl->m_source)) {
96 Base64Decode::finalize()
98 BIO_set_mem_eof_return(m_impl->m_source, 0);
110 Base64Decode::fillOutputBuffer()
114 auto buffer = make_unique<OBuffer>(1024);
115 int rLen = BIO_read(m_impl->m_base64, buffer->data(), buffer->size());
119 if (
static_cast<size_t>(rLen) < buffer->size())
120 buffer->erase(buffer->begin() + rLen, buffer->end());
125 unique_ptr<Transform>
128 return make_unique<Base64Decode>(expectNewlineEvery64Bytes);