Export base64 encoder and decoder

pull/100/head
Andri Yngvason 2023-09-09 23:52:57 +00:00
parent 98f6930580
commit c38f669e13
2 changed files with 21 additions and 0 deletions

View File

@ -48,6 +48,9 @@
#define nvnc_trace(...)
#endif
#define NVNC_BASE64_ENCODED_SIZE(x) ((((x) + 2) / 3) * 4 + 1)
#define NVNC_BASE64_DECODED_MAX_SIZE(x) ((((x) + 3) / 4) * 3)
struct nvnc;
struct nvnc_client;
struct nvnc_desktop_layout;
@ -237,3 +240,6 @@ void nvnc_set_cursor(struct nvnc*, struct nvnc_fb*, uint16_t width,
void nvnc_set_log_fn(nvnc_log_fn);
void nvnc_set_log_level(enum nvnc_log_level);
void nvnc__log(const struct nvnc_log_data*, const char* fmt, ...);
void nvnc_base64_encode(char* dst, const uint8_t* src, size_t src_len);
ssize_t nvnc_base64_decode(uint8_t* dst, const char* src);

View File

@ -14,6 +14,7 @@
*/
#include "base64.h"
#include "neatvnc.h"
#include <unistd.h>
#include <stdint.h>
@ -21,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
#define EXPORT __attribute__((visibility("default")))
static const char base64_enc_lut[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@ -153,3 +156,15 @@ ssize_t base64_decode(uint8_t* dst, const char* src)
return i * 3 + di;
}
EXPORT
void nvnc_base64_encode(char* dst, const uint8_t* src, size_t src_len)
{
base64_encode(dst, src, src_len);
}
EXPORT
ssize_t nvnc_base64_decode(uint8_t* dst, const char* src)
{
return base64_decode(dst, src);
}