Diffstat (limited to 'frontend/gamma/js/Clipperz/ByteArray.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/ByteArray.js | 15 |
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,152 +1,149 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz's Javascript Crypto Library. | 5 | This file is part of Clipperz Community Edition. |
6 | Javascript Crypto Library provides web developers with an extensive | 6 | Clipperz Community Edition is an online password manager. |
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
11 | refer to http://www.clipperz.com | 8 | refer 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 | ||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
30 | 27 | ||
31 | //============================================================================= | 28 | //============================================================================= |
32 | 29 | ||
33 | Clipperz.ByteArray_abstract = function(args) { | 30 | Clipperz.ByteArray_abstract = function(args) { |
34 | return this; | 31 | return this; |
35 | } | 32 | } |
36 | 33 | ||
37 | Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | 34 | Clipperz.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(); |