From c38f669e1355856fe95e449825ae0649974ae6ec Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sat, 9 Sep 2023 23:52:57 +0000 Subject: [PATCH] Export base64 encoder and decoder --- include/neatvnc.h | 6 ++++++ src/base64.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/neatvnc.h b/include/neatvnc.h index 4a61124..63ad54b 100644 --- a/include/neatvnc.h +++ b/include/neatvnc.h @@ -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); diff --git a/src/base64.c b/src/base64.c index 8b461dd..8e2f98e 100644 --- a/src/base64.c +++ b/src/base64.c @@ -14,6 +14,7 @@ */ #include "base64.h" +#include "neatvnc.h" #include #include @@ -21,6 +22,8 @@ #include #include +#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); +}