codex
Loading...
Searching...
No Matches
adaptor.hpp
Go to the documentation of this file.
1#ifndef CODEX_BASE64_RFC_ADAPTER_H
2#define CODEX_BASE64_RFC_ADAPTER_H
3
4#include <string_view>
5
6extern "C" {
7#include "base64.h"
8}
9
13struct Base64RFC {
14 static void encode(std::string_view src, char *out);
15 static char *decode(std::string_view src, char *out);
16};
17
18inline void Base64RFC::encode(std::string_view src, char *out) {
20 src.data(), src.size(),
21 out, output_size<4, 3>(src.size()));
22}
23
24inline char *Base64RFC::decode(std::string_view src, char *out) {
25 std::size_t ret = output_size<3, 4>(src.size());
26 if(!base64_decode(src.data(), src.size(), out, &ret))
27 return nullptr;
28 return out + ret;
29}
30
31#endif
constexpr std::size_t output_size(std::size_t n)
Calculates the size of the buffer required for the output, rounding up.
Definition cmd.hpp:48
bool base64_decode(const char *in, size_t inlen, char *out, size_t *outlen)
Definition base64.c:301
void base64_encode(const char *in, size_t inlen, char *out, size_t outlen)
Definition base64.c:68
Adaptor for EncodeFunc and DecodeFunc for the RFC implementation.
Definition adaptor.hpp:13
static char * decode(std::string_view src, char *out)
Definition adaptor.hpp:24
static void encode(std::string_view src, char *out)
Definition adaptor.hpp:18