Botan  1.11.15
src/lib/codec/hex/hex.h
Go to the documentation of this file.
00001 /*
00002 * Hex Encoding and Decoding
00003 * (C) 2010 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_HEX_CODEC_H__
00009 #define BOTAN_HEX_CODEC_H__
00010 
00011 #include <botan/secmem.h>
00012 #include <string>
00013 
00014 namespace Botan {
00015 
00016 /**
00017 * Perform hex encoding
00018 * @param output an array of at least input_length*2 bytes
00019 * @param input is some binary data
00020 * @param input_length length of input in bytes
00021 * @param uppercase should output be upper or lower case?
00022 */
00023 void BOTAN_DLL hex_encode(char output[],
00024                           const byte input[],
00025                           size_t input_length,
00026                           bool uppercase = true);
00027 
00028 /**
00029 * Perform hex encoding
00030 * @param input some input
00031 * @param input_length length of input in bytes
00032 * @param uppercase should output be upper or lower case?
00033 * @return hexadecimal representation of input
00034 */
00035 std::string BOTAN_DLL hex_encode(const byte input[],
00036                                  size_t input_length,
00037                                  bool uppercase = true);
00038 
00039 /**
00040 * Perform hex encoding
00041 * @param input some input
00042 * @param uppercase should output be upper or lower case?
00043 * @return hexadecimal representation of input
00044 */
00045 template<typename Alloc>
00046 std::string hex_encode(const std::vector<byte, Alloc>& input,
00047                        bool uppercase = true)
00048    {
00049    return hex_encode(&input[0], input.size(), uppercase);
00050    }
00051 
00052 /**
00053 * Perform hex decoding
00054 * @param output an array of at least input_length/2 bytes
00055 * @param input some hex input
00056 * @param input_length length of input in bytes
00057 * @param input_consumed is an output parameter which says how many
00058 *        bytes of input were actually consumed. If less than
00059 *        input_length, then the range input[consumed:length]
00060 *        should be passed in later along with more input.
00061 * @param ignore_ws ignore whitespace on input; if false, throw an
00062                    exception if whitespace is encountered
00063 * @return number of bytes written to output
00064 */
00065 size_t BOTAN_DLL hex_decode(byte output[],
00066                             const char input[],
00067                             size_t input_length,
00068                             size_t& input_consumed,
00069                             bool ignore_ws = true);
00070 
00071 /**
00072 * Perform hex decoding
00073 * @param output an array of at least input_length/2 bytes
00074 * @param input some hex input
00075 * @param input_length length of input in bytes
00076 * @param ignore_ws ignore whitespace on input; if false, throw an
00077                    exception if whitespace is encountered
00078 * @return number of bytes written to output
00079 */
00080 size_t BOTAN_DLL hex_decode(byte output[],
00081                             const char input[],
00082                             size_t input_length,
00083                             bool ignore_ws = true);
00084 
00085 /**
00086 * Perform hex decoding
00087 * @param output an array of at least input_length/2 bytes
00088 * @param input some hex input
00089 * @param ignore_ws ignore whitespace on input; if false, throw an
00090                    exception if whitespace is encountered
00091 * @return number of bytes written to output
00092 */
00093 size_t BOTAN_DLL hex_decode(byte output[],
00094                             const std::string& input,
00095                             bool ignore_ws = true);
00096 
00097 /**
00098 * Perform hex decoding
00099 * @param input some hex input
00100 * @param input_length the length of input in bytes
00101 * @param ignore_ws ignore whitespace on input; if false, throw an
00102                    exception if whitespace is encountered
00103 * @return decoded hex output
00104 */
00105 std::vector<byte> BOTAN_DLL
00106 hex_decode(const char input[],
00107            size_t input_length,
00108            bool ignore_ws = true);
00109 
00110 /**
00111 * Perform hex decoding
00112 * @param input some hex input
00113 * @param ignore_ws ignore whitespace on input; if false, throw an
00114                    exception if whitespace is encountered
00115 * @return decoded hex output
00116 */
00117 std::vector<byte> BOTAN_DLL
00118 hex_decode(const std::string& input,
00119            bool ignore_ws = true);
00120 
00121 
00122 /**
00123 * Perform hex decoding
00124 * @param input some hex input
00125 * @param input_length the length of input in bytes
00126 * @param ignore_ws ignore whitespace on input; if false, throw an
00127                    exception if whitespace is encountered
00128 * @return decoded hex output
00129 */
00130 secure_vector<byte> BOTAN_DLL
00131 hex_decode_locked(const char input[],
00132                   size_t input_length,
00133                   bool ignore_ws = true);
00134 
00135 /**
00136 * Perform hex decoding
00137 * @param input some hex input
00138 * @param ignore_ws ignore whitespace on input; if false, throw an
00139                    exception if whitespace is encountered
00140 * @return decoded hex output
00141 */
00142 secure_vector<byte> BOTAN_DLL
00143 hex_decode_locked(const std::string& input,
00144                   bool ignore_ws = true);
00145 
00146 }
00147 
00148 #endif