summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/base64.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cpukit/include/rtems/base64.h (renamed from cpukit/include/rtems/score/io.h)114
1 files changed, 81 insertions, 33 deletions
diff --git a/cpukit/include/rtems/score/io.h b/cpukit/include/rtems/base64.h
index 9cd401eb1d..58e48a8c33 100644
--- a/cpukit/include/rtems/score/io.h
+++ b/cpukit/include/rtems/base64.h
@@ -3,14 +3,14 @@
/**
* @file
*
- * @ingroup RTEMSScoreIO
+ * @ingroup RTEMSImplBase64
*
* @brief This header file provides the interfaces of the
- * @ref RTEMSScoreIO.
+ * @ref RTEMSImplBase64.
*/
/*
- * Copyright (c) 2017 embedded brains GmbH & Co. KG
+ * Copyright (C) 2020, 2024 embedded brains GmbH & Co. KG
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -34,42 +34,35 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _RTEMS_SCORE_IO_H
-#define _RTEMS_SCORE_IO_H
+#ifndef _RTEMS_BASE64_H
+#define _RTEMS_BASE64_H
-#include <rtems/score/basedefs.h>
-
-#include <stdarg.h>
+#include <rtems/dev/io.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
- * @defgroup RTEMSScoreIO IO Handler
+ * @defgroup RTEMSImplBase64 Base64 Encoding and Decoding
*
- * @ingroup RTEMSScore
+ * @ingroup RTEMSImpl
*
- * @brief This group contains the IO Handler implementation.
+ * @brief This group contains support functions for base64 and base64url
+ * encoding and decoding.
*
* @{
*/
-typedef void ( *IO_Put_char )( int c, void *arg );
-
-int _IO_Printf(
- IO_Put_char put_char,
- void *arg,
- char const *fmt,
- ...
-) RTEMS_PRINTFLIKE( 3, 4 );
+/**
+ * @brief Maps a 6-bit integer to the corresponding base64 encoding.
+ */
+extern const uint8_t _Base64_Encoding[ 64 ];
-int _IO_Vprintf(
- IO_Put_char put_char,
- void *arg,
- char const *fmt,
- va_list ap
-);
+/**
+ * @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.
@@ -93,7 +86,7 @@ int _IO_Vprintf(
*
* @return Returns the count of output characters.
*/
-int _IO_Base64(
+int _Base64_Encode(
IO_Put_char put_char,
void *arg,
const void *src,
@@ -124,7 +117,7 @@ int _IO_Base64(
*
* @return Returns the count of output characters.
*/
-int _IO_Base64url(
+int _Base64url_Encode(
IO_Put_char put_char,
void *arg,
const void *src,
@@ -134,17 +127,72 @@ int _IO_Base64url(
);
/**
- * @brief Issues a couple of no-operation instructions.
+ * @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.
*
- * This function may be used to burn a couple of processor cycles with minimum
- * impact on the system bus. It may be used in busy wait loops.
+ * @param[in, out] self is the base64 decoder control.
+ *
+ * @param ch is the character to decode.
*/
-void _IO_Relax( void );
+Base64_Decode_status _Base64_Decode(
+ Base64_Decode_control *self,
+ char ch
+);
-/** @} */
+/** @} */
#ifdef __cplusplus
}
#endif /* __cplusplus */
-#endif /* _RTEMS_SCORE_IO_H */
+#endif /* _RTEMS_BASE64_H */