diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-12-11 10:47:45 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2024-02-16 09:32:04 +0100 |
commit | c90e2b2fb2a2cafd8fe5fe50312ffed8cd555c48 (patch) | |
tree | 0aaacf44ec620afc093f9d60799e692ff2880c8e | |
parent | base64: Move base64 encoding support (diff) | |
download | rtems-c90e2b2fb2a2cafd8fe5fe50312ffed8cd555c48.tar.bz2 |
base64: Make base64 encoding tables public
This makes them reusable. Change the character type to uint8_t.
-rw-r--r-- | cpukit/base64/base64-encode.c | 24 | ||||
-rw-r--r-- | cpukit/include/rtems/base64.h | 10 |
2 files changed, 27 insertions, 7 deletions
diff --git a/cpukit/base64/base64-encode.c b/cpukit/base64/base64-encode.c index e72657cc5f..0110f3ff67 100644 --- a/cpukit/base64/base64-encode.c +++ b/cpukit/base64/base64-encode.c @@ -37,7 +37,7 @@ _Base64_Put(int c, void *arg, IO_Put_char put_char) static int _Base64_Do_encode(IO_Put_char put_char, void *arg, const void *src, - size_t srclen, const char *wordbreak, int wordlen, const char *encoding) + size_t srclen, const char *wordbreak, int wordlen, const uint8_t *encoding) { unsigned int loops = 0; const unsigned char *in = src; @@ -88,24 +88,34 @@ _Base64_Do_encode(IO_Put_char put_char, void *arg, const void *src, return out; } -static const char base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; +const uint8_t _Base64_Encoding[64] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '+', '/' +}; int _Base64_Encode(IO_Put_char put_char, void *arg, const void *src, size_t srclen, const char *wordbreak, int wordlen) { return _Base64_Do_encode(put_char, arg, src, srclen, wordbreak, - wordlen, base64); + wordlen, _Base64_Encoding); } -static const char base64url[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="; +const uint8_t _Base64url_Encoding[64] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '-', '_' +}; int _Base64url_Encode(IO_Put_char put_char, void *arg, const void *src, size_t srclen, const char *wordbreak, int wordlen) { return _Base64_Do_encode(put_char, arg, src, srclen, wordbreak, - wordlen, base64url); + wordlen, _Base64url_Encoding); } diff --git a/cpukit/include/rtems/base64.h b/cpukit/include/rtems/base64.h index 10c1e50840..b9d88f7818 100644 --- a/cpukit/include/rtems/base64.h +++ b/cpukit/include/rtems/base64.h @@ -55,6 +55,16 @@ extern "C" { */ /** + * @brief Maps a 6-bit integer to the corresponding base64 encoding. + */ +extern const uint8_t _Base64_Encoding[ 64 ]; + +/** + * @brief Maps a 6-bit integer to the corresponding base64url encoding. + */ +extern const uint8_t _Base64url_Encoding[ 64 ]; + +/** * @brief Outputs the source buffer in base64 encoding. * * After word length of output characters produced by the encoding a word break |