Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SW_HTTPServer by
Diff: Base64.h
- Revision:
- 13:8975d7928678
- Parent:
- 12:109bf1558300
- Child:
- 14:19c5f6151319
--- a/Base64.h Sun Aug 11 15:49:51 2013 +0000
+++ b/Base64.h Mon Aug 12 11:26:59 2013 +0000
@@ -1,13 +1,79 @@
+#ifndef BASE64_H
+#define BASE64_H
+#include "mbed.h"
+/** Base64 encoder and decoder
+*
+* This class provided both encoding and decoding functions. These functions
+* perform dynamic memory allocations to create space for the translated
+* response. It is up to the calling function to free the space when
+* done with the translation.
+*
+* This code was derived from code found online that did not have any
+* copyright or reference to its work.
+*
+* @code
+* Base64 n();
+*
+* size_t encodedLen;
+* char *encoded = n.Encode("This is the message", 20, &encodedLen);
+*
+*/
class Base64
{
public:
+ /** Constructor
+ *
+ */
Base64();
+
+ /** Destructor
+ *
+ * This will release memory that may have been allocated (when the Decode
+ * function is called).
+ */
~Base64();
- char *base64_encode(const unsigned char *data, size_t input_length, size_t *output_length);
- unsigned char *base64_decode(const char *data, size_t input_length, size_t *output_length);
+
+ /** Encodes a string of information of a defined length
+ *
+ * The encoded information is considered a binary stream, therefore a length is provided
+ * which is used to compute the amount of memory to allocate for the conversion.
+ *
+ * @note The Decode method does not know how you are using it - if it is for text,
+ * it will not apply any null termination, unless that was part of the input.
+ *
+ * @param data is a pointer to the input binary stream.
+ * @param input_length is the number of bytes to process.
+ * @param output_length is a pointer to a size_t value into which is written the
+ * number of bytes in the output.
+ *
+ * @returns a pointer to the allocated block of memory holding the converted results.
+ * @returns NULL if something went very wrong.
+ */
+ char *Encode(const char *data, size_t input_length, size_t *output_length);
+
+ /** Decodes a base64 encoded stream back into the original information.
+ *
+ * The information to decode is considered a base64 encoded stream. A length is
+ * provided which is used to compute the amount of memory to allocate for the conversion.
+ *
+ * @note The Decode method does not know how you are using it - if it is for text,
+ * it will not apply any null termination, unless that was part of the input.
+ *
+ * @param data is a pointer to the encoded data to decode.
+ * @param input_length is the number of bytes to process.
+ * @param output_length is a pointer to a size_t value into which is written the
+ * number of bytes in the output.
+ *
+ * @returns a pointer to the allocated block of memory holding the converted results.
+ * @returns NULL if something went very wrong.
+ */
+ char *Decode(const char *data, size_t input_length, size_t *output_length);
+
private:
void build_decoding_table();
char *decoding_table;
-};
\ No newline at end of file
+};
+
+#endif // BASE64_H
\ No newline at end of file
