Doug Anson / Base64

Dependents:   GSMandSdWork

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Base64.h Source File

Base64.h

Go to the documentation of this file.
00001 /**
00002  * @file    Base64.h
00003  * @brief   Base64 encoding and decoding header (DERIVED WORK)
00004  * @author  David Smart, Smartware Computing, Doug Anson ARM
00005  * @version 1.0
00006  * @see     
00007  *
00008  * Copyright (c) 2014
00009  *
00010  * Licensed under the Apache License, Version 2.0 (the "License");
00011  * you may not use this file except in compliance with the License.
00012  * You may obtain a copy of the License at
00013  *
00014  *     http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing, software
00017  * distributed under the License is distributed on an "AS IS" BASIS,
00018  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  * See the License for the specific language governing permissions and
00020  * limitations under the License.
00021  *
00022  * @note Copyright © 2013 by Smartware Computing, all rights reserved.
00023  *     Individuals may use this application for evaluation or non-commercial
00024  *     purposes. Within this restriction, changes may be made to this application
00025  *     as long as this copyright notice is retained. The user shall make
00026  *     clear that their work is a derived work, and not the original.
00027  *     Users of this application and sources accept this application "as is" and
00028  *     shall hold harmless Smartware Computing, for any undesired results while
00029  *     using this application - whether real or imagined.
00030  *
00031  * author David Smart, Smartware Computing
00032  */
00033  
00034 #ifndef BASE64_H
00035 #define BASE64_H
00036 
00037 #include "mbed.h"
00038 
00039 /** Base64 encoder and decoder
00040 *
00041 * This class provided both encoding and decoding functions. These functions
00042 * perform dynamic memory allocations to create space for the translated 
00043 * response. It is up to the calling function to free the space when
00044 * done with the translation.
00045 *
00046 * This code was derived from code found online that did not have any 
00047 * copyright or reference to its work.
00048 *
00049 * @code
00050 * Base64 n;
00051 *
00052 * size_t encodedLen;
00053 * char *encoded = n.Encode("This is the message", 20, &encodedLen);
00054 * printf("Encoded message is {%s}\r\n", encoded);
00055 * @endcode
00056 */
00057 class Base64
00058 {
00059 public:
00060     /** Constructor
00061     *
00062     */
00063     Base64();
00064     
00065     /** Destructor
00066     *
00067     * This will release memory that may have been allocated (when the Decode
00068     * function was called).
00069     */
00070     ~Base64();
00071     
00072     /** Encodes a string of information of a defined length
00073     *
00074     * The encoded information is considered a binary stream, therefore a length is provided
00075     * which is used to compute the amount of memory to allocate for the conversion.
00076     * 
00077     * @note The Decode method does not know how you are using it - if it is for text,
00078     *       it will not apply any null termination, unless that was part of the input.
00079     *
00080     * @param data is a pointer to the input binary stream.
00081     * @param input_length is the number of bytes to process.
00082     * @param output_length is a pointer to a size_t value into which is written the
00083     *        number of bytes in the output.
00084     *
00085     * @returns a pointer to the allocated block of memory holding the converted results.
00086     * @returns NULL if something went very wrong.
00087     */
00088     char *Encode(const char *data, size_t input_length, size_t *output_length);
00089     
00090     /** Decodes a base64 encoded stream back into the original information.
00091     *
00092     * The information to decode is considered a base64 encoded stream. A length is
00093     * provided which is used to compute the amount of memory to allocate for the conversion.
00094     *
00095     * @note The Decode method does not know how you are using it - if it is for text,
00096     *       it will not apply any null termination, unless that was part of the input.
00097     *
00098     * @param data is a pointer to the encoded data to decode.
00099     * @param input_length is the number of bytes to process.
00100     * @param output_length is a pointer to a size_t value into which is written the
00101     *        number of bytes in the output.
00102     *
00103     * @returns a pointer to the allocated block of memory holding the converted results.
00104     * @returns NULL if something went very wrong.
00105     */
00106     char *Decode(const char *data, size_t input_length, size_t *output_length);
00107     
00108 private:
00109     void build_decoding_table();
00110     char *decoding_table;
00111 };
00112 
00113 #endif // BASE64_H