~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to third-party/qca/qca/src/botantools/botan/charset.cpp

  • Committer: Package Import Robot
  • Author(s): Jan Niehusmann
  • Date: 2014-07-01 21:49:34 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140701214934-gt4dkgm94byi4vnn
Tags: 0.15-1
* New upstream version
* set debhelper compat level to 9
* set Standards-Version to 3.9.5 (no further changes)
* add lintian override regarding license-problem-non-free-RFC
* use qconf to regenerate configure script
* implement hardening using buildflags instead of hardening-wrapper

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright (C) 1999-2007 The Botan Project. All rights reserved.
3
 
 
4
 
Redistribution and use in source and binary forms, for any use, with or without
5
 
modification, is permitted provided that the following conditions are met:
6
 
 
7
 
1. Redistributions of source code must retain the above copyright notice, this
8
 
list of conditions, and the following disclaimer.
9
 
 
10
 
2. Redistributions in binary form must reproduce the above copyright notice,
11
 
this list of conditions, and the following disclaimer in the documentation
12
 
and/or other materials provided with the distribution.
13
 
 
14
 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED
15
 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
17
 
 
18
 
IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT,
19
 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20
 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22
 
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
 
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
 
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 
*/
26
 
// LICENSEHEADER_END
27
 
namespace QCA { // WRAPNS_LINE
28
 
/*************************************************
29
 
* Character Set Handling Source File             *
30
 
* (C) 1999-2007 The Botan Project                *
31
 
*************************************************/
32
 
 
33
 
} // WRAPNS_LINE
34
 
#include <botan/charset.h>
35
 
namespace QCA { // WRAPNS_LINE
36
 
#ifdef BOTAN_TOOLS_ONLY
37
 
} // WRAPNS_LINE
38
 
#include <botan/exceptn.h>
39
 
namespace QCA { // WRAPNS_LINE
40
 
#else
41
 
} // WRAPNS_LINE
42
 
#include <botan/hex.h>
43
 
namespace QCA { // WRAPNS_LINE
44
 
} // WRAPNS_LINE
45
 
#include <botan/base64.h>
46
 
namespace QCA { // WRAPNS_LINE
47
 
#endif
48
 
} // WRAPNS_LINE
49
 
#include <botan/libstate.h>
50
 
namespace QCA { // WRAPNS_LINE
51
 
} // WRAPNS_LINE
52
 
#include <cctype>
53
 
namespace QCA { // WRAPNS_LINE
54
 
} // WRAPNS_LINE
55
 
#include <ctype.h>
56
 
namespace QCA { // WRAPNS_LINE
57
 
 
58
 
namespace Botan {
59
 
 
60
 
namespace Charset {
61
 
 
62
 
/*************************************************
63
 
* Perform character set transcoding              *
64
 
*************************************************/
65
 
#ifndef BOTAN_TOOLS_ONLY
66
 
std::string transcode(const std::string& str,
67
 
                      Character_Set to, Character_Set from)
68
 
   {
69
 
   return global_state().transcode(str, to, from);
70
 
   }
71
 
#endif
72
 
 
73
 
/*************************************************
74
 
* Check if a character represents a digit        *
75
 
*************************************************/
76
 
bool is_digit(char c)
77
 
   {
78
 
   if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
79
 
      c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
80
 
      return true;
81
 
   return false;
82
 
   }
83
 
 
84
 
/*************************************************
85
 
* Check if a character represents whitespace     *
86
 
*************************************************/
87
 
bool is_space(char c)
88
 
   {
89
 
   if(c == ' ' || c == '\t' || c == '\n' || c == '\r')
90
 
      return true;
91
 
   return false;
92
 
   }
93
 
 
94
 
/*************************************************
95
 
* Convert a character to a digit                 *
96
 
*************************************************/
97
 
byte char2digit(char c)
98
 
   {
99
 
   switch(c)
100
 
      {
101
 
      case '0': return 0;
102
 
      case '1': return 1;
103
 
      case '2': return 2;
104
 
      case '3': return 3;
105
 
      case '4': return 4;
106
 
      case '5': return 5;
107
 
      case '6': return 6;
108
 
      case '7': return 7;
109
 
      case '8': return 8;
110
 
      case '9': return 9;
111
 
      }
112
 
 
113
 
   throw Invalid_Argument("char2digit: Input is not a digit character");
114
 
   }
115
 
 
116
 
/*************************************************
117
 
* Convert a digit to a character                 *
118
 
*************************************************/
119
 
char digit2char(byte b)
120
 
   {
121
 
   switch(b)
122
 
      {
123
 
      case 0: return '0';
124
 
      case 1: return '1';
125
 
      case 2: return '2';
126
 
      case 3: return '3';
127
 
      case 4: return '4';
128
 
      case 5: return '5';
129
 
      case 6: return '6';
130
 
      case 7: return '7';
131
 
      case 8: return '8';
132
 
      case 9: return '9';
133
 
      }
134
 
 
135
 
   throw Invalid_Argument("digit2char: Input is not a digit");
136
 
   }
137
 
 
138
 
/*************************************************
139
 
* Case-insensitive character comparison          *
140
 
*************************************************/
141
 
bool caseless_cmp(char a, char b)
142
 
   {
143
 
   return (tolower((unsigned char)a) == tolower((unsigned char)b));
144
 
   }
145
 
 
146
 
}
147
 
 
148
 
#ifndef BOTAN_TOOLS_ONLY
149
 
 
150
 
/*************************************************
151
 
* Hex Encoder Lookup Tables                      *
152
 
*************************************************/
153
 
const byte Hex_Encoder::BIN_TO_HEX_UPPER[16] = {
154
 
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43,
155
 
0x44, 0x45, 0x46 };
156
 
 
157
 
const byte Hex_Encoder::BIN_TO_HEX_LOWER[16] = {
158
 
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63,
159
 
0x64, 0x65, 0x66 };
160
 
 
161
 
/*************************************************
162
 
* Base64 Encoder Lookup Table                    *
163
 
*************************************************/
164
 
const byte Base64_Encoder::BIN_TO_BASE64[64] = {
165
 
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
166
 
0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
167
 
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D,
168
 
0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,
169
 
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F };
170
 
 
171
 
/*************************************************
172
 
* Hex Decoder Lookup Table                       *
173
 
*************************************************/
174
 
const byte Hex_Decoder::HEX_TO_BIN[256] = {
175
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
176
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
177
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
178
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, 0x02, 0x03,
179
 
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
180
 
0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
181
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
182
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80,
183
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
184
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
185
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
186
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
187
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
188
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
189
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
190
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
191
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
192
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
193
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
194
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
195
 
 
196
 
/*************************************************
197
 
* Base64 Decoder Lookup Table                    *
198
 
*************************************************/
199
 
const byte Base64_Decoder::BASE64_TO_BIN[256] = {
200
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
201
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
202
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
203
 
0x80, 0x80, 0x80, 0x80, 0x3E, 0x80, 0x80, 0x80, 0x3F, 0x34, 0x35, 0x36, 0x37,
204
 
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
205
 
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
206
 
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
207
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
208
 
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
209
 
0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
210
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
211
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
212
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
213
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
214
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
215
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
216
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
217
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
218
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
219
 
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
220
 
 
221
 
#endif
222
 
 
223
 
}
224
 
} // WRAPNS_LINE