summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/ByteArray.js
authorClipperz <info@clipperz.com>2013-01-31 13:42:04 (UTC)
committer Clipperz <info@clipperz.com>2013-01-31 13:42:04 (UTC)
commit07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff)
treef7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/ByteArray.js
parent767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff)
downloadclipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip
clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz
clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2
Updated Copyright claims
- updated reference dates; - removed reference to Community Edition; - normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/ByteArray.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/ByteArray.js71
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,46 +1,44 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer 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
26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
27 25
28//============================================================================= 26//=============================================================================
29 27
30Clipperz.ByteArray_abstract = function(args) { 28Clipperz.ByteArray_abstract = function(args) {
31 return this; 29 return this;
32} 30}
33 31
34Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { 32Clipperz.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 },
@@ -68,53 +66,50 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, {
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
@@ -123,70 +118,58 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, {
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]);
@@ -271,180 +254,158 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, {
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
@@ -499,49 +460,49 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, {
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) {
@@ -707,49 +668,49 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, {
707//============================================================================= 668//=============================================================================
708// 669//
709 //Clipperz.ByteArray_hex 670 //Clipperz.ByteArray_hex
710// 671//
711//============================================================================= 672//=============================================================================
712/* 673/*
713Clipperz.ByteArray_hex = function (args) { 674Clipperz.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 {
731MochiKit.Logging.logError("Clipperz.ByteArray should be inizialized with an hex string."); 692Clipperz.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
753Clipperz.ByteArray_hex.prototype = MochiKit.Base.update(new Clipperz.ByteArray_abstract(), { 714Clipperz.ByteArray_hex.prototype = MochiKit.Base.update(new Clipperz.ByteArray_abstract(), {
754 715
755 //------------------------------------------------------------------------- 716 //-------------------------------------------------------------------------
@@ -893,49 +854,49 @@ Clipperz.ByteArray_hex.prototype = MochiKit.Base.update(new Clipperz.ByteArray_a
893 854
894//============================================================================= 855//=============================================================================
895// 856//
896 //Clipperz.ByteArray_array 857 //Clipperz.ByteArray_array
897// 858//
898//============================================================================= 859//=============================================================================
899 860
900Clipperz.ByteArray_array = function (args) { 861Clipperz.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 {
917MochiKit.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
@@ -1094,49 +1055,49 @@ Clipperz.ByteArray_array.prototype = MochiKit.Base.update(new Clipperz.ByteArray
1094// 1055//
1095 //Clipperz.ByteArray_string 1056 //Clipperz.ByteArray_string
1096// 1057//
1097//============================================================================= 1058//=============================================================================
1098/* 1059/*
1099Clipperz.ByteArray_string = function (args) { 1060Clipperz.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 {
1118MochiKit.Logging.logError("Clipperz.ByteArray should be inizialized with an hex string."); 1079Clipperz.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
1141Clipperz.ByteArray_string.prototype = MochiKit.Base.update(new Clipperz.ByteArray_abstract(), { 1102Clipperz.ByteArray_string.prototype = MochiKit.Base.update(new Clipperz.ByteArray_abstract(), {
1142 1103