Diffstat (limited to 'frontend/beta/js/Clipperz/ByteArray.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/ByteArray.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/ByteArray.js b/frontend/beta/js/Clipperz/ByteArray.js index a69aa43..540563f 100644 --- a/frontend/beta/js/Clipperz/ByteArray.js +++ b/frontend/beta/js/Clipperz/ByteArray.js | |||
@@ -1,214 +1,212 @@ | |||
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 | 'checkValue': function(aValue) { | 89 | 'checkValue': function(aValue) { |
92 | if ((aValue & 0xff) != aValue) { | 90 | if ((aValue & 0xff) != aValue) { |
93 | MochiKit.Logging.logError("Clipperz.ByteArray.appendByte: the provided value (0x" + aValue.toString(16) + ") is not a byte value."); | 91 | MochiKit.Logging.logError("Clipperz.ByteArray.appendByte: the provided value (0x" + aValue.toString(16) + ") is not a byte value."); |
94 | throw Clipperz.ByteArray.exception.InvalidValue; | 92 | throw Clipperz.ByteArray.exception.InvalidValue; |
95 | } | 93 | } |
96 | }, | 94 | }, |
97 | 95 | ||
98 | //------------------------------------------------------------------------- | 96 | //------------------------------------------------------------------------- |
99 | 97 | ||
100 | 'xorMergeWithBlock': function(aBlock, anAllignment, paddingMode) { | 98 | 'xorMergeWithBlock': function(aBlock, anAllignment, paddingMode) { |
101 | var result; | 99 | var result; |
102 | var a, b; | 100 | var a, b; |
103 | var aLength; | 101 | var aLength; |
104 | var bLength; | 102 | var bLength; |
105 | var i, c; | 103 | var i, c; |
106 | 104 | ||
107 | if (this.length() > aBlock.length()) { | 105 | if (this.length() > aBlock.length()) { |
108 | a = this; | 106 | a = this; |
109 | b = aBlock; | 107 | b = aBlock; |
110 | } else { | 108 | } else { |
111 | a = aBlock; | 109 | a = aBlock; |
112 | b = this; | 110 | b = this; |
113 | } | 111 | } |
114 | 112 | ||
115 | aLength = a.length(); | 113 | aLength = a.length(); |
116 | bLength = b.length(); | 114 | bLength = b.length(); |
117 | 115 | ||
118 | if (aLength != bLength) { | 116 | if (aLength != bLength) { |
119 | if (paddingMode == 'truncate') { | 117 | if (paddingMode == 'truncate') { |
120 | if (anAllignment == 'left') { | 118 | if (anAllignment == 'left') { |
121 | a = a.split(0, bLength); | 119 | a = a.split(0, bLength); |
122 | } else { | 120 | } else { |
123 | a = a.split(aLength - bLength); | 121 | a = a.split(aLength - bLength); |
124 | } | 122 | } |
125 | } else { | 123 | } else { |
126 | var ii, cc; | 124 | var ii, cc; |
127 | var padding; | 125 | var padding; |
128 | 126 | ||
129 | // padding = new Clipperz.ByteArray(); | 127 | // padding = new Clipperz.ByteArray(); |
130 | padding = this.newInstance(); | 128 | padding = this.newInstance(); |
131 | cc = aLength - bLength; | 129 | cc = aLength - bLength; |
132 | for (ii=0; ii<cc; ii++) { | 130 | for (ii=0; ii<cc; ii++) { |
133 | padding.appendByte(0); | 131 | padding.appendByte(0); |
134 | } | 132 | } |
135 | 133 | ||
136 | if (anAllignment == 'left') { | 134 | if (anAllignment == 'left') { |
137 | b = b.appendBlock(padding); | 135 | b = b.appendBlock(padding); |
138 | } else { | 136 | } else { |
139 | b = padding.appendBlock(b); | 137 | b = padding.appendBlock(b); |
140 | } | 138 | } |
141 | } | 139 | } |
142 | } | 140 | } |
143 | 141 | ||
144 | 142 | ||
145 | // result = new Clipperz.ByteArray(); | 143 | // result = new Clipperz.ByteArray(); |
146 | result = this.newInstance(); | 144 | result = this.newInstance(); |
147 | c = a.length(); | 145 | c = a.length(); |
148 | for (i=0; i<c; i++) { | 146 | for (i=0; i<c; i++) { |
149 | result.appendByte(a.byteAtIndex(i) ^ b.byteAtIndex(i)); | 147 | result.appendByte(a.byteAtIndex(i) ^ b.byteAtIndex(i)); |
150 | } | 148 | } |
151 | 149 | ||
152 | return result; | 150 | return result; |
153 | }, | 151 | }, |
154 | 152 | ||
155 | //------------------------------------------------------------------------- | 153 | //------------------------------------------------------------------------- |
156 | /* | 154 | /* |
157 | 'shiftLeft': function(aNumberOfBitsToShift) { | 155 | 'shiftLeft': function(aNumberOfBitsToShift) { |
158 | var result; | 156 | var result; |
159 | 157 | ||
160 | result = this.clone(); //??????????? | 158 | result = this.clone(); //??????????? |
161 | 159 | ||
162 | return result; | 160 | return result; |
163 | }, | 161 | }, |
164 | */ | 162 | */ |
165 | //------------------------------------------------------------------------- | 163 | //------------------------------------------------------------------------- |
166 | 164 | ||
167 | 'appendBlock': function(aBlock) { | 165 | 'appendBlock': function(aBlock) { |
168 | throw Clipperz.Base.exception.AbstractMethod; | 166 | throw Clipperz.Base.exception.AbstractMethod; |
169 | }, | 167 | }, |
170 | 168 | ||
171 | //------------------------------------------------------------------------- | 169 | //------------------------------------------------------------------------- |
172 | 170 | ||
173 | 'appendByte': function(aValue) { | 171 | 'appendByte': function(aValue) { |
174 | throw Clipperz.Base.exception.AbstractMethod; | 172 | throw Clipperz.Base.exception.AbstractMethod; |
175 | }, | 173 | }, |
176 | 174 | ||
177 | 'appendBytes': function(args) { | 175 | 'appendBytes': function(args) { |
178 | varvalues; | 176 | varvalues; |
179 | vari,c; | 177 | vari,c; |
180 | 178 | ||
181 | if (args.constructor == Array) { | 179 | if (args.constructor == Array) { |
182 | values = args; | 180 | values = args; |
183 | } else { | 181 | } else { |
184 | values = arguments; | 182 | values = arguments; |
185 | } | 183 | } |
186 | 184 | ||
187 | c = values.length; | 185 | c = values.length; |
188 | for (i=0; i<c; i++) { | 186 | for (i=0; i<c; i++) { |
189 | this.appendByte(values[i]); | 187 | this.appendByte(values[i]); |
190 | } | 188 | } |
191 | 189 | ||
192 | return this; | 190 | return this; |
193 | }, | 191 | }, |
194 | 192 | ||
195 | //------------------------------------------------------------------------- | 193 | //------------------------------------------------------------------------- |
196 | 194 | ||
197 | 'appendWord': function(aValue, isLittleEndian) { | 195 | 'appendWord': function(aValue, isLittleEndian) { |
198 | var result; | 196 | var result; |
199 | var processAsLittleEndian; | 197 | var processAsLittleEndian; |
200 | 198 | ||
201 | processAsLittleEndian = isLittleEndian === true ? true : false; | 199 | processAsLittleEndian = isLittleEndian === true ? true : false; |
202 | 200 | ||
203 | if (processAsLittleEndian) { | 201 | if (processAsLittleEndian) { |
204 | result = this.appendBytes( (aValue) & 0xff, (aValue >> 8) & 0xff, (aValue >> 16) & 0xff, (aValue >> 24) & 0xff ); //little endian | 202 | result = this.appendBytes( (aValue) & 0xff, (aValue >> 8) & 0xff, (aValue >> 16) & 0xff, (aValue >> 24) & 0xff ); //little endian |
205 | } else { | 203 | } else { |
206 | result = this.appendBytes( (aValue >> 24) & 0xff, (aValue >> 16) & 0xff, (aValue >> 8) & 0xff, (aValue) & 0xff ); //big endian - DEFAULT | 204 | result = this.appendBytes( (aValue >> 24) & 0xff, (aValue >> 16) & 0xff, (aValue >> 8) & 0xff, (aValue) & 0xff ); //big endian - DEFAULT |
207 | } | 205 | } |
208 | 206 | ||
209 | return result; | 207 | return result; |
210 | }, | 208 | }, |
211 | 209 | ||
212 | 'appendWords': function(args) { | 210 | 'appendWords': function(args) { |
213 | varvalues; | 211 | varvalues; |
214 | vari,c; | 212 | vari,c; |