summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/ByteArray.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/ByteArray.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/ByteArray.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/ByteArray.js b/frontend/gamma/js/Clipperz/ByteArray.js
index 86136c8..ae586e7 100644
--- a/frontend/gamma/js/Clipperz/ByteArray.js
+++ b/frontend/gamma/js/Clipperz/ByteArray.js
@@ -1,216 +1,213 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2011 Clipperz Srl
4 4
5This file is part of Clipperz's Javascript Crypto Library. 5This file is part of Clipperz Community Edition.
6Javascript Crypto Library provides web developers with an extensive 6Clipperz Community Edition is an online password manager.
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please 7For further information about its features and functionalities please
11refer to http://www.clipperz.com 8refer to http://www.clipperz.com.
12 9
13* Javascript Crypto Library is free software: you can redistribute 10* Clipperz Community Edition is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public 11 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version 12 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version. 13 3 of the License, or (at your option) any later version.
17 14
18* Javascript Crypto Library is distributed in the hope that it will 15* Clipperz Community Edition is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied 16 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details. 18 See the GNU Affero General Public License for more details.
22 19
23* You should have received a copy of the GNU Affero General Public 20* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see 21 License along with Clipperz Community Edition. If not, see
25 <http://www.gnu.org/licenses/>. 22 <http://www.gnu.org/licenses/>.
26 23
27*/ 24*/
28 25
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30 27
31//============================================================================= 28//=============================================================================
32 29
33Clipperz.ByteArray_abstract = function(args) { 30Clipperz.ByteArray_abstract = function(args) {
34 return this; 31 return this;
35} 32}
36 33
37Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { 34Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, {
38 35
39 //------------------------------------------------------------------------- 36 //-------------------------------------------------------------------------
40 37
41 'toString': function() { 38 'toString': function() {
42 return "Clipperz.ByteArray_abstract"; 39 return "Clipperz.ByteArray_abstract";
43 }, 40 },
44 41
45 //------------------------------------------------------------------------- 42 //-------------------------------------------------------------------------
46 43
47 'equals': function(aValue) { 44 'equals': function(aValue) {
48 return (this.compare(aValue) == 0); 45 return (this.compare(aValue) == 0);
49 }, 46 },
50 47
51 //------------------------------------------------------------------------- 48 //-------------------------------------------------------------------------
52 49
53 'compare': function(aValue) { 50 'compare': function(aValue) {
54 var result; 51 var result;
55 var i; 52 var i;
56 53
57 result = MochiKit.Base.compare(this.length(), aValue.length()); 54 result = MochiKit.Base.compare(this.length(), aValue.length());
58 i = this.length(); 55 i = this.length();
59 56
60 while ((result == 0) && (i>0)) { 57 while ((result == 0) && (i>0)) {
61 i--; 58 i--;
62 result = MochiKit.Base.compare(this.byteAtIndex(i), aValue.byteAtIndex(i)); 59 result = MochiKit.Base.compare(this.byteAtIndex(i), aValue.byteAtIndex(i));
63 } 60 }
64 61
65 return result; 62 return result;
66 }, 63 },
67 64
68 //------------------------------------------------------------------------- 65 //-------------------------------------------------------------------------
69 66
70 'clone': function() { 67 'clone': function() {
71 throw Clipperz.Base.exception.AbstractMethod; 68 throw Clipperz.Base.exception.AbstractMethod;
72 }, 69 },
73 70
74 //------------------------------------------------------------------------- 71 //-------------------------------------------------------------------------
75 72
76 'newInstance': function() { 73 'newInstance': function() {
77 throw Clipperz.Base.exception.AbstractMethod; 74 throw Clipperz.Base.exception.AbstractMethod;
78 }, 75 },
79 76
80 //------------------------------------------------------------------------- 77 //-------------------------------------------------------------------------
81 78
82 'reset': function() { 79 'reset': function() {
83 throw Clipperz.Base.exception.AbstractMethod; 80 throw Clipperz.Base.exception.AbstractMethod;
84 }, 81 },
85 82
86 //------------------------------------------------------------------------- 83 //-------------------------------------------------------------------------
87 84
88 'length': function() { 85 'length': function() {
89 throw Clipperz.Base.exception.AbstractMethod; 86 throw Clipperz.Base.exception.AbstractMethod;
90 }, 87 },
91 88
92 //------------------------------------------------------------------------- 89 //-------------------------------------------------------------------------
93 90
94 'checkByteValue': function(aValue) { 91 'checkByteValue': function(aValue) {
95//Clipperz.log("aValue", aValue.toString(16)); 92//Clipperz.log("aValue", aValue.toString(16));
96//Clipperz.log("(aValue & 0xff)", (aValue & 0xff).toString(16)); 93//Clipperz.log("(aValue & 0xff)", (aValue & 0xff).toString(16));
97 94
98 if ((aValue & 0xff) != aValue) { 95 if ((aValue & 0xff) != aValue) {
99 MochiKit.Logging.logError("Clipperz.ByteArray.appendByte: the provided value (0x" + aValue.toString(16) + ") is not a byte value."); 96 MochiKit.Logging.logError("Clipperz.ByteArray.appendByte: the provided value (0x" + aValue.toString(16) + ") is not a byte value.");
100 throw Clipperz.ByteArray.exception.InvalidValue; 97 throw Clipperz.ByteArray.exception.InvalidValue;
101 } 98 }
102 }, 99 },
103 100
104 //------------------------------------------------------------------------- 101 //-------------------------------------------------------------------------
105 102
106 'xorMergeWithBlock': function(aBlock, anAllignment, paddingMode) { 103 'xorMergeWithBlock': function(aBlock, anAllignment, paddingMode) {
107 var result; 104 var result;
108 var a, b; 105 var a, b;
109 var aLength; 106 var aLength;
110 var bLength; 107 var bLength;
111 var i, c; 108 var i, c;
112 109
113 if (this.length() > aBlock.length()) { 110 if (this.length() > aBlock.length()) {
114 a = this; 111 a = this;
115 b = aBlock; 112 b = aBlock;
116 } else { 113 } else {
117 a = aBlock; 114 a = aBlock;
118 b = this; 115 b = this;
119 } 116 }
120 117
121 aLength = a.length(); 118 aLength = a.length();
122 bLength = b.length(); 119 bLength = b.length();
123 120
124 if (aLength != bLength) { 121 if (aLength != bLength) {
125 if (paddingMode == 'truncate') { 122 if (paddingMode == 'truncate') {
126 if (anAllignment == 'left') { 123 if (anAllignment == 'left') {
127 a = a.split(0, bLength); 124 a = a.split(0, bLength);
128 } else { 125 } else {
129 a = a.split(aLength - bLength); 126 a = a.split(aLength - bLength);
130 } 127 }
131 } else { 128 } else {
132 var ii, cc; 129 var ii, cc;
133 var padding; 130 var padding;
134 131
135 // padding = new Clipperz.ByteArray(); 132 // padding = new Clipperz.ByteArray();
136 padding = this.newInstance(); 133 padding = this.newInstance();
137 cc = aLength - bLength; 134 cc = aLength - bLength;
138 for (ii=0; ii<cc; ii++) { 135 for (ii=0; ii<cc; ii++) {
139 padding.appendByte(0); 136 padding.appendByte(0);
140 } 137 }
141 138
142 if (anAllignment == 'left') { 139 if (anAllignment == 'left') {
143 b = b.appendBlock(padding); 140 b = b.appendBlock(padding);
144 } else { 141 } else {
145 b = padding.appendBlock(b); 142 b = padding.appendBlock(b);
146 } 143 }
147 } 144 }
148 } 145 }
149 146
150 147
151 // result = new Clipperz.ByteArray(); 148 // result = new Clipperz.ByteArray();
152 result = this.newInstance(); 149 result = this.newInstance();
153 c = a.length(); 150 c = a.length();
154 for (i=0; i<c; i++) { 151 for (i=0; i<c; i++) {
155 result.appendByte(a.byteAtIndex(i) ^ b.byteAtIndex(i)); 152 result.appendByte(a.byteAtIndex(i) ^ b.byteAtIndex(i));
156 } 153 }
157 154
158 return result; 155 return result;
159 }, 156 },
160 157
161 //------------------------------------------------------------------------- 158 //-------------------------------------------------------------------------
162/* 159/*
163 'shiftLeft': function(aNumberOfBitsToShift) { 160 'shiftLeft': function(aNumberOfBitsToShift) {
164 var result; 161 var result;
165 162
166 result = this.clone(); //??????????? 163 result = this.clone(); //???????????
167 164
168 return result; 165 return result;
169 }, 166 },
170 */ 167 */
171 //------------------------------------------------------------------------- 168 //-------------------------------------------------------------------------
172 169
173 'appendBlock': function(aBlock) { 170 'appendBlock': function(aBlock) {
174 throw Clipperz.Base.exception.AbstractMethod; 171 throw Clipperz.Base.exception.AbstractMethod;
175 }, 172 },
176 173
177 //------------------------------------------------------------------------- 174 //-------------------------------------------------------------------------
178 175
179 'appendByte': function(aValue) { 176 'appendByte': function(aValue) {
180 throw Clipperz.Base.exception.AbstractMethod; 177 throw Clipperz.Base.exception.AbstractMethod;
181 }, 178 },
182 179
183 'appendBytes': function(args) { 180 'appendBytes': function(args) {
184 varvalues; 181 varvalues;
185 vari,c; 182 vari,c;
186 183
187 if (args.constructor == Array) { 184 if (args.constructor == Array) {
188 values = args; 185 values = args;
189 } else { 186 } else {
190 values = arguments; 187 values = arguments;
191 } 188 }
192 189
193 c = values.length; 190 c = values.length;
194 for (i=0; i<c; i++) { 191 for (i=0; i<c; i++) {
195 this.appendByte(values[i]); 192 this.appendByte(values[i]);
196 } 193 }
197 194
198 return this; 195 return this;
199 }, 196 },
200 197
201 //------------------------------------------------------------------------- 198 //-------------------------------------------------------------------------
202 199
203 'appendWord': function(aValue, isLittleEndian) { 200 'appendWord': function(aValue, isLittleEndian) {
204 var result; 201 var result;
205 var processAsLittleEndian; 202 var processAsLittleEndian;
206 203
207 processAsLittleEndian = isLittleEndian === true ? true : false; 204 processAsLittleEndian = isLittleEndian === true ? true : false;
208 205
209 if (processAsLittleEndian) { 206 if (processAsLittleEndian) {
210 result = this.appendBytes( (aValue) & 0xff, (aValue >> 8) & 0xff, (aValue >> 16) & 0xff, (aValue >> 24) & 0xff ); //little endian 207 result = this.appendBytes( (aValue) & 0xff, (aValue >> 8) & 0xff, (aValue >> 16) & 0xff, (aValue >> 24) & 0xff ); //little endian
211 } else { 208 } else {
212 result = this.appendBytes( (aValue >> 24) & 0xff, (aValue >> 16) & 0xff, (aValue >> 8) & 0xff, (aValue) & 0xff ); //big endian - DEFAULT 209 result = this.appendBytes( (aValue >> 24) & 0xff, (aValue >> 16) & 0xff, (aValue >> 8) & 0xff, (aValue) & 0xff ); //big endian - DEFAULT
213 } 210 }
214 211
215 return result; 212 return result;
216 }, 213 },