Diffstat (limited to 'frontend/gamma/js/Clipperz/ByteArray.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/ByteArray.js | 71 |
1 files changed, 16 insertions, 55 deletions
diff --git a/frontend/gamma/js/Clipperz/ByteArray.js b/frontend/gamma/js/Clipperz/ByteArray.js index ae586e7..22c7c6e 100644 --- a/frontend/gamma/js/Clipperz/ByteArray.js +++ b/frontend/gamma/js/Clipperz/ByteArray.js | |||
@@ -1,216 +1,199 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | 25 | ||
28 | //============================================================================= | 26 | //============================================================================= |
29 | 27 | ||
30 | Clipperz.ByteArray_abstract = function(args) { | 28 | Clipperz.ByteArray_abstract = function(args) { |
31 | return this; | 29 | return this; |
32 | } | 30 | } |
33 | 31 | ||
34 | Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | 32 | Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { |
35 | 33 | ||
36 | //------------------------------------------------------------------------- | 34 | //------------------------------------------------------------------------- |
37 | 35 | ||
38 | 'toString': function() { | 36 | 'toString': function() { |
39 | return "Clipperz.ByteArray_abstract"; | 37 | return "Clipperz.ByteArray_abstract"; |
40 | }, | 38 | }, |
41 | 39 | ||
42 | //------------------------------------------------------------------------- | 40 | //------------------------------------------------------------------------- |
43 | 41 | ||
44 | 'equals': function(aValue) { | 42 | 'equals': function(aValue) { |
45 | return (this.compare(aValue) == 0); | 43 | return (this.compare(aValue) == 0); |
46 | }, | 44 | }, |
47 | 45 | ||
48 | //------------------------------------------------------------------------- | 46 | //------------------------------------------------------------------------- |
49 | 47 | ||
50 | 'compare': function(aValue) { | 48 | 'compare': function(aValue) { |
51 | var result; | 49 | var result; |
52 | var i; | 50 | var i; |
53 | 51 | ||
54 | result = MochiKit.Base.compare(this.length(), aValue.length()); | 52 | result = MochiKit.Base.compare(this.length(), aValue.length()); |
55 | i = this.length(); | 53 | i = this.length(); |
56 | 54 | ||
57 | while ((result == 0) && (i>0)) { | 55 | while ((result == 0) && (i>0)) { |
58 | i--; | 56 | i--; |
59 | result = MochiKit.Base.compare(this.byteAtIndex(i), aValue.byteAtIndex(i)); | 57 | result = MochiKit.Base.compare(this.byteAtIndex(i), aValue.byteAtIndex(i)); |
60 | } | 58 | } |
61 | 59 | ||
62 | return result; | 60 | return result; |
63 | }, | 61 | }, |
64 | 62 | ||
65 | //------------------------------------------------------------------------- | 63 | //------------------------------------------------------------------------- |
66 | 64 | ||
67 | 'clone': function() { | 65 | 'clone': function() { |
68 | throw Clipperz.Base.exception.AbstractMethod; | 66 | throw Clipperz.Base.exception.AbstractMethod; |
69 | }, | 67 | }, |
70 | 68 | ||
71 | //------------------------------------------------------------------------- | 69 | //------------------------------------------------------------------------- |
72 | 70 | ||
73 | 'newInstance': function() { | 71 | 'newInstance': function() { |
74 | throw Clipperz.Base.exception.AbstractMethod; | 72 | throw Clipperz.Base.exception.AbstractMethod; |
75 | }, | 73 | }, |
76 | 74 | ||
77 | //------------------------------------------------------------------------- | 75 | //------------------------------------------------------------------------- |
78 | 76 | ||
79 | 'reset': function() { | 77 | 'reset': function() { |
80 | throw Clipperz.Base.exception.AbstractMethod; | 78 | throw Clipperz.Base.exception.AbstractMethod; |
81 | }, | 79 | }, |
82 | 80 | ||
83 | //------------------------------------------------------------------------- | 81 | //------------------------------------------------------------------------- |
84 | 82 | ||
85 | 'length': function() { | 83 | 'length': function() { |
86 | throw Clipperz.Base.exception.AbstractMethod; | 84 | throw Clipperz.Base.exception.AbstractMethod; |
87 | }, | 85 | }, |
88 | 86 | ||
89 | //------------------------------------------------------------------------- | 87 | //------------------------------------------------------------------------- |
90 | 88 | ||
91 | 'checkByteValue': function(aValue) { | 89 | 'checkByteValue': function(aValue) { |
92 | //Clipperz.log("aValue", aValue.toString(16)); | ||
93 | //Clipperz.log("(aValue & 0xff)", (aValue & 0xff).toString(16)); | ||
94 | |||
95 | if ((aValue & 0xff) != aValue) { | 90 | if ((aValue & 0xff) != aValue) { |
96 | MochiKit.Logging.logError("Clipperz.ByteArray.appendByte: the provided value (0x" + aValue.toString(16) + ") is not a byte value."); | 91 | Clipperz.logError("Clipperz.ByteArray.appendByte: the provided value (0x" + aValue.toString(16) + ") is not a byte value."); |
97 | throw Clipperz.ByteArray.exception.InvalidValue; | 92 | throw Clipperz.ByteArray.exception.InvalidValue; |
98 | } | 93 | } |
99 | }, | 94 | }, |
100 | 95 | ||
101 | //------------------------------------------------------------------------- | 96 | //------------------------------------------------------------------------- |
102 | 97 | ||
103 | 'xorMergeWithBlock': function(aBlock, anAllignment, paddingMode) { | 98 | 'xorMergeWithBlock': function(aBlock, anAllignment, paddingMode) { |
104 | var result; | 99 | var result; |
105 | var a, b; | 100 | var a, b; |
106 | var aLength; | 101 | var aLength; |
107 | var bLength; | 102 | var bLength; |
108 | var i, c; | 103 | var i, c; |
109 | 104 | ||
110 | if (this.length() > aBlock.length()) { | 105 | if (this.length() > aBlock.length()) { |
111 | a = this; | 106 | a = this; |
112 | b = aBlock; | 107 | b = aBlock; |
113 | } else { | 108 | } else { |
114 | a = aBlock; | 109 | a = aBlock; |
115 | b = this; | 110 | b = this; |
116 | } | 111 | } |
117 | 112 | ||
118 | aLength = a.length(); | 113 | aLength = a.length(); |
119 | bLength = b.length(); | 114 | bLength = b.length(); |
120 | 115 | ||
121 | if (aLength != bLength) { | 116 | if (aLength != bLength) { |
122 | if (paddingMode == 'truncate') { | 117 | if (paddingMode == 'truncate') { |
123 | if (anAllignment == 'left') { | 118 | if (anAllignment == 'left') { |
124 | a = a.split(0, bLength); | 119 | a = a.split(0, bLength); |
125 | } else { | 120 | } else { |
126 | a = a.split(aLength - bLength); | 121 | a = a.split(aLength - bLength); |
127 | } | 122 | } |
128 | } else { | 123 | } else { |
129 | var ii, cc; | 124 | var ii, cc; |
130 | var padding; | 125 | var padding; |
131 | 126 | ||
132 | // padding = new Clipperz.ByteArray(); | 127 | // padding = new Clipperz.ByteArray(); |
133 | padding = this.newInstance(); | 128 | padding = this.newInstance(); |
134 | cc = aLength - bLength; | 129 | cc = aLength - bLength; |
135 | for (ii=0; ii<cc; ii++) { | 130 | for (ii=0; ii<cc; ii++) { |
136 | padding.appendByte(0); | 131 | padding.appendByte(0); |
137 | } | 132 | } |
138 | 133 | ||
139 | if (anAllignment == 'left') { | 134 | if (anAllignment == 'left') { |
140 | b = b.appendBlock(padding); | 135 | b = b.appendBlock(padding); |
141 | } else { | 136 | } else { |
142 | b = padding.appendBlock(b); | 137 | b = padding.appendBlock(b); |
143 | } | 138 | } |
144 | } | 139 | } |
145 | } | 140 | } |
146 | 141 | ||
147 | |||
148 | // result = new Clipperz.ByteArray(); | ||
149 | result = this.newInstance(); | 142 | result = this.newInstance(); |
150 | c = a.length(); | 143 | c = a.length(); |
151 | for (i=0; i<c; i++) { | 144 | for (i=0; i<c; i++) { |
152 | result.appendByte(a.byteAtIndex(i) ^ b.byteAtIndex(i)); | 145 | result.appendByte(a.byteAtIndex(i) ^ b.byteAtIndex(i)); |
153 | } | 146 | } |
154 | 147 | ||
155 | return result; | 148 | return result; |
156 | }, | 149 | }, |
157 | 150 | ||
158 | //------------------------------------------------------------------------- | 151 | //------------------------------------------------------------------------- |
159 | /* | ||
160 | 'shiftLeft': function(aNumberOfBitsToShift) { | ||
161 | var result; | ||
162 | |||
163 | result = this.clone(); //??????????? | ||
164 | |||
165 | return result; | ||
166 | }, | ||
167 | */ | ||
168 | //------------------------------------------------------------------------- | ||
169 | 152 | ||
170 | 'appendBlock': function(aBlock) { | 153 | 'appendBlock': function(aBlock) { |
171 | throw Clipperz.Base.exception.AbstractMethod; | 154 | throw Clipperz.Base.exception.AbstractMethod; |
172 | }, | 155 | }, |
173 | 156 | ||
174 | //------------------------------------------------------------------------- | 157 | //------------------------------------------------------------------------- |
175 | 158 | ||
176 | 'appendByte': function(aValue) { | 159 | 'appendByte': function(aValue) { |
177 | throw Clipperz.Base.exception.AbstractMethod; | 160 | throw Clipperz.Base.exception.AbstractMethod; |
178 | }, | 161 | }, |
179 | 162 | ||
180 | 'appendBytes': function(args) { | 163 | 'appendBytes': function(args) { |
181 | varvalues; | 164 | varvalues; |
182 | vari,c; | 165 | vari,c; |
183 | 166 | ||
184 | if (args.constructor == Array) { | 167 | if (args.constructor == Array) { |
185 | values = args; | 168 | values = args; |
186 | } else { | 169 | } else { |
187 | values = arguments; | 170 | values = arguments; |
188 | } | 171 | } |
189 | 172 | ||
190 | c = values.length; | 173 | c = values.length; |
191 | for (i=0; i<c; i++) { | 174 | for (i=0; i<c; i++) { |
192 | this.appendByte(values[i]); | 175 | this.appendByte(values[i]); |
193 | } | 176 | } |
194 | 177 | ||
195 | return this; | 178 | return this; |
196 | }, | 179 | }, |
197 | 180 | ||
198 | //------------------------------------------------------------------------- | 181 | //------------------------------------------------------------------------- |
199 | 182 | ||
200 | 'appendWord': function(aValue, isLittleEndian) { | 183 | 'appendWord': function(aValue, isLittleEndian) { |
201 | var result; | 184 | var result; |
202 | var processAsLittleEndian; | 185 | var processAsLittleEndian; |
203 | 186 | ||
204 | processAsLittleEndian = isLittleEndian === true ? true : false; | 187 | processAsLittleEndian = isLittleEndian === true ? true : false; |
205 | 188 | ||
206 | if (processAsLittleEndian) { | 189 | if (processAsLittleEndian) { |
207 | result = this.appendBytes( (aValue) & 0xff, (aValue >> 8) & 0xff, (aValue >> 16) & 0xff, (aValue >> 24) & 0xff ); //little endian | 190 | result = this.appendBytes( (aValue) & 0xff, (aValue >> 8) & 0xff, (aValue >> 16) & 0xff, (aValue >> 24) & 0xff ); //little endian |
208 | } else { | 191 | } else { |
209 | result = this.appendBytes( (aValue >> 24) & 0xff, (aValue >> 16) & 0xff, (aValue >> 8) & 0xff, (aValue) & 0xff ); //big endian - DEFAULT | 192 | result = this.appendBytes( (aValue >> 24) & 0xff, (aValue >> 16) & 0xff, (aValue >> 8) & 0xff, (aValue) & 0xff ); //big endian - DEFAULT |
210 | } | 193 | } |
211 | 194 | ||
212 | return result; | 195 | return result; |
213 | }, | 196 | }, |
214 | 197 | ||
215 | 'appendWords': function(args) { | 198 | 'appendWords': function(args) { |
216 | varvalues; | 199 | varvalues; |
@@ -247,325 +230,303 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | |||
247 | this.appendWord(values[i], true); | 230 | this.appendWord(values[i], true); |
248 | } | 231 | } |
249 | 232 | ||
250 | return this; | 233 | return this; |
251 | }, | 234 | }, |
252 | 235 | ||
253 | //------------------------------------------------------------------------- | 236 | //------------------------------------------------------------------------- |
254 | 237 | ||
255 | 'appendBinaryString': function (aBinaryString) { | 238 | 'appendBinaryString': function (aBinaryString) { |
256 | var i,c; | 239 | var i,c; |
257 | 240 | ||
258 | c = aBinaryString.length; | 241 | c = aBinaryString.length; |
259 | for (i=0; i<c; i++) { | 242 | for (i=0; i<c; i++) { |
260 | this.appendByte(aBinaryString.charCodeAt(i)); | 243 | this.appendByte(aBinaryString.charCodeAt(i)); |
261 | }; | 244 | }; |
262 | 245 | ||
263 | return this; | 246 | return this; |
264 | }, | 247 | }, |
265 | 248 | ||
266 | //------------------------------------------------------------------------- | 249 | //------------------------------------------------------------------------- |
267 | 250 | ||
268 | 'byteAtIndex': function(anIndex) { | 251 | 'byteAtIndex': function(anIndex) { |
269 | throw Clipperz.Base.exception.AbstractMethod; | 252 | throw Clipperz.Base.exception.AbstractMethod; |
270 | }, | 253 | }, |
271 | 254 | ||
272 | 'setByteAtIndex': function(aValue, anIndex) { | 255 | 'setByteAtIndex': function(aValue, anIndex) { |
273 | throw Clipperz.Base.exception.AbstractMethod; | 256 | throw Clipperz.Base.exception.AbstractMethod; |
274 | }, | 257 | }, |
275 | 258 | ||
276 | //------------------------------------------------------------------------- | 259 | //------------------------------------------------------------------------- |
277 | 260 | ||
278 | 'bitAtIndex': function(aBitPosition) { | 261 | 'bitAtIndex': function(aBitPosition) { |
279 | var result; | 262 | var result; |
280 | varbytePosition; | 263 | varbytePosition; |
281 | var bitPositionInSelectedByte; | 264 | var bitPositionInSelectedByte; |
282 | var selectedByte; | 265 | var selectedByte; |
283 | var selectedByteMask; | 266 | var selectedByteMask; |
284 | 267 | ||
285 | bytePosition = this.length() - Math.ceil((aBitPosition + 1)/ 8); | 268 | bytePosition = this.length() - Math.ceil((aBitPosition + 1)/ 8); |
286 | bitPositionInSelectedByte = aBitPosition % 8; | 269 | bitPositionInSelectedByte = aBitPosition % 8; |
287 | selectedByte = this.byteAtIndex(bytePosition); | 270 | selectedByte = this.byteAtIndex(bytePosition); |
288 | 271 | ||
289 | if (bitPositionInSelectedByte > 0) { | 272 | if (bitPositionInSelectedByte > 0) { |
290 | selectedByteMask = (1 << bitPositionInSelectedByte); | 273 | selectedByteMask = (1 << bitPositionInSelectedByte); |
291 | } else { | 274 | } else { |
292 | selectedByteMask = 1; | 275 | selectedByteMask = 1; |
293 | } | 276 | } |
294 | result = selectedByte & selectedByteMask ? 1 : 0; | 277 | result = selectedByte & selectedByteMask ? 1 : 0; |
295 | //console.log("aBitPosition: " + aBitPosition + ", length: " + this.length() + ", bytePosition: " + bytePosition + ", bitPositionInSelectedByte: " + bitPositionInSelectedByte + ", selectedByteMask: " + selectedByteMask); | ||
296 | 278 | ||
297 | return result; | 279 | return result; |
298 | }, | 280 | }, |
299 | 281 | ||
300 | //------------------------------------------------------------------------- | 282 | //------------------------------------------------------------------------- |
301 | 283 | ||
302 | 'bitBlockAtIndexWithSize': function(aBitPosition, aSize) { | 284 | 'bitBlockAtIndexWithSize': function(aBitPosition, aSize) { |
303 | var result; | 285 | var result; |
304 | var bitValue; | 286 | var bitValue; |
305 | var i,c; | 287 | var i,c; |
306 | 288 | ||
307 | result = 0; | 289 | result = 0; |
308 | c = aSize; | 290 | c = aSize; |
309 | for (i=0; i<c; i++) { | 291 | for (i=0; i<c; i++) { |
310 | bitValue = this.bitAtIndex(aBitPosition + i); | 292 | bitValue = this.bitAtIndex(aBitPosition + i); |
311 | result = result | bitValue << i; | 293 | result = result | bitValue << i; |
312 | } | 294 | } |
313 | 295 | ||
314 | return result; | 296 | return result; |
315 | }, | 297 | }, |
316 | 298 | ||
317 | //------------------------------------------------------------------------- | 299 | //------------------------------------------------------------------------- |
318 | 300 | ||
319 | 'asString': function() { | 301 | 'asString': function() { |
320 | varresult; | 302 | varresult; |
321 | varlength; | 303 | varlength; |
322 | vari; | 304 | vari; |
323 | 305 | ||
324 | //var startTime = new Date(); | ||
325 | |||
326 | //# result = ""; | ||
327 | result = []; | 306 | result = []; |
328 | 307 | ||
329 | i = 0; | 308 | i = 0; |
330 | length = this.length(); | 309 | length = this.length(); |
331 | 310 | ||
332 | while (i < length) { | 311 | while (i < length) { |
333 | varcurrentCharacter; | 312 | varcurrentCharacter; |
334 | varcurrentByte; | 313 | varcurrentByte; |
335 | varunicode; | 314 | varunicode; |
336 | 315 | ||
337 | currentByte = this.byteAtIndex(i); | 316 | currentByte = this.byteAtIndex(i); |
338 | 317 | ||
339 | if ((currentByte & 0x80) == 0x00 ) { //0xxxxxxx | 318 | if ((currentByte & 0x80) == 0x00 ) { //0xxxxxxx |
340 | unicode = currentByte; | 319 | unicode = currentByte; |
341 | currentCharacter = String.fromCharCode(unicode); | 320 | currentCharacter = String.fromCharCode(unicode); |
342 | } else if ((currentByte & 0xe0) == 0xc0 ) { //110xxxxx 10xxxxxx | 321 | } else if ((currentByte & 0xe0) == 0xc0 ) { //110xxxxx 10xxxxxx |
343 | unicode = (currentByte & 0x1f) << 6; | 322 | unicode = (currentByte & 0x1f) << 6; |
344 | i++; currentByte = this.byteAtIndex(i); | 323 | i++; currentByte = this.byteAtIndex(i); |
345 | unicode = unicode | (currentByte & 0x3f); | 324 | unicode = unicode | (currentByte & 0x3f); |
346 | 325 | ||
347 | currentCharacter = String.fromCharCode(unicode); | 326 | currentCharacter = String.fromCharCode(unicode); |
348 | } else if ((currentByte & 0xf0) == 0xe0 ) { //1110xxxx 10xxxxxx 10xxxxxx | 327 | } else if ((currentByte & 0xf0) == 0xe0 ) { //1110xxxx 10xxxxxx 10xxxxxx |
349 | unicode = (currentByte & 0x0f) << (6+6); | 328 | unicode = (currentByte & 0x0f) << (6+6); |
350 | i++; currentByte = this.byteAtIndex(i); | 329 | i++; currentByte = this.byteAtIndex(i); |
351 | unicode = unicode | ((currentByte & 0x3f) << 6); | 330 | unicode = unicode | ((currentByte & 0x3f) << 6); |
352 | i++; currentByte = this.byteAtIndex(i); | 331 | i++; currentByte = this.byteAtIndex(i); |
353 | unicode = unicode | (currentByte & 0x3f); | 332 | unicode = unicode | (currentByte & 0x3f); |
354 | 333 | ||
355 | currentCharacter = String.fromCharCode(unicode); | 334 | currentCharacter = String.fromCharCode(unicode); |
356 | } else { //11110xxx 10xxxxxx 10xxxxxx 10xxxxxx | 335 | } else { //11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
357 | unicode = (currentByte & 0x07) << (6+6+6); | 336 | unicode = (currentByte & 0x07) << (6+6+6); |
358 | i++; currentByte = this.byteAtIndex(i); | 337 | i++; currentByte = this.byteAtIndex(i); |
359 | unicode = unicode | ((currentByte & 0x3f) << (6+6)); | 338 | unicode = unicode | ((currentByte & 0x3f) << (6+6)); |
360 | i++; currentByte = this.byteAtIndex(i); | 339 | i++; currentByte = this.byteAtIndex(i); |
361 | unicode = unicode | ((currentByte & 0x3f) << 6); | 340 | unicode = unicode | ((currentByte & 0x3f) << 6); |
362 | i++; currentByte = this.byteAtIndex(i); | 341 | i++; currentByte = this.byteAtIndex(i); |
363 | unicode = unicode | (currentByte & 0x3f); | 342 | unicode = unicode | (currentByte & 0x3f); |
364 | 343 | ||
365 | currentCharacter = String.fromCharCode(unicode); | 344 | currentCharacter = String.fromCharCode(unicode); |
366 | } | 345 | } |
367 | 346 | ||
368 | // result += currentCharacter; | ||
369 | result.push(currentCharacter); | 347 | result.push(currentCharacter); |
370 | i++; | 348 | i++; |
371 | } | 349 | } |
372 | 350 | ||
373 | //MochiKit.Logging.logDebug("[" + (new Date() - startTime) + "] ByteArray.asString"); | ||
374 | |||
375 | // return result; | ||
376 | return result.join(""); | 351 | return result.join(""); |
377 | }, | 352 | }, |
378 | 353 | ||
379 | //------------------------------------------------------------------------- | 354 | //------------------------------------------------------------------------- |
380 | 355 | ||
381 | 'toHexString': function() { | 356 | 'toHexString': function() { |
382 | throw Clipperz.Base.exception.AbstractMethod; | 357 | throw Clipperz.Base.exception.AbstractMethod; |
383 | }, | 358 | }, |
384 | 359 | ||
385 | //------------------------------------------------------------------------- | 360 | //------------------------------------------------------------------------- |
386 | 361 | ||
387 | 'base64map': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | 362 | 'base64map': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", |
388 | 'base64mapIndex': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(''), | 363 | 'base64mapIndex': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(''), |
389 | //'base64mapInvertedIndex': { | ||
390 | // 'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 'I': 8, 'J': 9, | ||
391 | // 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15, 'Q': 16, 'R': 17, 'S': 18, 'T': 19, | ||
392 | // 'U': 20, 'V': 21, 'W': 22, 'X': 23, 'Y': 24, 'Z': 25, 'a': 26, 'b': 27, 'c': 28, 'd': 29, | ||
393 | // 'e': 30, 'f': 31, 'g': 32, 'h': 33, 'i': 34, 'j': 35, 'k': 36, 'l': 37, 'm': 38, 'n': 39, | ||
394 | // 'o': 40, 'p': 41, 'q': 42, 'r': 43, 's': 44, 't': 45, 'u': 46, 'v': 47, 'w': 48, 'x': 49, | ||
395 | // 'y': 50, 'z': 51, '0': 52, '1': 53, '2': 54, '3': 55, '4': 56, '5': 57, '6': 58, '7': 59, | ||
396 | // '8': 60, '9': 61, '+': 62, '/': 63, | ||
397 | // "=": -1}, | ||
398 | 364 | ||
399 | //------------------------------------------------------------------------- | 365 | //------------------------------------------------------------------------- |
400 | 366 | ||
401 | 'appendBase64String': function(aValue) { | 367 | 'appendBase64String': function(aValue) { |
402 | var i; | 368 | var i; |
403 | var length; | 369 | var length; |
404 | 370 | ||
405 | length = aValue.length; | 371 | length = aValue.length; |
406 | 372 | ||
407 | if ((length % 4) != 0) { | 373 | if ((length % 4) != 0) { |
408 | MochiKit.Logging.logError("the value passed to the 'ByteArray.setBase64Value' is not correct"); | 374 | Clipperz.logError("the value passed to the 'ByteArray.setBase64Value' is not correct"); |
409 | throw Clipperz.ByteArray.exception.InvalidValue; | 375 | throw Clipperz.ByteArray.exception.InvalidValue; |
410 | } | 376 | } |
411 | 377 | ||
412 | i = 0; | 378 | i = 0; |
413 | while (i<length) { | 379 | while (i<length) { |
414 | var value1, value2, value3, value4; | 380 | var value1, value2, value3, value4; |
415 | var byte1, byte2, byte3; | 381 | var byte1, byte2, byte3; |
416 | 382 | ||
417 | value1 = this.base64map.indexOf(aValue.charAt(i)); | 383 | value1 = this.base64map.indexOf(aValue.charAt(i)); |
418 | value2 = this.base64map.indexOf(aValue.charAt(i+1)); | 384 | value2 = this.base64map.indexOf(aValue.charAt(i+1)); |
419 | value3 = this.base64map.indexOf(aValue.charAt(i+2)); | 385 | value3 = this.base64map.indexOf(aValue.charAt(i+2)); |
420 | value4 = this.base64map.indexOf(aValue.charAt(i+3)); | 386 | value4 = this.base64map.indexOf(aValue.charAt(i+3)); |
421 | 387 | ||
422 | // value1 = this.base64mapInvertedIndex[aValue.charAt(i)]; | ||
423 | // value2 = this.base64mapInvertedIndex[aValue.charAt(i+1)]; | ||
424 | // value3 = this.base64mapInvertedIndex[aValue.charAt(i+2)]; | ||
425 | // value4 = this.base64mapInvertedIndex[aValue.charAt(i+3)]; | ||
426 | |||
427 | byte1 = (value1 << 2) | ((value2 & 0x30) >> 4); | 388 | byte1 = (value1 << 2) | ((value2 & 0x30) >> 4); |
428 | if (value3 != -1) { | 389 | if (value3 != -1) { |
429 | byte2 = ((value2 & 0x0f) << 4) | ((value3 & 0x3c) >> 2); | 390 | byte2 = ((value2 & 0x0f) << 4) | ((value3 & 0x3c) >> 2); |
430 | 391 | ||
431 | if (value4 != -1) { | 392 | if (value4 != -1) { |
432 | byte3 = ((value3 & 0x03) << 6) | (value4); | 393 | byte3 = ((value3 & 0x03) << 6) | (value4); |
433 | } else { | 394 | } else { |
434 | byte3 = null; | 395 | byte3 = null; |
435 | } | 396 | } |
436 | } else { | 397 | } else { |
437 | byte2 = null; | 398 | byte2 = null; |
438 | byte3 = null; | 399 | byte3 = null; |
439 | } | 400 | } |
440 | 401 | ||
441 | this.appendByte(byte1); | 402 | this.appendByte(byte1); |
442 | this.appendByte(byte2); | 403 | this.appendByte(byte2); |
443 | this.appendByte(byte3); | 404 | this.appendByte(byte3); |
444 | 405 | ||
445 | i += 4; | 406 | i += 4; |
446 | } | 407 | } |
447 | 408 | ||
448 | return this; | 409 | return this; |
449 | }, | 410 | }, |
450 | 411 | ||
451 | //------------------------------------------------------------------------- | 412 | //------------------------------------------------------------------------- |
452 | 413 | ||
453 | 'toBase64String': function() { | 414 | 'toBase64String': function() { |
454 | var result; | 415 | var result; |
455 | var length; | 416 | var length; |
456 | var i; | 417 | var i; |
457 | var byte1, byte2, byte3; | 418 | var byte1, byte2, byte3; |
458 | var char1, char2, char3, char4; | 419 | var char1, char2, char3, char4; |
459 | 420 | ||
460 | i = 0; | 421 | i = 0; |
461 | length = this.length(); | 422 | length = this.length(); |
462 | result = new Array(Math.ceil(length/3)); | 423 | result = new Array(Math.ceil(length/3)); |
463 | 424 | ||
464 | while (i < length) { | 425 | while (i < length) { |
465 | byte1 = this.byteAtIndex(i); | 426 | byte1 = this.byteAtIndex(i); |
466 | if ((i+2) < length) { | 427 | if ((i+2) < length) { |
467 | byte2 = this.byteAtIndex(i+1); | 428 | byte2 = this.byteAtIndex(i+1); |
468 | byte3 = this.byteAtIndex(i+2); | 429 | byte3 = this.byteAtIndex(i+2); |
469 | } else if ((i+2) == length) { | 430 | } else if ((i+2) == length) { |
470 | byte2 = this.byteAtIndex(i+1); | 431 | byte2 = this.byteAtIndex(i+1); |
471 | byte3 = null; | 432 | byte3 = null; |
472 | } else { | 433 | } else { |
473 | byte2 = null; | 434 | byte2 = null; |
474 | byte3 = null; | 435 | byte3 = null; |
475 | } | 436 | } |
476 | 437 | ||
477 | char1 = this.base64mapIndex[byte1 >> 2]; | 438 | char1 = this.base64mapIndex[byte1 >> 2]; |
478 | if (byte2 != null) { | 439 | if (byte2 != null) { |
479 | char2 = this.base64mapIndex[((byte1 & 0x03) << 4) | ((byte2 & 0xf0) >> 4)]; | 440 | char2 = this.base64mapIndex[((byte1 & 0x03) << 4) | ((byte2 & 0xf0) >> 4)]; |
480 | if (byte3 != null) { | 441 | if (byte3 != null) { |
481 | char3 = this.base64mapIndex[((byte2 & 0x0f) << 2) | ((byte3 & 0xc0) >> 6)]; | 442 | char3 = this.base64mapIndex[((byte2 & 0x0f) << 2) | ((byte3 & 0xc0) >> 6)]; |
482 | char4 = this.base64mapIndex[(byte3 & 0x3f)]; | 443 | char4 = this.base64mapIndex[(byte3 & 0x3f)]; |
483 | } else { | 444 | } else { |
484 | char3 = this.base64mapIndex[(byte2 & 0x0f) << 2]; | 445 | char3 = this.base64mapIndex[(byte2 & 0x0f) << 2]; |
485 | char4 = "="; | 446 | char4 = "="; |
486 | } | 447 | } |
487 | } else { | 448 | } else { |
488 | char2 = this.base64mapIndex[(byte1 & 0x03) << 4]; | 449 | char2 = this.base64mapIndex[(byte1 & 0x03) << 4]; |
489 | char3 = "="; | 450 | char3 = "="; |
490 | char4 = "="; | 451 | char4 = "="; |
491 | } | 452 | } |
492 | 453 | ||
493 | result.push(char1 + char2 + char3 + char4); | 454 | result.push(char1 + char2 + char3 + char4); |
494 | 455 | ||
495 | i += 3; | 456 | i += 3; |
496 | } | 457 | } |
497 | 458 | ||
498 | return result.join(""); | 459 | return result.join(""); |
499 | }, | 460 | }, |
500 | 461 | ||
501 | //------------------------------------------------------------------------- | 462 | //------------------------------------------------------------------------- |
502 | 463 | ||
503 | 'base32map': "0123456789abcdefghjkmnpqrstvwxyz", | 464 | 'base32map': "0123456789abcdefghjkmnpqrstvwxyz", |
504 | 'base32mapIndex': "0123456789abcdefghjkmnpqrstvwxyz".split(''), | 465 | 'base32mapIndex': "0123456789abcdefghjkmnpqrstvwxyz".split(''), |
505 | 466 | ||
506 | //------------------------------------------------------------------------- | 467 | //------------------------------------------------------------------------- |
507 | 468 | ||
508 | 'appendBase32String': function(aValue) { | 469 | 'appendBase32String': function(aValue) { |
509 | var value; | 470 | var value; |
510 | var i; | 471 | var i; |
511 | var length; | 472 | var length; |
512 | var value1, value2, value3, value4, value5, value6, value7, value8; | 473 | var value1, value2, value3, value4, value5, value6, value7, value8; |
513 | var byte1, byte2, byte3, byte4, byte5; | 474 | var byte1, byte2, byte3, byte4, byte5; |
514 | 475 | ||
515 | value = aValue.toLowerCase(); | 476 | value = aValue.toLowerCase(); |
516 | value = value.replace(/[\s\-]/g, ''); | 477 | value = value.replace(/[\s\-]/g, ''); |
517 | value = value.replace(/[0o]/g, '0'); | 478 | value = value.replace(/[0o]/g, '0'); |
518 | value = value.replace(/[1il]/g, '1'); | 479 | value = value.replace(/[1il]/g, '1'); |
519 | 480 | ||
520 | length = value.length; | 481 | length = value.length; |
521 | 482 | ||
522 | if ((length % 8) != 0) { | 483 | if ((length % 8) != 0) { |
523 | MochiKit.Logging.logError("the value passed to the 'ByteArray.setBase32Value' is not correct"); | 484 | Clipperz.logError("the value passed to the 'ByteArray.setBase32Value' is not correct"); |
524 | throw Clipperz.ByteArray.exception.InvalidValue; | 485 | throw Clipperz.ByteArray.exception.InvalidValue; |
525 | } | 486 | } |
526 | 487 | ||
527 | i = 0; | 488 | i = 0; |
528 | while (i<length) { | 489 | while (i<length) { |
529 | value1 = this.base32map.indexOf(value.charAt(i)); | 490 | value1 = this.base32map.indexOf(value.charAt(i)); |
530 | value2 = this.base32map.indexOf(value.charAt(i+1)); | 491 | value2 = this.base32map.indexOf(value.charAt(i+1)); |
531 | value3 = this.base32map.indexOf(value.charAt(i+2)); | 492 | value3 = this.base32map.indexOf(value.charAt(i+2)); |
532 | value4 = this.base32map.indexOf(value.charAt(i+3)); | 493 | value4 = this.base32map.indexOf(value.charAt(i+3)); |
533 | value5 = this.base32map.indexOf(value.charAt(i+4)); | 494 | value5 = this.base32map.indexOf(value.charAt(i+4)); |
534 | value6 = this.base32map.indexOf(value.charAt(i+5)); | 495 | value6 = this.base32map.indexOf(value.charAt(i+5)); |
535 | value7 = this.base32map.indexOf(value.charAt(i+6)); | 496 | value7 = this.base32map.indexOf(value.charAt(i+6)); |
536 | value8 = this.base32map.indexOf(value.charAt(i+7)); | 497 | value8 = this.base32map.indexOf(value.charAt(i+7)); |
537 | 498 | ||
538 | byte1 = byte2 = byte3 = byte4 = byte5 = null; | 499 | byte1 = byte2 = byte3 = byte4 = byte5 = null; |
539 | 500 | ||
540 | byte1 = (value1 << 3) | ((value2 & 0x1c) >> 2); | 501 | byte1 = (value1 << 3) | ((value2 & 0x1c) >> 2); |
541 | if (value3 != -1) { | 502 | if (value3 != -1) { |
542 | byte2 = ((value2 & 0x03) << 6) | (value3 << 1) | ((value4 & 0x10) >> 4); | 503 | byte2 = ((value2 & 0x03) << 6) | (value3 << 1) | ((value4 & 0x10) >> 4); |
543 | if (value5 != -1) { | 504 | if (value5 != -1) { |
544 | byte3 = ((value4 & 0x0f) << 4) | ((value5 & 0x1e) >> 1); | 505 | byte3 = ((value4 & 0x0f) << 4) | ((value5 & 0x1e) >> 1); |
545 | if (value6 != -1) { | 506 | if (value6 != -1) { |
546 | byte4 = ((value5 & 0x01) << 7) | (value6 << 2) | ((value7 & 0x18) >> 3); | 507 | byte4 = ((value5 & 0x01) << 7) | (value6 << 2) | ((value7 & 0x18) >> 3); |
547 | if (value8 != -1) { | 508 | if (value8 != -1) { |
548 | byte5 = ((value7 & 0x07) << 5) | (value8); | 509 | byte5 = ((value7 & 0x07) << 5) | (value8); |
549 | } | 510 | } |
550 | } | 511 | } |
551 | } | 512 | } |
552 | } | 513 | } |
553 | 514 | ||
554 | this.appendByte(byte1); | 515 | this.appendByte(byte1); |
555 | this.appendByte(byte2); | 516 | this.appendByte(byte2); |
556 | this.appendByte(byte3); | 517 | this.appendByte(byte3); |
557 | this.appendByte(byte4); | 518 | this.appendByte(byte4); |
558 | this.appendByte(byte5); | 519 | this.appendByte(byte5); |
559 | 520 | ||
560 | i += 8; | 521 | i += 8; |
561 | } | 522 | } |
562 | 523 | ||
563 | return this; | 524 | return this; |
564 | }, | 525 | }, |
565 | 526 | ||
566 | //------------------------------------------------------------------------- | 527 | //------------------------------------------------------------------------- |
567 | 528 | ||
568 | 'toBase32String': function() { | 529 | 'toBase32String': function() { |
569 | var result; | 530 | var result; |
570 | var length; | 531 | var length; |
571 | var i; | 532 | var i; |
@@ -683,97 +644,97 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | |||
683 | this.setByteAtIndex(0, i); | 644 | this.setByteAtIndex(0, i); |
684 | if (i>= 0) { | 645 | if (i>= 0) { |
685 | i --; | 646 | i --; |
686 | } else { | 647 | } else { |
687 | done = true; | 648 | done = true; |
688 | } | 649 | } |
689 | } else { | 650 | } else { |
690 | this.setByteAtIndex(currentByteValue + 1, i); | 651 | this.setByteAtIndex(currentByteValue + 1, i); |
691 | done = true; | 652 | done = true; |
692 | } | 653 | } |
693 | } | 654 | } |
694 | }, | 655 | }, |
695 | 656 | ||
696 | //------------------------------------------------------------------------- | 657 | //------------------------------------------------------------------------- |
697 | 658 | ||
698 | 'arrayValues': function() { | 659 | 'arrayValues': function() { |
699 | throw Clipperz.Base.exception.AbstractMethod; | 660 | throw Clipperz.Base.exception.AbstractMethod; |
700 | }, | 661 | }, |
701 | 662 | ||
702 | //------------------------------------------------------------------------- | 663 | //------------------------------------------------------------------------- |
703 | __syntaxFix__: "syntax fix" | 664 | __syntaxFix__: "syntax fix" |
704 | 665 | ||
705 | }); | 666 | }); |
706 | 667 | ||
707 | //============================================================================= | 668 | //============================================================================= |
708 | // | 669 | // |
709 | //Clipperz.ByteArray_hex | 670 | //Clipperz.ByteArray_hex |
710 | // | 671 | // |
711 | //============================================================================= | 672 | //============================================================================= |
712 | /* | 673 | /* |
713 | Clipperz.ByteArray_hex = function (args) { | 674 | Clipperz.ByteArray_hex = function (args) { |
714 | this._value = ""; | 675 | this._value = ""; |
715 | 676 | ||
716 | if (typeof(args) != 'undefined') { | 677 | if (typeof(args) != 'undefined') { |
717 | if (args.constructor == Array) { | 678 | if (args.constructor == Array) { |
718 | this.appendBytes(args); | 679 | this.appendBytes(args); |
719 | } else if (args.constructor == String) { | 680 | } else if (args.constructor == String) { |
720 | if (args.indexOf("0x") == 0) { | 681 | if (args.indexOf("0x") == 0) { |
721 | varvalue; | 682 | varvalue; |
722 | 683 | ||
723 | value = args.substring(2).toLowerCase(); | 684 | value = args.substring(2).toLowerCase(); |
724 | if (/[0123456789abcdef]* /.test(value)) { the space in the regexp shoud be removed if the code is activate | 685 | if (/[0123456789abcdef]* /.test(value)) { the space in the regexp shoud be removed if the code is activate |
725 | if ((value.length % 2) == 0) { | 686 | if ((value.length % 2) == 0) { |
726 | this._value = value; | 687 | this._value = value; |
727 | } else { | 688 | } else { |
728 | this._value = "0" + value; | 689 | this._value = "0" + value; |
729 | } | 690 | } |
730 | } else { | 691 | } else { |
731 | MochiKit.Logging.logError("Clipperz.ByteArray should be inizialized with an hex string."); | 692 | Clipperz.logError("Clipperz.ByteArray should be inizialized with an hex string."); |
732 | throw Clipperz.ByteArray.exception.InvalidValue; | 693 | throw Clipperz.ByteArray.exception.InvalidValue; |
733 | } | 694 | } |
734 | } else { | 695 | } else { |
735 | varvalue; | 696 | varvalue; |
736 | vari,c; | 697 | vari,c; |
737 | 698 | ||
738 | c = args.length; | 699 | c = args.length; |
739 | value = new Array(c); | 700 | value = new Array(c); |
740 | for (i=0; i<c; i++) { | 701 | for (i=0; i<c; i++) { |
741 | value.push(Clipperz.ByteArray.unicodeToUtf8HexString(args.charCodeAt(i))); | 702 | value.push(Clipperz.ByteArray.unicodeToUtf8HexString(args.charCodeAt(i))); |
742 | } | 703 | } |
743 | 704 | ||
744 | this._value = value.join(""); | 705 | this._value = value.join(""); |
745 | } | 706 | } |
746 | } else { | 707 | } else { |
747 | this.appendBytes(MochiKit.Base.extend(null, arguments)); | 708 | this.appendBytes(MochiKit.Base.extend(null, arguments)); |
748 | } | 709 | } |
749 | } | 710 | } |
750 | return this; | 711 | return this; |
751 | } | 712 | } |
752 | 713 | ||
753 | Clipperz.ByteArray_hex.prototype = MochiKit.Base.update(new Clipperz.ByteArray_abstract(), { | 714 | Clipperz.ByteArray_hex.prototype = MochiKit.Base.update(new Clipperz.ByteArray_abstract(), { |
754 | 715 | ||
755 | //------------------------------------------------------------------------- | 716 | //------------------------------------------------------------------------- |
756 | 717 | ||
757 | 'toString': function() { | 718 | 'toString': function() { |
758 | return "Clipperz.ByteArray_hex"; | 719 | return "Clipperz.ByteArray_hex"; |
759 | }, | 720 | }, |
760 | 721 | ||
761 | //------------------------------------------------------------------------- | 722 | //------------------------------------------------------------------------- |
762 | 723 | ||
763 | 'clone': function() { | 724 | 'clone': function() { |
764 | var result; | 725 | var result; |
765 | 726 | ||
766 | result = this.newInstance(); | 727 | result = this.newInstance(); |
767 | result._value = this._value; | 728 | result._value = this._value; |
768 | 729 | ||
769 | return result; | 730 | return result; |
770 | }, | 731 | }, |
771 | 732 | ||
772 | //------------------------------------------------------------------------- | 733 | //------------------------------------------------------------------------- |
773 | 734 | ||
774 | 'newInstance': function() { | 735 | 'newInstance': function() { |
775 | return new Clipperz.ByteArray_hex(); | 736 | return new Clipperz.ByteArray_hex(); |
776 | }, | 737 | }, |
777 | 738 | ||
778 | //------------------------------------------------------------------------- | 739 | //------------------------------------------------------------------------- |
779 | 740 | ||
@@ -869,97 +830,97 @@ Clipperz.ByteArray_hex.prototype = MochiKit.Base.update(new Clipperz.ByteArray_a | |||
869 | 830 | ||
870 | return result; | 831 | return result; |
871 | }, | 832 | }, |
872 | 833 | ||
873 | //------------------------------------------------------------------------- | 834 | //------------------------------------------------------------------------- |
874 | 835 | ||
875 | 'arrayValues': function() { | 836 | 'arrayValues': function() { |
876 | var result; | 837 | var result; |
877 | var i,c; | 838 | var i,c; |
878 | 839 | ||
879 | c = this.length(); | 840 | c = this.length(); |
880 | 841 | ||
881 | result = new Array(c); | 842 | result = new Array(c); |
882 | for (i=0; i<c; i++) { | 843 | for (i=0; i<c; i++) { |
883 | result[i] = this.byteAtIndex(i); | 844 | result[i] = this.byteAtIndex(i); |
884 | } | 845 | } |
885 | 846 | ||
886 | return result; | 847 | return result; |
887 | }, | 848 | }, |
888 | 849 | ||
889 | //------------------------------------------------------------------------- | 850 | //------------------------------------------------------------------------- |
890 | __syntaxFix__: "syntax fix" | 851 | __syntaxFix__: "syntax fix" |
891 | }); | 852 | }); |
892 | */ | 853 | */ |
893 | 854 | ||
894 | //============================================================================= | 855 | //============================================================================= |
895 | // | 856 | // |
896 | //Clipperz.ByteArray_array | 857 | //Clipperz.ByteArray_array |
897 | // | 858 | // |
898 | //============================================================================= | 859 | //============================================================================= |
899 | 860 | ||
900 | Clipperz.ByteArray_array = function (args) { | 861 | Clipperz.ByteArray_array = function (args) { |
901 | if (typeof(args) != 'undefined') { | 862 | if (typeof(args) != 'undefined') { |
902 | if (args.constructor == Array) { | 863 | if (args.constructor == Array) { |
903 | this._value = args.slice(0); | 864 | this._value = args.slice(0); |
904 | } else if (args.constructor == String) { | 865 | } else if (args.constructor == String) { |
905 | var result; | 866 | var result; |
906 | varvalue; | 867 | varvalue; |
907 | var i, c; | 868 | var i, c; |
908 | 869 | ||
909 | if (args.indexOf("0x") == 0) { | 870 | if (args.indexOf("0x") == 0) { |
910 | 871 | ||
911 | value = args.substring(2).toLowerCase(); | 872 | value = args.substring(2).toLowerCase(); |
912 | if (/[0123456789abcdef]*/.test(value)) { | 873 | if (/[0123456789abcdef]*/.test(value)) { |
913 | if ((value.length % 2) != 0) { | 874 | if ((value.length % 2) != 0) { |
914 | value = "0" + value; | 875 | value = "0" + value; |
915 | } | 876 | } |
916 | } else { | 877 | } else { |
917 | MochiKit.Logging.logError("Clipperz.ByteArray should be inizialized with an hex string."); | 878 | Clipperz.logError("Clipperz.ByteArray should be inizialized with an hex string."); |
918 | throw Clipperz.ByteArray.exception.InvalidValue; | 879 | throw Clipperz.ByteArray.exception.InvalidValue; |
919 | } | 880 | } |
920 | 881 | ||
921 | c = value.length / 2 | 882 | c = value.length / 2 |
922 | result = new Array(c); | 883 | result = new Array(c); |
923 | for (i=0; i<c; i++) { | 884 | for (i=0; i<c; i++) { |
924 | result[i] = parseInt(value.substr(i*2, 2), 16); | 885 | result[i] = parseInt(value.substr(i*2, 2), 16); |
925 | } | 886 | } |
926 | 887 | ||
927 | } else { | 888 | } else { |
928 | var unicode; | 889 | var unicode; |
929 | result = []; | 890 | result = []; |
930 | c = args.length; | 891 | c = args.length; |
931 | for (i=0; i<c; i++) { | 892 | for (i=0; i<c; i++) { |
932 | // Clipperz.ByteArray.pushUtf8BytesOfUnicodeChar(result, args.charCodeAt(i)); | 893 | // Clipperz.ByteArray.pushUtf8BytesOfUnicodeChar(result, args.charCodeAt(i)); |
933 | 894 | ||
934 | unicode = args.charCodeAt(i); | 895 | unicode = args.charCodeAt(i); |
935 | if (unicode <= 0x7f) { //0x00000000 - 0x0000007f -> 0xxxxxxx | 896 | if (unicode <= 0x7f) { //0x00000000 - 0x0000007f -> 0xxxxxxx |
936 | result.push(unicode); | 897 | result.push(unicode); |
937 | // } else if ((unicode >= 0x80) && (unicode <= 0x7ff)) { //0x00000080 - 0x000007ff -> 110xxxxx 10xxxxxx | 898 | // } else if ((unicode >= 0x80) && (unicode <= 0x7ff)) { //0x00000080 - 0x000007ff -> 110xxxxx 10xxxxxx |
938 | } else if (unicode <= 0x7ff) { //0x00000080 - 0x000007ff -> 110xxxxx 10xxxxxx | 899 | } else if (unicode <= 0x7ff) { //0x00000080 - 0x000007ff -> 110xxxxx 10xxxxxx |
939 | result.push((unicode >> 6) | 0xc0); | 900 | result.push((unicode >> 6) | 0xc0); |
940 | result.push((unicode & 0x3F) | 0x80); | 901 | result.push((unicode & 0x3F) | 0x80); |
941 | // } else if ((unicode >= 0x0800) && (unicode <= 0xffff)) { //0x00000800 - 0x0000ffff -> 1110xxxx 10xxxxxx 10xxxxxx | 902 | // } else if ((unicode >= 0x0800) && (unicode <= 0xffff)) { //0x00000800 - 0x0000ffff -> 1110xxxx 10xxxxxx 10xxxxxx |
942 | } else if (unicode <= 0xffff) { //0x00000800 - 0x0000ffff -> 1110xxxx 10xxxxxx 10xxxxxx | 903 | } else if (unicode <= 0xffff) { //0x00000800 - 0x0000ffff -> 1110xxxx 10xxxxxx 10xxxxxx |
943 | result.push((unicode >> 12) | 0xe0); | 904 | result.push((unicode >> 12) | 0xe0); |
944 | result.push(((unicode >> 6) & 0x3f) | 0x80); | 905 | result.push(((unicode >> 6) & 0x3f) | 0x80); |
945 | result.push((unicode & 0x3f) | 0x80); | 906 | result.push((unicode & 0x3f) | 0x80); |
946 | } else { //0x00010000 - 0x001fffff -> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx | 907 | } else { //0x00010000 - 0x001fffff -> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
947 | result.push((unicode >> 18) | 0xf0); | 908 | result.push((unicode >> 18) | 0xf0); |
948 | result.push(((unicode >> 12) & 0x3f) | 0x80); | 909 | result.push(((unicode >> 12) & 0x3f) | 0x80); |
949 | result.push(((unicode >> 6) & 0x3f) | 0x80); | 910 | result.push(((unicode >> 6) & 0x3f) | 0x80); |
950 | result.push((unicode & 0x3f) | 0x80); | 911 | result.push((unicode & 0x3f) | 0x80); |
951 | } | 912 | } |
952 | } | 913 | } |
953 | } | 914 | } |
954 | 915 | ||
955 | 916 | ||
956 | this._value = result; | 917 | this._value = result; |
957 | } else { | 918 | } else { |
958 | this._value = []; | 919 | this._value = []; |
959 | this.appendBytes(MochiKit.Base.extend(null, arguments)); | 920 | this.appendBytes(MochiKit.Base.extend(null, arguments)); |
960 | } | 921 | } |
961 | } else { | 922 | } else { |
962 | this._value = []; | 923 | this._value = []; |
963 | } | 924 | } |
964 | 925 | ||
965 | return this; | 926 | return this; |
@@ -1070,97 +1031,97 @@ Clipperz.ByteArray_array.prototype = MochiKit.Base.update(new Clipperz.ByteArray | |||
1070 | 'split': function(aStartingIndex, anEndingIndex) { | 1031 | 'split': function(aStartingIndex, anEndingIndex) { |
1071 | var result; | 1032 | var result; |
1072 | 1033 | ||
1073 | result = this.newInstance(); | 1034 | result = this.newInstance(); |
1074 | result._value = this._value.slice(aStartingIndex, anEndingIndex ? anEndingIndex : this.length()); | 1035 | result._value = this._value.slice(aStartingIndex, anEndingIndex ? anEndingIndex : this.length()); |
1075 | 1036 | ||
1076 | return result; | 1037 | return result; |
1077 | }, | 1038 | }, |
1078 | 1039 | ||
1079 | //------------------------------------------------------------------------- | 1040 | //------------------------------------------------------------------------- |
1080 | 1041 | ||
1081 | 'arrayValues': function() { | 1042 | 'arrayValues': function() { |
1082 | return this._value.slice(0); | 1043 | return this._value.slice(0); |
1083 | }, | 1044 | }, |
1084 | 1045 | ||
1085 | //------------------------------------------------------------------------- | 1046 | //------------------------------------------------------------------------- |
1086 | __syntaxFix__: "syntax fix" | 1047 | __syntaxFix__: "syntax fix" |
1087 | }); | 1048 | }); |
1088 | 1049 | ||
1089 | 1050 | ||
1090 | 1051 | ||
1091 | 1052 | ||
1092 | 1053 | ||
1093 | //============================================================================= | 1054 | //============================================================================= |
1094 | // | 1055 | // |
1095 | //Clipperz.ByteArray_string | 1056 | //Clipperz.ByteArray_string |
1096 | // | 1057 | // |
1097 | //============================================================================= | 1058 | //============================================================================= |
1098 | /* | 1059 | /* |
1099 | Clipperz.ByteArray_string = function (args) { | 1060 | Clipperz.ByteArray_string = function (args) { |
1100 | this._value = ""; | 1061 | this._value = ""; |
1101 | 1062 | ||
1102 | if (typeof(args) != 'undefined') { | 1063 | if (typeof(args) != 'undefined') { |
1103 | if (args.constructor == Array) { | 1064 | if (args.constructor == Array) { |
1104 | this.appendBytes(args); | 1065 | this.appendBytes(args); |
1105 | } else if (args.constructor == String) { | 1066 | } else if (args.constructor == String) { |
1106 | var result; | 1067 | var result; |
1107 | varvalue; | 1068 | varvalue; |
1108 | var i, c; | 1069 | var i, c; |
1109 | 1070 | ||
1110 | if (args.indexOf("0x") == 0) { | 1071 | if (args.indexOf("0x") == 0) { |
1111 | 1072 | ||
1112 | value = args.substring(2).toLowerCase(); | 1073 | value = args.substring(2).toLowerCase(); |
1113 | if (/[0123456789abcdef]* /.test(value)) { the space in the regexp shoud be removed if the code is activated | 1074 | if (/[0123456789abcdef]* /.test(value)) { the space in the regexp shoud be removed if the code is activated |
1114 | if ((value.length % 2) != 0) { | 1075 | if ((value.length % 2) != 0) { |
1115 | value = "0" + value; | 1076 | value = "0" + value; |
1116 | } | 1077 | } |
1117 | } else { | 1078 | } else { |
1118 | MochiKit.Logging.logError("Clipperz.ByteArray should be inizialized with an hex string."); | 1079 | Clipperz.logError("Clipperz.ByteArray should be inizialized with an hex string."); |
1119 | throw Clipperz.ByteArray.exception.InvalidValue; | 1080 | throw Clipperz.ByteArray.exception.InvalidValue; |
1120 | } | 1081 | } |
1121 | } else { | 1082 | } else { |
1122 | value = ""; | 1083 | value = ""; |
1123 | c = args.length; | 1084 | c = args.length; |
1124 | for (i=0; i<c; i++) { | 1085 | for (i=0; i<c; i++) { |
1125 | value += Clipperz.ByteArray.unicodeToUtf8HexString(args.charCodeAt(i)); | 1086 | value += Clipperz.ByteArray.unicodeToUtf8HexString(args.charCodeAt(i)); |
1126 | } | 1087 | } |
1127 | } | 1088 | } |
1128 | 1089 | ||
1129 | c = value.length / 2 | 1090 | c = value.length / 2 |
1130 | for (i=0; i<c; i++) { | 1091 | for (i=0; i<c; i++) { |
1131 | this.appendByte(parseInt(value.substr(i*2, 2), 16)); | 1092 | this.appendByte(parseInt(value.substr(i*2, 2), 16)); |
1132 | } | 1093 | } |
1133 | } else { | 1094 | } else { |
1134 | this.appendBytes(MochiKit.Base.extend(null, arguments)); | 1095 | this.appendBytes(MochiKit.Base.extend(null, arguments)); |
1135 | } | 1096 | } |
1136 | } | 1097 | } |
1137 | 1098 | ||
1138 | return this; | 1099 | return this; |
1139 | } | 1100 | } |
1140 | 1101 | ||
1141 | Clipperz.ByteArray_string.prototype = MochiKit.Base.update(new Clipperz.ByteArray_abstract(), { | 1102 | Clipperz.ByteArray_string.prototype = MochiKit.Base.update(new Clipperz.ByteArray_abstract(), { |
1142 | 1103 | ||
1143 | //------------------------------------------------------------------------- | 1104 | //------------------------------------------------------------------------- |
1144 | 1105 | ||
1145 | 'toString': function() { | 1106 | 'toString': function() { |
1146 | return "Clipperz.ByteArray_string"; | 1107 | return "Clipperz.ByteArray_string"; |
1147 | }, | 1108 | }, |
1148 | 1109 | ||
1149 | //------------------------------------------------------------------------- | 1110 | //------------------------------------------------------------------------- |
1150 | 1111 | ||
1151 | 'clone': function() { | 1112 | 'clone': function() { |
1152 | var result; | 1113 | var result; |
1153 | 1114 | ||
1154 | result = this.newInstance(); | 1115 | result = this.newInstance(); |
1155 | result._value = this._value; | 1116 | result._value = this._value; |
1156 | 1117 | ||
1157 | return result; | 1118 | return result; |
1158 | }, | 1119 | }, |
1159 | 1120 | ||
1160 | //------------------------------------------------------------------------- | 1121 | //------------------------------------------------------------------------- |
1161 | 1122 | ||
1162 | 'newInstance': function() { | 1123 | 'newInstance': function() { |
1163 | return new Clipperz.ByteArray_string(); | 1124 | return new Clipperz.ByteArray_string(); |
1164 | }, | 1125 | }, |
1165 | 1126 | ||
1166 | //------------------------------------------------------------------------- | 1127 | //------------------------------------------------------------------------- |