24 #include <openssl/bio.h>
25 #include <openssl/evp.h>
31 class Base64Encode::Impl : boost::noncopyable
35 : m_base64(BIO_new(BIO_f_base64()))
36 , m_sink(BIO_new(BIO_s_mem()))
39 BIO_push(m_base64, m_sink);
44 BIO_free_all(m_base64);
54 : m_impl(make_unique<Impl>())
57 BIO_set_flags(m_impl->m_base64, BIO_FLAGS_BASE64_NO_NL);
63 Base64Encode::preTransform()
69 Base64Encode::convert(span<const uint8_t> data)
74 int wLen = BIO_write(m_impl->m_base64, data.data(), data.size());
77 if (!BIO_should_retry(m_impl->m_base64)) {
90 Base64Encode::finalize()
92 if (BIO_flush(m_impl->m_base64) != 1)
95 while (!isConverterEmpty()) {
104 Base64Encode::fillOutputBuffer()
106 int nRead = BIO_pending(m_impl->m_sink);
111 auto buffer = make_unique<OBuffer>(nRead);
112 int rLen = BIO_read(m_impl->m_sink, buffer->data(), nRead);
117 buffer->erase(buffer->begin() + rLen, buffer->end());
123 Base64Encode::isConverterEmpty()
125 return BIO_pending(m_impl->m_sink) <= 0;
128 unique_ptr<Transform>
131 return make_unique<Base64Encode>(needBreak);