13 #include <openssl/buffer.h> 18 void operator()(BIO* bio)
const { BIO_free_all(bio); };
27 std::unique_ptr<BIO, BIODeleter> bio, b64;
28 uint8_t padding = (4 - urlB64message.length() % 4) % 4;
33 std::string b64message(urlB64message.length() + padding, 0);
35 urlB64message.begin(), urlB64message.end(), b64message.begin(),
39 }
else if (
c ==
'_') {
44 for (
auto i = urlB64message.length();
i < urlB64message.length() + padding;
48 return decode(b64message, padding);
52 if (b64message.length() % 4 != 0 || padding >= 3) {
56 std::unique_ptr<BIO, BIODeleter> bio, b64;
57 size_t decodeLen = b64message.length() * 3/4 - padding;
60 bio.reset(BIO_new_mem_buf((
void*)b64message.data(), -1));
64 b64.reset(BIO_new(BIO_f_base64()));
68 bio.reset(BIO_push(b64.release(), bio.release()));
71 BIO_set_flags(bio.get(), BIO_FLAGS_BASE64_NO_NL);
72 BIO_read(bio.get(), (
char*)result.data(), b64message.length());
73 DCHECK_LE(result.length(), decodeLen);
74 if (result.length() < decodeLen) {
81 std::unique_ptr<BIO, BIODeleter> bio, b64;
84 b64.reset(BIO_new(BIO_f_base64()));
86 throw std::bad_alloc();
88 bio.reset(BIO_new(BIO_s_mem()));
90 throw std::bad_alloc();
92 bio.reset(BIO_push(b64.release(), bio.release()));
95 BIO_set_flags(bio.get(), BIO_FLAGS_BASE64_NO_NL);
96 BIO_write(bio.get(), buffer.
data(), buffer.
size());
97 (void)BIO_flush(bio.get());
98 BIO_get_mem_ptr(bio.get(), &bufferPtr);
99 (void)BIO_set_close(bio.get(), BIO_NOCLOSE);
101 std::string result(bufferPtr->data, bufferPtr->length);
102 BUF_MEM_free(bufferPtr);
112 sp.begin(), sp.end(), result.begin(),
116 }
else if (
c ==
'/') {
118 }
else if (
c ==
'=') {
123 DCHECK_LE(padding, result.length());
124 result.resize(result.length() - padding);
std::vector< uint8_t > buffer(kBufferSize+16)
unique_ptr< IOBuf > encode(vector< HPACKHeader > &headers, HPACKEncoder &encoder)
TokenBindingMessage decode(folly::io::Cursor &cursor)
constexpr size_type size() const
PUSHMI_INLINE_VAR constexpr detail::transform_fn transform
constexpr Iter data() const