summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/base64.h
diff options
context:
space:
mode:
authorMatthew Joyce <matthew.joyce@embedded-brains.de>2023-08-09 08:19:51 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2024-02-16 09:32:04 +0100
commit2757b360985f4878ace8838ca24eac6c1a6585d3 (patch)
tree3cefcdeb29f7d9335fa13e747d7bfcd66c68cad4 /cpukit/include/rtems/base64.h
parentbase64: Make base64 encoding tables public (diff)
downloadrtems-2757b360985f4878ace8838ca24eac6c1a6585d3.tar.bz2
base64: Add decoder
Diffstat (limited to '')
-rw-r--r--cpukit/include/rtems/base64.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/cpukit/include/rtems/base64.h b/cpukit/include/rtems/base64.h
index b9d88f7818..58e48a8c33 100644
--- a/cpukit/include/rtems/base64.h
+++ b/cpukit/include/rtems/base64.h
@@ -126,6 +126,69 @@ int _Base64url_Encode(
int wordlen
);
+/**
+ * @brief Represents the base64 and base64url decoder state.
+ */
+typedef enum {
+ BASE64_DECODE_STATE_0,
+ BASE64_DECODE_STATE_1,
+ BASE64_DECODE_STATE_2,
+ BASE64_DECODE_STATE_3
+} Base64_Decode_state;
+
+/**
+ * @brief Contains the base64 and base64url decoder control.
+ */
+typedef struct {
+ Base64_Decode_state state;
+ uint8_t *target;
+ const uint8_t *target_end;
+} Base64_Decode_control;
+
+/**
+ * @brief Maps a 7-bit character to the associated 6-bit integer as defined by
+ * the base64 or base64url encoding or a special value.
+ */
+extern const uint8_t _Base64_Decoding[ 128 ];
+
+/**
+ * @brief Initializes the base64 decoder.
+ *
+ * @param[out] self is the base64 decoder control to initialize.
+ *
+ * @param[out] target is the base address of the target area for decoding.
+ *
+ * @param target_size is the size in bytes of the target area for decoding.
+ */
+void _Base64_Decode_initialize(
+ Base64_Decode_control *self,
+ uint8_t *target,
+ size_t target_size
+);
+
+/**
+ * @brief Represents the base64 and base64url decoder status.
+ */
+typedef enum {
+ BASE64_DECODE_SUCCESS,
+ BASE64_DECODE_OVERFLOW,
+ BASE64_DECODE_INVALID_INPUT
+} Base64_Decode_status;
+
+/**
+ * @brief Decodes the character.
+ *
+ * The decoder accepts base64 and base64url encodings. White space is ignored.
+ *
+ * @param[in, out] self is the base64 decoder control.
+ *
+ * @param ch is the character to decode.
+ */
+Base64_Decode_status _Base64_Decode(
+ Base64_Decode_control *self,
+ char ch
+);
+
/** @} */
#ifdef __cplusplus