00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 namespace QCA {
00028
00029
00030
00031
00032
00033 }
00034 #include <botan/charset.h>
00035 namespace QCA {
00036 #ifdef BOTAN_TOOLS_ONLY
00037 }
00038 #include <botan/exceptn.h>
00039 namespace QCA {
00040 #else
00041 }
00042 #include <botan/hex.h>
00043 namespace QCA {
00044 }
00045 #include <botan/base64.h>
00046 namespace QCA {
00047 #endif
00048 }
00049 #include <botan/libstate.h>
00050 namespace QCA {
00051 }
00052 #include <cctype>
00053 namespace QCA {
00054 }
00055 #include <ctype.h>
00056 namespace QCA {
00057
00058 namespace Botan {
00059
00060 namespace Charset {
00061
00062
00063
00064
00065 #ifndef BOTAN_TOOLS_ONLY
00066 std::string transcode(const std::string& str,
00067 Character_Set to, Character_Set from)
00068 {
00069 return global_state().transcode(str, to, from);
00070 }
00071 #endif
00072
00073
00074
00075
00076 bool is_digit(char c)
00077 {
00078 if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
00079 c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
00080 return true;
00081 return false;
00082 }
00083
00084
00085
00086
00087 bool is_space(char c)
00088 {
00089 if(c == ' ' || c == '\t' || c == '\n' || c == '\r')
00090 return true;
00091 return false;
00092 }
00093
00094
00095
00096
00097 byte char2digit(char c)
00098 {
00099 switch(c)
00100 {
00101 case '0': return 0;
00102 case '1': return 1;
00103 case '2': return 2;
00104 case '3': return 3;
00105 case '4': return 4;
00106 case '5': return 5;
00107 case '6': return 6;
00108 case '7': return 7;
00109 case '8': return 8;
00110 case '9': return 9;
00111 }
00112
00113 throw Invalid_Argument("char2digit: Input is not a digit character");
00114 }
00115
00116
00117
00118
00119 char digit2char(byte b)
00120 {
00121 switch(b)
00122 {
00123 case 0: return '0';
00124 case 1: return '1';
00125 case 2: return '2';
00126 case 3: return '3';
00127 case 4: return '4';
00128 case 5: return '5';
00129 case 6: return '6';
00130 case 7: return '7';
00131 case 8: return '8';
00132 case 9: return '9';
00133 }
00134
00135 throw Invalid_Argument("digit2char: Input is not a digit");
00136 }
00137
00138
00139
00140
00141 bool caseless_cmp(char a, char b)
00142 {
00143 return (tolower((unsigned char)a) == tolower((unsigned char)b));
00144 }
00145
00146 }
00147
00148 #ifndef BOTAN_TOOLS_ONLY
00149
00150
00151
00152
00153 const byte Hex_Encoder::BIN_TO_HEX_UPPER[16] = {
00154 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43,
00155 0x44, 0x45, 0x46 };
00156
00157 const byte Hex_Encoder::BIN_TO_HEX_LOWER[16] = {
00158 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63,
00159 0x64, 0x65, 0x66 };
00160
00161
00162
00163
00164 const byte Base64_Encoder::BIN_TO_BASE64[64] = {
00165 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
00166 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
00167 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D,
00168 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,
00169 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F };
00170
00171
00172
00173
00174 const byte Hex_Decoder::HEX_TO_BIN[256] = {
00175 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00176 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00177 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00178 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, 0x02, 0x03,
00179 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00180 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00181 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00182 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80,
00183 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00184 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00185 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00186 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00187 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00188 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00189 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00190 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00191 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00192 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00193 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00194 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
00195
00196
00197
00198
00199 const byte Base64_Decoder::BASE64_TO_BIN[256] = {
00200 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00201 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00202 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00203 0x80, 0x80, 0x80, 0x80, 0x3E, 0x80, 0x80, 0x80, 0x3F, 0x34, 0x35, 0x36, 0x37,
00204 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00205 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
00206 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
00207 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
00208 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
00209 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00210 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00211 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00212 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00213 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00214 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00215 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00216 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00217 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00218 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
00219 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
00220
00221 #endif
00222
00223 }
00224 }