├── Icon.png ├── LICENSE.txt ├── README.md ├── js └── Clipperz │ ├── Async.js │ ├── Base.js │ ├── ByteArray.js │ ├── Crypto │ ├── AES.js │ ├── Base.js │ ├── BigInt.js │ ├── BigInt_scoped.js │ ├── ECC │ │ ├── BinaryField │ │ │ ├── Curve.js │ │ │ ├── FiniteField.js │ │ │ ├── Point.js │ │ │ └── Value.js │ │ └── StandardCurves.js │ ├── PRNG.js │ ├── RSA.js │ ├── SHA.js │ └── SRP.js │ ├── Logging.js │ └── YUI │ └── Utils.js ├── other_libraries ├── JSON │ └── json2.js └── MochiKit │ ├── Async.js │ ├── Base.js │ ├── Color.js │ ├── DOM.js │ ├── DateTime.js │ ├── DragAndDrop.js │ ├── Format.js │ ├── Iter.js │ ├── LICENSE.txt │ ├── Logging.js │ ├── LoggingPane.js │ ├── MochiKit.js │ ├── MockDOM.js │ ├── Position.js │ ├── Selector.js │ ├── Signal.js │ ├── Sortable.js │ ├── Style.js │ ├── Test.js │ ├── Text.js │ ├── Visual.js │ └── __package__.js └── tests ├── SimpleTest ├── SimpleTest.Async.js ├── SimpleTest.js ├── TestRunner.js └── test.css ├── index.html └── tests ├── Clipperz ├── Async.html ├── Async.test.js ├── Base.html ├── Base.test.js ├── ByteArray.html ├── ByteArray.test.js ├── Crypto │ ├── AES.html │ ├── Base.html │ ├── BigInt.html │ ├── ECC.B283.deferred.html │ ├── ECC.BinaryField.FiniteField.B283.html │ ├── ECC.BinaryField.FiniteField.html │ ├── ECC.BinaryField.Value.html │ ├── ECC.K283.deferred.html │ ├── JSCrypto_vs_Clipperz.html │ ├── JSCrypto_vs_Clipperz.test.js │ ├── PRNG.html │ ├── RSA.html │ ├── SHA.html │ ├── SHA.test.js │ ├── SRP.html │ ├── Usage.html │ ├── index.html │ └── jscrypto.js └── index.html └── index.html /Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clipperz/javascript-crypto-library/e99e9e83dd2321ff6a4457cc2f73c4aec17e6674/Icon.png -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Clipperz Srl 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![Clipperz icon][icon] JAVASCRIPT CRYPTO LIBRARY - by Clipperz 2 | 3 | The JavaScript Crypto Library provides web developers with an extensive and efficient set of cryptographic functions. The library aims to obtain maximum execution speed while preserving modularity and reusability. 4 | 5 | ALL the code included in this project, if not otherwise stated, is released with the **BSD 3-Clause License** (see `LICENSE.txt`), and all rights are reserved to Clipperz Srl. 6 | 7 | For any use not allowed by the license, please [contact us][contact]. 8 | 9 | 10 | ## Features 11 | The Javascript Crypto Library currently includes: 12 | 13 | * AES-256, symmetric encryption; 14 | * Fortuna, a strong pseudo-random number generator; 15 | * SRP, a verifier-based authentication protocol; 16 | * SHA-2, hash function. 17 | 18 | [Clipperz online password manager][clipperz] makes heavy use of the above cryptographic functions. 19 | 20 | Browser cryptography is an critical component for building [zero-knowledge web applications][zkwa], but you can also use it to improve the security of specific portion of your code. As an example, you could consider replacing your present user authentication process with SRP. 21 | 22 | 23 | ## Acknowledgments 24 | 25 | Javascript implementations of cryptographic algorithms have been around for years. Some of the pioneers in this field were: [John Walker][walker], [Chris Veness][veness], [Paul Andrew Johnston][johnston] and [Leemon Baird][baird]. They all realized that Javascript could turn the browser into a new and ubiquitous “number crunching” tool that comes pre-installed on every modern computer. Even if they mostly wrote code for educational purposes, their work was an important inspiration to us. 26 | 27 | 28 | ## Future developments 29 | 30 | Basically we need to make the library more flexible and more powerful. Most functions need parameters for selecting the key length, the encoding options, … 31 | 32 | Public-key cryptography is an area that definitely needs to be covered. The code already includes a first attempt to use elliptic curve cryptography (ECC), but it is still very slow and incomplete. We would love to improve it and develop all the components of a robust public-key cryptographic system based on elliptic curves. It’s an ambitious and complex plan. Any volunteer to help? 33 | 34 | 35 | ## Contributions 36 | 37 | Your contributions to the Javascript Crypto Library are very welcome! In order to avoid jeopardizing the ownership of the code base, we will require every developer to sign the Clipperz [Contributor Agreement][CA] 38 | 39 | This enables a single entity to represent the aggregated code base and gives the community flexibility to act as a whole to changing situations. 40 | 41 | The CA establishes a joint copyright assignment in which the contributor retains copyright ownership while also granting those rights to Clipperz Srl. With the CA in place, the aggregated code base within any Clipperz open source project is protected by both the distribution license and copyright law. 42 | 43 | Please [download][CA] and review the Contributor Agreement for a complete understanding of its terms and conditions. You may send your signed and completed CA to Clipperz by scanning your completed form and emailing the image or by fax. Please retain a copy for your records. **Thanks!** 44 | 45 | [icon]: http://0.gravatar.com/avatar/2a9fae49ced80a42830a206f88ea1022?size=100 46 | [clipperz]: https://clipperz.is 47 | [contact]: https://clipperz.is/contact 48 | [zkwa]: https://clipperz.is/users/marco/blog/2007/08/24/anatomy_zero_knowledge_web_application 49 | [walker]: http://www.fourmilab.ch/javascrypt/ 50 | [veness]: http://www.movable-type.co.uk/ 51 | [johnston]: http://pajhome.org.uk/ 52 | [baird]: http://www.leemon.com 53 | [CA]: https://clipperz.is/contributor_agreement/ 54 | 55 | -------------------------------------------------------------------------------- /js/Clipperz/Crypto/ECC/BinaryField/Point.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { 24 | // throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; 25 | //} 26 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } 27 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } 28 | 29 | Clipperz.Crypto.ECC.BinaryField.Point = function(args) { 30 | args = args || {}; 31 | this._x = args.x; 32 | this._y = args.y; 33 | 34 | return this; 35 | } 36 | 37 | Clipperz.Crypto.ECC.BinaryField.Point.prototype = MochiKit.Base.update(null, { 38 | 39 | 'asString': function() { 40 | return "Clipperz.Crypto.ECC.BinaryField.Point (" + this.x() + ", " + this.y() + ")"; 41 | }, 42 | 43 | //----------------------------------------------------------------------------- 44 | 45 | 'x': function() { 46 | return this._x; 47 | }, 48 | 49 | 'y': function() { 50 | return this._y; 51 | }, 52 | 53 | //----------------------------------------------------------------------------- 54 | 55 | 'isZero': function() { 56 | return (this.x().isZero() && this.y().isZero()) 57 | }, 58 | 59 | //----------------------------------------------------------------------------- 60 | __syntaxFix__: "syntax fix" 61 | }); 62 | -------------------------------------------------------------------------------- /js/Clipperz/Crypto/ECC/BinaryField/Value.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | //try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { 24 | // throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; 25 | //} 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 27 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } 28 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } 29 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } 30 | 31 | Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase, aBitSize) { 32 | if (aValue.constructor == String) { 33 | var value; 34 | var stringLength; 35 | var numberOfWords; 36 | var i,c; 37 | 38 | if (aBase != 16) { 39 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; 40 | } 41 | 42 | value = aValue.replace(/ /g, ''); 43 | stringLength = value.length; 44 | numberOfWords = Math.ceil(stringLength / 8); 45 | this._value = new Array(numberOfWords); 46 | 47 | c = numberOfWords; 48 | for (i=0; i>> 0); 194 | } 195 | 196 | return result; 197 | }; 198 | 199 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteXor = function(a, b, aFirstItemOffset) { 200 | var i,c; 201 | var firstItemOffset; 202 | 203 | firstItemOffset = aFirstItemOffset || 0; 204 | 205 | c = Math.max((a.length - firstItemOffset), b.length) + firstItemOffset; 206 | for (i=firstItemOffset; i>> 0); 208 | } 209 | }; 210 | 211 | Clipperz.Crypto.ECC.BinaryField.Value._shiftLeft = function(aWordArray, aNumberOfBitsToShift) { 212 | var numberOfWordsToShift; 213 | var numberOfBitsToShift; 214 | var result; 215 | var overflowValue; 216 | var nextOverflowValue; 217 | var i,c; 218 | 219 | numberOfWordsToShift = Math.floor(aNumberOfBitsToShift / 32); 220 | numberOfBitsToShift = aNumberOfBitsToShift % 32; 221 | 222 | result = new Array(aWordArray.length + numberOfWordsToShift); 223 | 224 | c = numberOfWordsToShift; 225 | for (i=0; i 0) { 241 | nextOverflowValue = (value >>> (32 - numberOfBitsToShift)); 242 | value = value & (0xffffffff >>> numberOfBitsToShift); 243 | resultWord = (((value << numberOfBitsToShift) | overflowValue) >>> 0); 244 | } else { 245 | resultWord = value; 246 | } 247 | 248 | result[i+numberOfWordsToShift] = resultWord; 249 | overflowValue = nextOverflowValue; 250 | } 251 | 252 | if (overflowValue != 0) { 253 | result[aWordArray.length + numberOfWordsToShift] = overflowValue; 254 | } 255 | 256 | return result; 257 | }; 258 | 259 | Clipperz.Crypto.ECC.BinaryField.Value._overwriteShiftLeft = function(aWordArray, aNumberOfBitsToShift) { 260 | var numberOfWordsToShift; 261 | var numberOfBitsToShift; 262 | var result; 263 | var overflowValue; 264 | var i,c; 265 | 266 | numberOfWordsToShift = Math.floor(aNumberOfBitsToShift / 32); 267 | numberOfBitsToShift = aNumberOfBitsToShift % 32; 268 | 269 | result = new Array(aWordArray.length + numberOfWordsToShift); 270 | 271 | c = numberOfWordsToShift; 272 | for (i=0; i 0) { 288 | var nextOverflowValue; 289 | 290 | nextOverflowValue = (value >>> (32 - numberOfBitsToShift)); 291 | value = value & (0xffffffff >>> numberOfBitsToShift); 292 | resultWord = (((value << numberOfBitsToShift) | overflowValue) >>> 0); 293 | } else { 294 | resultWord = value; 295 | } 296 | 297 | result[i+numberOfWordsToShift] = resultWord; 298 | overflowValue = nextOverflowValue; 299 | } 300 | 301 | if (overflowValue != 0) { 302 | result[aWordArray.length + numberOfWordsToShift] = overflowValue; 303 | } 304 | 305 | return result; 306 | }; 307 | 308 | Clipperz.Crypto.ECC.BinaryField.Value._bitSize = function(aWordArray) { 309 | var result; 310 | var notNullElements; 311 | var mostValuableWord; 312 | var matchingBitsInMostImportantWord; 313 | var mask; 314 | var i,c; 315 | 316 | notNullElements = aWordArray.length; 317 | 318 | if ((aWordArray.length == 1) && (aWordArray[0] == 0)) { 319 | result = 0; 320 | } else { 321 | notNullElements --; 322 | while((notNullElements > 0) && (aWordArray[notNullElements] == 0)) { 323 | notNullElements --; 324 | } 325 | 326 | result = notNullElements * 32; 327 | mostValuableWord = aWordArray[notNullElements]; 328 | 329 | matchingBits = 32; 330 | mask = 0x80000000; 331 | 332 | while ((matchingBits > 0) && ((mostValuableWord & mask) == 0)) { 333 | matchingBits --; 334 | mask >>>= 1; 335 | } 336 | 337 | result += matchingBits; 338 | } 339 | 340 | return result; 341 | }; 342 | 343 | Clipperz.Crypto.ECC.BinaryField.Value._isBitSet = function(aWordArray, aBitPosition) { 344 | var result; 345 | var byteIndex; 346 | var bitIndexInSelectedByte; 347 | 348 | byteIndex = Math.floor(aBitPosition / 32); 349 | bitIndexInSelectedByte = aBitPosition % 32; 350 | 351 | if (byteIndex <= aWordArray.length) { 352 | result = ((aWordArray[byteIndex] & (1 << bitIndexInSelectedByte)) != 0); 353 | } else { 354 | result = false; 355 | } 356 | 357 | return result; 358 | }; 359 | 360 | Clipperz.Crypto.ECC.BinaryField.Value._compare = function(a,b) { 361 | var result; 362 | var i,c; 363 | 364 | result = MochiKit.Base.compare(a.length, b.length); 365 | 366 | c = a.length; 367 | for (i=0; (i. 19 | 20 | */ 21 | 22 | 23 | //try { if (typeof(Clipperz.Crypto.ECC.BinaryField.Curve) == 'undefined') { throw ""; }} catch (e) { 24 | // throw "Clipperz.Crypto.ECC depends on Clipperz.Crypto.ECC.BinaryField.Curve!"; 25 | //} 26 | //try { if (typeof(Clipperz.Crypto.ECC.Koblitz.Curve) == 'undefined') { throw ""; }} catch (e) { 27 | // throw "Clipperz.Crypto.ECC depends on Clipperz.Crypto.ECC.Koblitz.Curve!"; 28 | //} 29 | 30 | Clipperz.Crypto.ECC.StandardCurves = {}; 31 | 32 | MochiKit.Base.update(Clipperz.Crypto.ECC.StandardCurves, { 33 | 34 | //============================================================================== 35 | 36 | '_K571': null, 37 | 'K571': function() { // f(z) = z^571 + z^10 + z^5 + z^2 + 1 38 | if ((Clipperz.Crypto.ECC.StandardCurves._K571 == null) && (typeof(Clipperz.Crypto.ECC.Koblitz.Curve) != 'undefined')) { 39 | Clipperz.Crypto.ECC.StandardCurves._K571 = new Clipperz.Crypto.ECC.Koblitz.Curve({ 40 | modulus: new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000425', 16), 41 | a: new Clipperz.Crypto.ECC.Koblitz.Value('0', 16), 42 | b: new Clipperz.Crypto.ECC.Koblitz.Value('1', 16), 43 | G: new Clipperz.Crypto.ECC.Koblitz.Point({ 44 | x: new Clipperz.Crypto.ECC.Koblitz.Value('026eb7a8 59923fbc 82189631 f8103fe4 ac9ca297 0012d5d4 60248048 01841ca4 43709584 93b205e6 47da304d b4ceb08c bbd1ba39 494776fb 988b4717 4dca88c7 e2945283 a01c8972', 16), 45 | y: new Clipperz.Crypto.ECC.Koblitz.Value('0349dc80 7f4fbf37 4f4aeade 3bca9531 4dd58cec 9f307a54 ffc61efc 006d8a2c 9d4979c0 ac44aea7 4fbebbb9 f772aedc b620b01a 7ba7af1b 320430c8 591984f6 01cd4c14 3ef1c7a3', 16) 46 | }), 47 | r: new Clipperz.Crypto.ECC.Koblitz.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16), 48 | h: new Clipperz.Crypto.ECC.Koblitz.Value('4', 16), 49 | primeFactor: new Clipperz.Crypto.ECC.Koblitz.Value('02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 131850e1 f19a63e4 b391a8db 917f4138 b630d84b e5d63938 1e91deb4 5cfe778f 637c1001', 16) 50 | }); 51 | } 52 | 53 | return Clipperz.Crypto.ECC.StandardCurves._K571; 54 | }, 55 | 56 | //----------------------------------------------------------------------------- 57 | 58 | '_K283': null, 59 | 'K283': function() { // f(z) = z^283 + z^12 + z^7 + z^5 + 1 60 | if ((Clipperz.Crypto.ECC.StandardCurves._K283 == null) && (typeof(Clipperz.Crypto.ECC.Koblitz.Curve) != 'undefined')) { 61 | Clipperz.Crypto.ECC.StandardCurves._K283 = new Clipperz.Crypto.ECC.Koblitz.Curve({ 62 | modulus: new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), 63 | a: new Clipperz.Crypto.ECC.Koblitz.Value('0', 16), 64 | b: new Clipperz.Crypto.ECC.Koblitz.Value('1', 16), 65 | G: new Clipperz.Crypto.ECC.Koblitz.Point({ 66 | x: new Clipperz.Crypto.ECC.Koblitz.Value('0503213f 78ca4488 3f1a3b81 62f188e5 53cd265f 23c1567a 16876913 b0c2ac24 58492836', 16), 67 | y: new Clipperz.Crypto.ECC.Koblitz.Value('01ccda38 0f1c9e31 8d90f95d 07e5426f e87e45c0 e8184698 e4596236 4e341161 77dd2259', 16) 68 | }), 69 | r: new Clipperz.Crypto.ECC.Koblitz.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16), 70 | h: new Clipperz.Crypto.ECC.Koblitz.Value('4', 16), 71 | primeFactor: new Clipperz.Crypto.ECC.Koblitz.Value('01ffffff ffffffff ffffffff ffffffff ffffe9ae 2ed07577 265dff7f 94451e06 1e163c61', 16) 72 | }); 73 | } 74 | 75 | return Clipperz.Crypto.ECC.StandardCurves._K283; 76 | }, 77 | 78 | //============================================================================== 79 | 80 | '_B571': null, 81 | 'B571': function() { // f(z) = z^571 + z^10 + z^5 + z^2 + 1 82 | if ((Clipperz.Crypto.ECC.StandardCurves._B571 == null) && (typeof(Clipperz.Crypto.ECC.BinaryField.Curve) != 'undefined')) { 83 | Clipperz.Crypto.ECC.StandardCurves._B571 = new Clipperz.Crypto.ECC.BinaryField.Curve({ 84 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000425', 16), 85 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), 86 | b: new Clipperz.Crypto.ECC.BinaryField.Value('02f40e7e 2221f295 de297117 b7f3d62f 5c6a97ff cb8ceff1 cd6ba8ce 4a9a18ad 84ffabbd 8efa5933 2be7ad67 56a66e29 4afd185a 78ff12aa 520e4de7 39baca0c 7ffeff7f 2955727a', 16), 87 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ 88 | x: new Clipperz.Crypto.ECC.BinaryField.Value('0303001d 34b85629 6c16c0d4 0d3cd775 0a93d1d2 955fa80a a5f40fc8 db7b2abd bde53950 f4c0d293 cdd711a3 5b67fb14 99ae6003 8614f139 4abfa3b4 c850d927 e1e7769c 8eec2d19', 16), 89 | y: new Clipperz.Crypto.ECC.BinaryField.Value('037bf273 42da639b 6dccfffe b73d69d7 8c6c27a6 009cbbca 1980f853 3921e8a6 84423e43 bab08a57 6291af8f 461bb2a8 b3531d2f 0485c19b 16e2f151 6e23dd3c 1a4827af 1b8ac15b', 16) 90 | }), 91 | r: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff e661ce18 ff559873 08059b18 6823851e c7dd9ca1 161de93d 5174d66e 8382e9bb 2fe84e47', 16), 92 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) 93 | 94 | // S: new Clipperz.Crypto.ECC.BinaryField.Value('2aa058f73a0e33ab486b0f610410c53a7f132310', 10), 95 | // n: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47', 16) 96 | }); 97 | 98 | //----------------------------------------------------------------------------- 99 | // 100 | // Guide to Elliptic Curve Cryptography 101 | // Darrel Hankerson, Alfred Menezes, Scott Vanstone 102 | // - Pag: 56, Alorithm 2.45 (with a typo!!!) 103 | // 104 | //----------------------------------------------------------------------------- 105 | // 106 | // http://www.milw0rm.com/papers/136 107 | // 108 | // ------------------------------------------------------------------------- 109 | // Polynomial Reduction Algorithm Modulo f571 110 | // ------------------------------------------------------------------------- 111 | // 112 | // Input: Polynomial p(x) of degree 1140 or less, stored as 113 | // an array of 2T machinewords. 114 | // Output: p(x) mod f571(x) 115 | // 116 | // FOR i = T-1, ..., 0 DO 117 | // SET X := P[i+T] 118 | // P[i] := P[i] ^ (X<<5) ^ (X<<7) ^ (X<<10) ^ (X<<15) 119 | // P[i+1] := P[i+1] ^ (X>>17) ^ (X>>22) ^ (X>>25) ^ (X>>27) 120 | // 121 | // SET X := P[T-1] >> 27 122 | // P[0] := P[0] ^ X ^ (X<<2) ^ (X<<5) ^ (X<<10) 123 | // P[T-1] := P[T-1] & 0x07ffffff 124 | // 125 | // RETURN P[T-1],...,P[0] 126 | // 127 | // ------------------------------------------------------------------------- 128 | // 129 | Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().slowModule = Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().module; 130 | Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().module = function(aValue) { 131 | var result; 132 | 133 | if (aValue.bitSize() > 1140) { 134 | MochiKit.Logging.logWarning("ECC.StandarCurves.B571.finiteField().module: falling back to default implementation"); 135 | result = Clipperz.Crypto.ECC.StandardCurves._B571.finiteField().slowModule(aValue); 136 | } else { 137 | var C, T; 138 | var i; 139 | 140 | //console.log(">>> binaryField.finiteField.(improved)module"); 141 | // C = aValue.value().slice(0); 142 | C = aValue._value.slice(0); 143 | for (i=35; i>=18; i--) { 144 | T = C[i]; 145 | C[i-18] = (((C[i-18] ^ (T<<5) ^ (T<<7) ^ (T<<10) ^ (T<<15)) & 0xffffffff) >>> 0); 146 | C[i-17] = ((C[i-17] ^ (T>>>27) ^ (T>>>25) ^ (T>>>22) ^ (T>>>17)) >>> 0); 147 | } 148 | T = (C[17] >>> 27); 149 | C[0] = ((C[0] ^ T ^ ((T<<2) ^ (T<<5) ^ (T<<10)) & 0xffffffff) >>> 0); 150 | C[17] = (C[17] & 0x07ffffff); 151 | 152 | for(i=18; i<=35; i++) { 153 | C[i] = 0; 154 | } 155 | 156 | result = new Clipperz.Crypto.ECC.BinaryField.Value(C); 157 | //console.log("<<< binaryField.finiteField.(improved)module"); 158 | } 159 | 160 | return result; 161 | }; 162 | } 163 | 164 | return Clipperz.Crypto.ECC.StandardCurves._B571; 165 | }, 166 | 167 | //----------------------------------------------------------------------------- 168 | 169 | '_B283': null, 170 | 'B283': function() { // f(z) = z^283 + z^12 + z^7 + z^5 + 1 171 | if ((Clipperz.Crypto.ECC.StandardCurves._B283 == null) && (typeof(Clipperz.Crypto.ECC.BinaryField.Curve) != 'undefined')) { 172 | Clipperz.Crypto.ECC.StandardCurves._B283 = new Clipperz.Crypto.ECC.BinaryField.Curve({ 173 | modulus: new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16), 174 | a: new Clipperz.Crypto.ECC.BinaryField.Value('1', 16), 175 | b: new Clipperz.Crypto.ECC.BinaryField.Value('027b680a c8b8596d a5a4af8a 19a0303f ca97fd76 45309fa2 a581485a f6263e31 3b79a2f5', 16), 176 | G: new Clipperz.Crypto.ECC.BinaryField.Point({ 177 | x: new Clipperz.Crypto.ECC.BinaryField.Value('05f93925 8db7dd90 e1934f8c 70b0dfec 2eed25b8 557eac9c 80e2e198 f8cdbecd 86b12053', 16), 178 | y: new Clipperz.Crypto.ECC.BinaryField.Value('03676854 fe24141c b98fe6d4 b20d02b4 516ff702 350eddb0 826779c8 13f0df45 be8112f4', 16) 179 | }), 180 | r: new Clipperz.Crypto.ECC.BinaryField.Value('03ffffff ffffffff ffffffff ffffffff ffffef90 399660fc 938a9016 5b042a7c efadb307', 16), 181 | h: new Clipperz.Crypto.ECC.BinaryField.Value('2', 16) 182 | }); 183 | 184 | //----------------------------------------------------------------------------- 185 | // 186 | // Guide to Elliptic Curve Cryptography 187 | // Darrel Hankerson, Alfred Menezes, Scott Vanstone 188 | // - Pag: 56, Alorithm 2.43 189 | // 190 | //----------------------------------------------------------------------------- 191 | Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().slowModule = Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().module; 192 | Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().module = function(aValue) { 193 | var result; 194 | 195 | if (aValue.bitSize() > 564) { 196 | MochiKit.Logging.logWarning("ECC.StandarCurves.B283.finiteField().module: falling back to default implementation"); 197 | result = Clipperz.Crypto.ECC.StandardCurves._B283.finiteField().slowModule(aValue); 198 | } else { 199 | var C, T; 200 | var i; 201 | 202 | //console.log(">>> binaryField.finiteField.(improved)module"); 203 | C = aValue._value.slice(0); 204 | for (i=17; i>=9; i--) { 205 | T = C[i]; 206 | C[i-9] = (((C[i-9] ^ (T<<5) ^ (T<<10) ^ (T<<12) ^ (T<<17)) & 0xffffffff) >>> 0); 207 | C[i-8] = ((C[i-8] ^ (T>>>27) ^ (T>>>22) ^ (T>>>20) ^ (T>>>15)) >>> 0); 208 | } 209 | T = (C[8] >>> 27); 210 | C[0] = ((C[0] ^ T ^ ((T<<5) ^ (T<<7) ^ (T<<12)) & 0xffffffff) >>> 0); 211 | C[8] = (C[8] & 0x07ffffff); 212 | 213 | for(i=9; i<=17; i++) { 214 | C[i] = 0; 215 | } 216 | 217 | result = new Clipperz.Crypto.ECC.BinaryField.Value(C); 218 | //console.log("<<< binaryField.finiteField.(improved)module"); 219 | } 220 | 221 | return result; 222 | }; 223 | } 224 | 225 | return Clipperz.Crypto.ECC.StandardCurves._B283; 226 | }, 227 | 228 | //============================================================================== 229 | __syntaxFix__: "syntax fix" 230 | }); 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /js/Clipperz/Crypto/RSA.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { 24 | throw "Clipperz.Crypto.RSA depends on Clipperz.Crypto.BigInt!"; 25 | } 26 | 27 | if (typeof(Clipperz.Crypto.RSA) == 'undefined') { Clipperz.Crypto.RSA = {}; } 28 | 29 | Clipperz.Crypto.RSA.VERSION = "0.1"; 30 | Clipperz.Crypto.RSA.NAME = "Clipperz.RSA"; 31 | 32 | //############################################################################# 33 | 34 | MochiKit.Base.update(Clipperz.Crypto.RSA, { 35 | 36 | //------------------------------------------------------------------------- 37 | 38 | 'publicKeyWithValues': function (e, d, n) { 39 | var result; 40 | 41 | result = {}; 42 | 43 | if (e.isBigInt) { 44 | result.e = e; 45 | } else { 46 | result.e = new Clipperz.Crypto.BigInt(e, 16); 47 | } 48 | 49 | if (d.isBigInt) { 50 | result.d = d; 51 | } else { 52 | result.d = new Clipperz.Crypto.BigInt(d, 16); 53 | } 54 | 55 | if (n.isBigInt) { 56 | result.n = n; 57 | } else { 58 | result.n = new Clipperz.Crypto.BigInt(n, 16); 59 | } 60 | 61 | return result; 62 | }, 63 | 64 | 'privateKeyWithValues': function(e, d, n) { 65 | return Clipperz.Crypto.RSA.publicKeyWithValues(e, d, n); 66 | }, 67 | 68 | //----------------------------------------------------------------------------- 69 | 70 | 'encryptUsingPublicKey': function (aKey, aMessage) { 71 | var messageValue; 72 | var result; 73 | 74 | messageValue = new Clipperz.Crypto.BigInt(aMessage, 16); 75 | result = messageValue.powerModule(aKey.e, aKey.n); 76 | 77 | return result.asString(16); 78 | }, 79 | 80 | //............................................................................. 81 | 82 | 'decryptUsingPublicKey': function (aKey, aMessage) { 83 | return Clipperz.Crypto.RSA.encryptUsingPublicKey(aKey, aMessage); 84 | }, 85 | 86 | //----------------------------------------------------------------------------- 87 | 88 | 'encryptUsingPrivateKey': function (aKey, aMessage) { 89 | var messageValue; 90 | var result; 91 | 92 | messageValue = new Clipperz.Crypto.BigInt(aMessage, 16); 93 | result = messageValue.powerModule(aKey.d, aKey.n); 94 | 95 | return result.asString(16); 96 | }, 97 | 98 | //............................................................................. 99 | 100 | 'decryptUsingPrivateKey': function (aKey, aMessage) { 101 | return Clipperz.Crypto.RSA.encryptUsingPrivateKey(aKey, aMessage); 102 | }, 103 | 104 | //----------------------------------------------------------------------------- 105 | 106 | 'generatePublicKey': function(aNumberOfBits) { 107 | var result; 108 | var e; 109 | var d; 110 | var n; 111 | 112 | e = new Clipperz.Crypto.BigInt("10001", 16); 113 | 114 | { 115 | var p, q; 116 | var phi; 117 | 118 | do { 119 | p = Clipperz.Crypto.BigInt.randomPrime(aNumberOfBits); 120 | } while (p.module(e).equals(1)); 121 | 122 | do { 123 | q = Clipperz.Crypto.BigInt.randomPrime(aNumberOfBits); 124 | } while ((q.equals(p)) || (q.module(e).equals(1))); 125 | 126 | n = p.multiply(q); 127 | phi = (p.subtract(1).multiply(q.subtract(1))); 128 | d = e.powerModule(-1, phi); 129 | } 130 | 131 | result = Clipperz.Crypto.RSA.publicKeyWithValues(e, d, n); 132 | 133 | return result; 134 | }, 135 | 136 | //------------------------------------------------------------------------- 137 | 138 | __syntaxFix__: "syntax fix" 139 | 140 | //------------------------------------------------------------------------- 141 | 142 | }); 143 | 144 | //############################################################################# 145 | 146 | -------------------------------------------------------------------------------- /js/Clipperz/Crypto/SHA.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { 24 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; 25 | } 26 | 27 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } 28 | if (typeof(Clipperz.Crypto.SHA) == 'undefined') { Clipperz.Crypto.SHA = {}; } 29 | 30 | Clipperz.Crypto.SHA.VERSION = "0.3"; 31 | Clipperz.Crypto.SHA.NAME = "Clipperz.Crypto.SHA"; 32 | 33 | MochiKit.Base.update(Clipperz.Crypto.SHA, { 34 | 35 | '__repr__': function () { 36 | return "[" + this.NAME + " " + this.VERSION + "]"; 37 | }, 38 | 39 | 'toString': function () { 40 | return this.__repr__(); 41 | }, 42 | 43 | //----------------------------------------------------------------------------- 44 | 45 | 'rotateRight': function(aValue, aNumberOfBits) { 46 | //Clipperz.Profile.start("Clipperz.Crypto.SHA.rotateRight"); 47 | var result; 48 | 49 | result = (aValue >>> aNumberOfBits) | (aValue << (32 - aNumberOfBits)); 50 | 51 | //Clipperz.Profile.stop("Clipperz.Crypto.SHA.rotateRight"); 52 | return result; 53 | }, 54 | 55 | 'shiftRight': function(aValue, aNumberOfBits) { 56 | //Clipperz.Profile.start("Clipperz.Crypto.SHA.shiftRight"); 57 | var result; 58 | 59 | result = aValue >>> aNumberOfBits; 60 | 61 | //Clipperz.Profile.stop("Clipperz.Crypto.SHA.shiftRight"); 62 | return result; 63 | }, 64 | 65 | //----------------------------------------------------------------------------- 66 | 67 | 'safeAdd': function() { 68 | //Clipperz.Profile.start("Clipperz.Crypto.SHA.safeAdd"); 69 | var result; 70 | var i, c; 71 | 72 | result = arguments[0]; 73 | c = arguments.length; 74 | for (i=1; i> 16) + (arguments[i] >> 16) + (lowerBytesSum >> 16)) << 16) | (lowerBytesSum & 0xffff); 79 | } 80 | 81 | //Clipperz.Profile.stop("Clipperz.Crypto.SHA.safeAdd"); 82 | return result; 83 | }, 84 | 85 | //----------------------------------------------------------------------------- 86 | 87 | 'sha256_array': function(aValue) { 88 | //Clipperz.Profile.start("Clipperz.Crypto.SHA.sha256_array"); 89 | var result; 90 | var message; 91 | var h0, h1, h2, h3, h4, h5, h6, h7; 92 | var k; 93 | var messageLength; 94 | var messageLengthInBits; 95 | var _i, _c; 96 | var charBits; 97 | var rotateRight; 98 | var shiftRight; 99 | var safeAdd; 100 | var bytesPerBlock; 101 | var currentMessageIndex; 102 | 103 | bytesPerBlock = 512/8; 104 | rotateRight = Clipperz.Crypto.SHA.rotateRight; 105 | shiftRight = Clipperz.Crypto.SHA.shiftRight; 106 | safeAdd = Clipperz.Crypto.SHA.safeAdd; 107 | 108 | charBits = 8; 109 | 110 | h0 = 0x6a09e667; 111 | h1 = 0xbb67ae85; 112 | h2 = 0x3c6ef372; 113 | h3 = 0xa54ff53a; 114 | h4 = 0x510e527f; 115 | h5 = 0x9b05688c; 116 | h6 = 0x1f83d9ab; 117 | h7 = 0x5be0cd19; 118 | 119 | k = [ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 120 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 121 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 122 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 123 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 124 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 125 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 126 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2]; 127 | 128 | message = aValue; 129 | messageLength = message.length; 130 | 131 | //Pre-processing: 132 | message.push(0x80); // append a single "1" bit to message 133 | 134 | _c = (512 - (((messageLength + 1) * charBits) % 512) - 64) / charBits; 135 | if (_c < 0) { 136 | _c = _c + (512 / charBits); 137 | } 138 | 139 | for (_i=0; _i<_c; _i++) { 140 | message.push(0x00); // append "0" bits until message length ≡ 448 ≡ -64 (mod 512) 141 | } 142 | 143 | messageLengthInBits = messageLength * charBits; 144 | message.push(0x00); // the 4 most high byte are alway 0 as message length is represented with a 32bit value; 145 | message.push(0x00); 146 | message.push(0x00); 147 | message.push(0x00); 148 | message.push((messageLengthInBits >> 24) & 0xff); 149 | message.push((messageLengthInBits >> 16) & 0xff); 150 | message.push((messageLengthInBits >> 8) & 0xff); 151 | message.push( messageLengthInBits & 0xff); 152 | 153 | currentMessageIndex = 0; 154 | while(currentMessageIndex < message.length) { 155 | var w; 156 | var a, b, c, d, e, f, g, h; 157 | 158 | w = Array(64); 159 | 160 | _c = 16; 161 | for (_i=0; _i<_c; _i++) { 162 | var _j; 163 | 164 | _j = currentMessageIndex + _i*4; 165 | w[_i] = (message[_j] << 24) | (message[_j + 1] << 16) | (message[_j + 2] << 8) | (message[_j + 3] << 0); 166 | } 167 | 168 | _c = 64; 169 | for (_i=16; _i<_c; _i++) { 170 | var s0, s1; 171 | 172 | s0 = (rotateRight(w[_i-15], 7)) ^ (rotateRight(w[_i-15], 18)) ^ (shiftRight(w[_i-15], 3)); 173 | s1 = (rotateRight(w[_i-2], 17)) ^ (rotateRight(w[_i-2], 19)) ^ (shiftRight(w[_i-2], 10)); 174 | w[_i] = safeAdd(w[_i-16], s0, w[_i-7], s1); 175 | } 176 | 177 | a=h0; b=h1; c=h2; d=h3; e=h4; f=h5; g=h6; h=h7; 178 | 179 | _c = 64; 180 | for (_i=0; _i<_c; _i++) { 181 | var s0, s1, ch, maj, t1, t2; 182 | 183 | s0 = (rotateRight(a, 2)) ^ (rotateRight(a, 13)) ^ (rotateRight(a, 22)); 184 | maj = (a & b) ^ (a & c) ^ (b & c); 185 | t2 = safeAdd(s0, maj); 186 | s1 = (rotateRight(e, 6)) ^ (rotateRight(e, 11)) ^ (rotateRight(e, 25)); 187 | ch = (e & f) ^ ((~e) & g); 188 | t1 = safeAdd(h, s1, ch, k[_i], w[_i]); 189 | 190 | h = g; 191 | g = f; 192 | f = e; 193 | e = safeAdd(d, t1); 194 | d = c; 195 | c = b; 196 | b = a; 197 | a = safeAdd(t1, t2); 198 | } 199 | 200 | h0 = safeAdd(h0, a); 201 | h1 = safeAdd(h1, b); 202 | h2 = safeAdd(h2, c); 203 | h3 = safeAdd(h3, d); 204 | h4 = safeAdd(h4, e); 205 | h5 = safeAdd(h5, f); 206 | h6 = safeAdd(h6, g); 207 | h7 = safeAdd(h7, h); 208 | 209 | currentMessageIndex += bytesPerBlock; 210 | } 211 | 212 | result = new Array(256/8); 213 | result[0] = (h0 >> 24) & 0xff; 214 | result[1] = (h0 >> 16) & 0xff; 215 | result[2] = (h0 >> 8) & 0xff; 216 | result[3] = h0 & 0xff; 217 | 218 | result[4] = (h1 >> 24) & 0xff; 219 | result[5] = (h1 >> 16) & 0xff; 220 | result[6] = (h1 >> 8) & 0xff; 221 | result[7] = h1 & 0xff; 222 | 223 | result[8] = (h2 >> 24) & 0xff; 224 | result[9] = (h2 >> 16) & 0xff; 225 | result[10] = (h2 >> 8) & 0xff; 226 | result[11] = h2 & 0xff; 227 | 228 | result[12] = (h3 >> 24) & 0xff; 229 | result[13] = (h3 >> 16) & 0xff; 230 | result[14] = (h3 >> 8) & 0xff; 231 | result[15] = h3 & 0xff; 232 | 233 | result[16] = (h4 >> 24) & 0xff; 234 | result[17] = (h4 >> 16) & 0xff; 235 | result[18] = (h4 >> 8) & 0xff; 236 | result[19] = h4 & 0xff; 237 | 238 | result[20] = (h5 >> 24) & 0xff; 239 | result[21] = (h5 >> 16) & 0xff; 240 | result[22] = (h5 >> 8) & 0xff; 241 | result[23] = h5 & 0xff; 242 | 243 | result[24] = (h6 >> 24) & 0xff; 244 | result[25] = (h6 >> 16) & 0xff; 245 | result[26] = (h6 >> 8) & 0xff; 246 | result[27] = h6 & 0xff; 247 | 248 | result[28] = (h7 >> 24) & 0xff; 249 | result[29] = (h7 >> 16) & 0xff; 250 | result[30] = (h7 >> 8) & 0xff; 251 | result[31] = h7 & 0xff; 252 | 253 | //Clipperz.Profile.stop("Clipperz.Crypto.SHA.sha256_array"); 254 | return result; 255 | }, 256 | 257 | //----------------------------------------------------------------------------- 258 | 259 | 'sha256': function(aValue) { 260 | //Clipperz.Profile.start("Clipperz.Crypto.SHA.sha256"); 261 | var result; 262 | var resultArray; 263 | var valueArray; 264 | 265 | valueArray = aValue.arrayValues(); 266 | resultArray = Clipperz.Crypto.SHA.sha256_array(valueArray); 267 | 268 | result = new Clipperz.ByteArray(resultArray); 269 | 270 | //Clipperz.Profile.stop("Clipperz.Crypto.SHA.sha256"); 271 | return result; 272 | }, 273 | 274 | //----------------------------------------------------------------------------- 275 | 276 | 'sha_d256': function(aValue) { 277 | //Clipperz.Profile.start("Clipperz.Crypto.SHA.sha_d256"); 278 | var result; 279 | var resultArray; 280 | var valueArray; 281 | 282 | valueArray = aValue.arrayValues(); 283 | resultArray = Clipperz.Crypto.SHA.sha256_array(valueArray); 284 | resultArray = Clipperz.Crypto.SHA.sha256_array(resultArray); 285 | 286 | result = new Clipperz.ByteArray(resultArray); 287 | 288 | //Clipperz.Profile.stop("Clipperz.Crypto.SHA.sha256"); 289 | return result; 290 | }, 291 | 292 | //----------------------------------------------------------------------------- 293 | __syntaxFix__: "syntax fix" 294 | 295 | }); 296 | -------------------------------------------------------------------------------- /js/Clipperz/Crypto/SRP.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { 24 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; 25 | } 26 | 27 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { 28 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.BigInt!"; 29 | } 30 | 31 | try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { 32 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.PRNG!"; 33 | } 34 | 35 | if (typeof(Clipperz.Crypto.SRP) == 'undefined') { Clipperz.Crypto.SRP = {}; } 36 | 37 | Clipperz.Crypto.SRP.VERSION = "0.1"; 38 | Clipperz.Crypto.SRP.NAME = "Clipperz.Crypto.SRP"; 39 | 40 | //############################################################################# 41 | 42 | MochiKit.Base.update(Clipperz.Crypto.SRP, { 43 | 44 | '_n': null, 45 | '_g': null, 46 | //------------------------------------------------------------------------- 47 | 48 | 'n': function() { 49 | if (Clipperz.Crypto.SRP._n == null) { 50 | Clipperz.Crypto.SRP._n = new Clipperz.Crypto.BigInt("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); 51 | } 52 | 53 | return Clipperz.Crypto.SRP._n; 54 | }, 55 | 56 | //------------------------------------------------------------------------- 57 | 58 | 'g': function() { 59 | if (Clipperz.Crypto.SRP._g == null) { 60 | Clipperz.Crypto.SRP._g = new Clipperz.Crypto.BigInt(2); // eventually 5 (as suggested on the Diffi-Helmann documentation) 61 | } 62 | 63 | return Clipperz.Crypto.SRP._g; 64 | }, 65 | 66 | //----------------------------------------------------------------------------- 67 | 68 | 'exception': { 69 | 'InvalidValue': new MochiKit.Base.NamedError("Clipperz.Crypto.SRP.exception.InvalidValue") 70 | }, 71 | 72 | //------------------------------------------------------------------------- 73 | __syntaxFix__: "syntax fix" 74 | 75 | }); 76 | 77 | //############################################################################# 78 | // 79 | // S R P C o n n e c t i o n version 1.0 80 | // 81 | //============================================================================= 82 | Clipperz.Crypto.SRP.Connection = function (args) { 83 | args = args || {}; 84 | 85 | this._C = args.C; 86 | this._P = args.P; 87 | this.hash = args.hash; 88 | 89 | this._a = null; 90 | this._A = null; 91 | 92 | this._s = null; 93 | this._B = null; 94 | 95 | this._x = null; 96 | 97 | this._u = null; 98 | this._K = null; 99 | this._M1 = null; 100 | this._M2 = null; 101 | 102 | this._sessionKey = null; 103 | 104 | return this; 105 | } 106 | 107 | Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, { 108 | 109 | 'toString': function () { 110 | return "Clipperz.Crypto.SRP.Connection (username: " + this.username() + "). Status: " + this.statusDescription(); 111 | }, 112 | 113 | //------------------------------------------------------------------------- 114 | 115 | 'C': function () { 116 | return this._C; 117 | }, 118 | 119 | //------------------------------------------------------------------------- 120 | 121 | 'P': function () { 122 | return this._P; 123 | }, 124 | 125 | //------------------------------------------------------------------------- 126 | 127 | 'a': function () { 128 | if (this._a == null) { 129 | this._a = new Clipperz.Crypto.BigInt(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2), 16); 130 | // this._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10); 131 | //MochiKit.Logging.logDebug("SRP a: " + this._a); 132 | } 133 | 134 | return this._a; 135 | }, 136 | 137 | //------------------------------------------------------------------------- 138 | 139 | 'A': function () { 140 | if (this._A == null) { 141 | // Warning: this value should be strictly greater than zero: how should we perform this check? 142 | this._A = Clipperz.Crypto.SRP.g().powerModule(this.a(), Clipperz.Crypto.SRP.n()); 143 | 144 | if (this._A.equals(0)) { 145 | MochiKit.Logging.logError("Clipperz.Crypto.SRP.Connection: trying to set 'A' to 0."); 146 | throw Clipperz.Crypto.SRP.exception.InvalidValue; 147 | } 148 | //MochiKit.Logging.logDebug("SRP A: " + this._A); 149 | } 150 | 151 | return this._A; 152 | }, 153 | 154 | //------------------------------------------------------------------------- 155 | 156 | 's': function () { 157 | return this._s; 158 | //MochiKit.Logging.logDebug("SRP s: " + this._S); 159 | }, 160 | 161 | 'set_s': function(aValue) { 162 | this._s = aValue; 163 | }, 164 | 165 | //------------------------------------------------------------------------- 166 | 167 | 'B': function () { 168 | return this._B; 169 | }, 170 | 171 | 'set_B': function(aValue) { 172 | // Warning: this value should be strictly greater than zero: how should we perform this check? 173 | if (! aValue.equals(0)) { 174 | this._B = aValue; 175 | //MochiKit.Logging.logDebug("SRP B: " + this._B); 176 | } else { 177 | MochiKit.Logging.logError("Clipperz.Crypto.SRP.Connection: trying to set 'B' to 0."); 178 | throw Clipperz.Crypto.SRP.exception.InvalidValue; 179 | } 180 | }, 181 | 182 | //------------------------------------------------------------------------- 183 | 184 | 'x': function () { 185 | if (this._x == null) { 186 | this._x = new Clipperz.Crypto.BigInt(this.stringHash(this.s().asString(16, 64) + this.P()), 16); 187 | //MochiKit.Logging.logDebug("SRP x: " + this._x); 188 | } 189 | 190 | return this._x; 191 | }, 192 | 193 | //------------------------------------------------------------------------- 194 | 195 | 'u': function () { 196 | if (this._u == null) { 197 | this._u = new Clipperz.Crypto.BigInt(this.stringHash(this.B().asString()), 16); 198 | //MochiKit.Logging.logDebug("SRP u: " + this._u); 199 | } 200 | 201 | return this._u; 202 | }, 203 | 204 | //------------------------------------------------------------------------- 205 | 206 | 'S': function () { 207 | if (this._S == null) { 208 | var bigint; 209 | var srp; 210 | 211 | bigint = Clipperz.Crypto.BigInt; 212 | srp = Clipperz.Crypto.SRP; 213 | 214 | this._S = bigint.powerModule( 215 | bigint.subtract(this.B(), bigint.powerModule(srp.g(), this.x(), srp.n())), 216 | bigint.add(this.a(), bigint.multiply(this.u(), this.x())), 217 | srp.n() 218 | ) 219 | //MochiKit.Logging.logDebug("SRP S: " + this._S); 220 | } 221 | 222 | return this._S; 223 | }, 224 | 225 | //------------------------------------------------------------------------- 226 | 227 | 'K': function () { 228 | if (this._K == null) { 229 | this._K = this.stringHash(this.S().asString()); 230 | //MochiKit.Logging.logDebug("SRP K: " + this._K); 231 | } 232 | 233 | return this._K; 234 | }, 235 | 236 | //------------------------------------------------------------------------- 237 | 238 | 'M1': function () { 239 | if (this._M1 == null) { 240 | this._M1 = this.stringHash(this.A().asString(10) + this.B().asString(10) + this.K()); 241 | //MochiKit.Logging.logDebug("SRP M1: " + this._M1); 242 | } 243 | 244 | return this._M1; 245 | }, 246 | 247 | //------------------------------------------------------------------------- 248 | 249 | 'M2': function () { 250 | if (this._M2 == null) { 251 | this._M2 = this.stringHash(this.A().asString(10) + this.M1() + this.K()); 252 | //MochiKit.Logging.logDebug("SRP M2: " + this._M2); 253 | } 254 | 255 | return this._M2; 256 | }, 257 | 258 | //========================================================================= 259 | 260 | 'serverSideCredentialsWithSalt': function(aSalt) { 261 | var result; 262 | var s, x, v; 263 | 264 | s = aSalt; 265 | x = this.stringHash(s + this.P()); 266 | v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n()); 267 | 268 | result = {}; 269 | result['C'] = this.C(); 270 | result['s'] = s; 271 | result['v'] = v.asString(16); 272 | 273 | return result; 274 | }, 275 | 276 | 'serverSideCredentials': function() { 277 | var result; 278 | var s; 279 | 280 | s = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); 281 | 282 | result = this.serverSideCredentialsWithSalt(s); 283 | 284 | return result; 285 | }, 286 | 287 | //========================================================================= 288 | /* 289 | 'computeServerSide_S': function(b) { 290 | var result; 291 | var v; 292 | var bigint; 293 | var srp; 294 | 295 | bigint = Clipperz.Crypto.BigInt; 296 | srp = Clipperz.Crypto.SRP; 297 | 298 | v = new Clipperz.Crypto.BigInt(srpConnection.serverSideCredentialsWithSalt(this.s().asString(16, 64)).v, 16); 299 | // _S = (this.A().multiply(this.v().modPow(this.u(), this.n()))).modPow(this.b(), this.n()); 300 | result = bigint.powerModule( 301 | bigint.multiply( 302 | this.A(), 303 | bigint.powerModule(v, this.u(), srp.n()) 304 | ), new Clipperz.Crypto.BigInt(b, 10), srp.n() 305 | ); 306 | 307 | return result; 308 | }, 309 | */ 310 | //========================================================================= 311 | 312 | 'stringHash': function(aValue) { 313 | var result; 314 | 315 | result = this.hash(new Clipperz.ByteArray(aValue)).toHexString().substring(2); 316 | 317 | return result; 318 | }, 319 | 320 | //========================================================================= 321 | __syntaxFix__: "syntax fix" 322 | 323 | }); 324 | 325 | //############################################################################# 326 | -------------------------------------------------------------------------------- /js/Clipperz/Logging.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | Clipperz.Base.module('Clipperz'); 24 | 25 | if (typeof console == 'undefined') { 26 | Clipperz.log = MochiKit.Logging.logDebug; 27 | // Safari/WebKit 4 28 | } else if (navigator.userAgent.match(/WebKit/)) { 29 | // Clipperz.log = console.log; 30 | Clipperz.log = MochiKit.Logging.logDebug; 31 | } else if (navigator.userAgent.match(/Gecko/)) { 32 | Clipperz.log = function () { 33 | // firebug 1.3 bug see http://code.google.com/p/fbug/issues/detail?id=1347 34 | console.log.apply(window._firebug, arguments); 35 | }; 36 | } -------------------------------------------------------------------------------- /js/Clipperz/YUI/Utils.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | if (typeof YAHOO == 'undefined') { YAHOO = {}; }; 24 | if (typeof YAHOO.util == 'undefined') { YAHOO.util = {}; }; 25 | if (typeof YAHOO.util.Dom == 'undefined') { YAHOO.util.Dom = {}; }; 26 | 27 | YAHOO.extend = function(subc, superc, overrides) { 28 | var F = function() {}; 29 | F.prototype=superc.prototype; 30 | subc.prototype=new F(); 31 | subc.prototype.constructor=subc; 32 | subc.superclass=superc.prototype; 33 | if (superc.prototype.constructor == Object.prototype.constructor) { 34 | superc.prototype.constructor=superc; 35 | } 36 | 37 | if (overrides) { 38 | for (var i in overrides) { 39 | subc.prototype[i]=overrides[i]; 40 | } 41 | } 42 | }; 43 | 44 | YAHOO.override = function(origclass, overrides){ 45 | if(overrides){ 46 | var p = origclass.prototype; 47 | for(var method in overrides){ 48 | p[method] = overrides[method]; 49 | } 50 | } 51 | }; 52 | 53 | YAHOO.extendX = function(subclass, superclass, overrides){ 54 | YAHOO.extend(subclass, superclass); 55 | subclass.override = function(o){ 56 | YAHOO.override(subclass, o); 57 | }; 58 | if(!subclass.prototype.override){ 59 | subclass.prototype.override = function(o){ 60 | for(var method in o){ 61 | this[method] = o[method]; 62 | } 63 | }; 64 | } 65 | if(overrides){ 66 | subclass.override(overrides); 67 | }; 68 | 69 | }; 70 | 71 | YAHOO.util.Dom.get = function(el) { 72 | if (!el) { return null; } // nothing to work with 73 | 74 | if (typeof el != 'string' && !(el instanceof Array) ) { // assuming HTMLElement or HTMLCollection, so pass back as is 75 | return el; 76 | } 77 | 78 | if (typeof el == 'string') { // ID 79 | return document.getElementById(el); 80 | } 81 | else { // array of ID's and/or elements 82 | var collection = []; 83 | for (var i = 0, len = el.length; i < len; ++i) { 84 | collection[collection.length] = YAHOO.util.Dom.get(el[i]); 85 | } 86 | 87 | return collection; 88 | } 89 | 90 | return null; // safety, should never happen 91 | }; 92 | 93 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/DateTime.js: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | MochiKit.DateTime 1.5 4 | 5 | See for documentation, downloads, license, etc. 6 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. 8 | 9 | ***/ 10 | 11 | MochiKit.Base._module('DateTime', '1.5', ['Base']); 12 | 13 | /** @id MochiKit.DateTime.isoDate */ 14 | MochiKit.DateTime.isoDate = function (str) { 15 | str = str + ""; 16 | if (typeof(str) != "string" || str.length === 0) { 17 | return null; 18 | } 19 | var iso = str.split('-'); 20 | if (iso.length === 0) { 21 | return null; 22 | } 23 | var date = new Date(iso[0], iso[1] - 1, iso[2]); 24 | date.setFullYear(iso[0]); 25 | date.setMonth(iso[1] - 1); 26 | date.setDate(iso[2]); 27 | return date; 28 | }; 29 | 30 | MochiKit.DateTime._isoRegexp = /(\d{4,})(?:-(\d{1,2})(?:-(\d{1,2})(?:[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2})(?:\.(\d+))?)?(?:(Z)|([+-])(\d{1,2})(?::(\d{1,2}))?)?)?)?)?/; 31 | 32 | /** @id MochiKit.DateTime.isoTimestamp */ 33 | MochiKit.DateTime.isoTimestamp = function (str) { 34 | str = str + ""; 35 | if (typeof(str) != "string" || str.length === 0) { 36 | return null; 37 | } 38 | var res = str.match(MochiKit.DateTime._isoRegexp); 39 | if (typeof(res) == "undefined" || res === null) { 40 | return null; 41 | } 42 | var year, month, day, hour, min, sec, msec; 43 | year = parseInt(res[1], 10); 44 | if (typeof(res[2]) == "undefined" || res[2] === '') { 45 | return new Date(year); 46 | } 47 | month = parseInt(res[2], 10) - 1; 48 | day = parseInt(res[3], 10); 49 | if (typeof(res[4]) == "undefined" || res[4] === '') { 50 | return new Date(year, month, day); 51 | } 52 | hour = parseInt(res[4], 10); 53 | min = parseInt(res[5], 10); 54 | sec = (typeof(res[6]) != "undefined" && res[6] !== '') ? parseInt(res[6], 10) : 0; 55 | if (typeof(res[7]) != "undefined" && res[7] !== '') { 56 | msec = Math.round(1000.0 * parseFloat("0." + res[7])); 57 | } else { 58 | msec = 0; 59 | } 60 | if ((typeof(res[8]) == "undefined" || res[8] === '') && (typeof(res[9]) == "undefined" || res[9] === '')) { 61 | return new Date(year, month, day, hour, min, sec, msec); 62 | } 63 | var ofs; 64 | if (typeof(res[9]) != "undefined" && res[9] !== '') { 65 | ofs = parseInt(res[10], 10) * 3600000; 66 | if (typeof(res[11]) != "undefined" && res[11] !== '') { 67 | ofs += parseInt(res[11], 10) * 60000; 68 | } 69 | if (res[9] == "-") { 70 | ofs = -ofs; 71 | } 72 | } else { 73 | ofs = 0; 74 | } 75 | return new Date(Date.UTC(year, month, day, hour, min, sec, msec) - ofs); 76 | }; 77 | 78 | /** @id MochiKit.DateTime.toISOTime */ 79 | MochiKit.DateTime.toISOTime = function (date, realISO/* = false */) { 80 | if (typeof(date) == "undefined" || date === null) { 81 | return null; 82 | } 83 | var hh = date.getHours(); 84 | var mm = date.getMinutes(); 85 | var ss = date.getSeconds(); 86 | var lst = [ 87 | ((realISO && (hh < 10)) ? "0" + hh : hh), 88 | ((mm < 10) ? "0" + mm : mm), 89 | ((ss < 10) ? "0" + ss : ss) 90 | ]; 91 | return lst.join(":"); 92 | }; 93 | 94 | /** @id MochiKit.DateTime.toISOTimeStamp */ 95 | MochiKit.DateTime.toISOTimestamp = function (date, realISO/* = false*/) { 96 | if (typeof(date) == "undefined" || date === null) { 97 | return null; 98 | } 99 | var sep = realISO ? "T" : " "; 100 | var foot = realISO ? "Z" : ""; 101 | if (realISO) { 102 | date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000)); 103 | } 104 | return MochiKit.DateTime.toISODate(date) + sep + MochiKit.DateTime.toISOTime(date, realISO) + foot; 105 | }; 106 | 107 | /** @id MochiKit.DateTime.toISODate */ 108 | MochiKit.DateTime.toISODate = function (date) { 109 | if (typeof(date) == "undefined" || date === null) { 110 | return null; 111 | } 112 | var _padTwo = MochiKit.DateTime._padTwo; 113 | var _padFour = MochiKit.DateTime._padFour; 114 | return [ 115 | _padFour(date.getFullYear()), 116 | _padTwo(date.getMonth() + 1), 117 | _padTwo(date.getDate()) 118 | ].join("-"); 119 | }; 120 | 121 | /** @id MochiKit.DateTime.americanDate */ 122 | MochiKit.DateTime.americanDate = function (d) { 123 | d = d + ""; 124 | if (typeof(d) != "string" || d.length === 0) { 125 | return null; 126 | } 127 | var a = d.split('/'); 128 | return new Date(a[2], a[0] - 1, a[1]); 129 | }; 130 | 131 | MochiKit.DateTime._padTwo = function (n) { 132 | return (n > 9) ? n : "0" + n; 133 | }; 134 | 135 | MochiKit.DateTime._padFour = function(n) { 136 | switch(n.toString().length) { 137 | case 1: return "000" + n; break; 138 | case 2: return "00" + n; break; 139 | case 3: return "0" + n; break; 140 | case 4: 141 | default: 142 | return n; 143 | } 144 | }; 145 | 146 | /** @id MochiKit.DateTime.toPaddedAmericanDate */ 147 | MochiKit.DateTime.toPaddedAmericanDate = function (d) { 148 | if (typeof(d) == "undefined" || d === null) { 149 | return null; 150 | } 151 | var _padTwo = MochiKit.DateTime._padTwo; 152 | return [ 153 | _padTwo(d.getMonth() + 1), 154 | _padTwo(d.getDate()), 155 | d.getFullYear() 156 | ].join('/'); 157 | }; 158 | 159 | /** @id MochiKit.DateTime.toAmericanDate */ 160 | MochiKit.DateTime.toAmericanDate = function (d) { 161 | if (typeof(d) == "undefined" || d === null) { 162 | return null; 163 | } 164 | return [d.getMonth() + 1, d.getDate(), d.getFullYear()].join('/'); 165 | }; 166 | 167 | MochiKit.DateTime.__new__ = function () { 168 | MochiKit.Base.nameFunctions(this); 169 | }; 170 | 171 | MochiKit.DateTime.__new__(); 172 | 173 | MochiKit.Base._exportSymbols(this, MochiKit.DateTime); 174 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/Format.js: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | MochiKit.Format 1.5 4 | 5 | See for documentation, downloads, license, etc. 6 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. 8 | 9 | ***/ 10 | 11 | MochiKit.Base._module('Format', '1.5', ['Base']); 12 | 13 | MochiKit.Format._numberFormatter = function (placeholder, header, footer, locale, isPercent, precision, leadingZeros, separatorAt, trailingZeros) { 14 | return function (num) { 15 | num = parseFloat(num); 16 | if (typeof(num) == "undefined" || num === null || isNaN(num)) { 17 | return placeholder; 18 | } 19 | var curheader = header; 20 | var curfooter = footer; 21 | if (num < 0) { 22 | num = -num; 23 | } else { 24 | curheader = curheader.replace(/-/, ""); 25 | } 26 | var me = arguments.callee; 27 | var fmt = MochiKit.Format.formatLocale(locale); 28 | if (isPercent) { 29 | num = num * 100.0; 30 | curfooter = fmt.percent + curfooter; 31 | } 32 | num = MochiKit.Format.roundToFixed(num, precision); 33 | var parts = num.split(/\./); 34 | var whole = parts[0]; 35 | var frac = (parts.length == 1) ? "" : parts[1]; 36 | var res = ""; 37 | while (whole.length < leadingZeros) { 38 | whole = "0" + whole; 39 | } 40 | if (separatorAt) { 41 | while (whole.length > separatorAt) { 42 | var i = whole.length - separatorAt; 43 | //res = res + fmt.separator + whole.substring(i, whole.length); 44 | res = fmt.separator + whole.substring(i, whole.length) + res; 45 | whole = whole.substring(0, i); 46 | } 47 | } 48 | res = whole + res; 49 | if (precision > 0) { 50 | while (frac.length < trailingZeros) { 51 | frac = frac + "0"; 52 | } 53 | res = res + fmt.decimal + frac; 54 | } 55 | return curheader + res + curfooter; 56 | }; 57 | }; 58 | 59 | /** @id MochiKit.Format.numberFormatter */ 60 | MochiKit.Format.numberFormatter = function (pattern, placeholder/* = "" */, locale/* = "default" */) { 61 | // http://java.sun.com/docs/books/tutorial/i18n/format/numberpattern.html 62 | // | 0 | leading or trailing zeros 63 | // | # | just the number 64 | // | , | separator 65 | // | . | decimal separator 66 | // | % | Multiply by 100 and format as percent 67 | if (typeof(placeholder) == "undefined") { 68 | placeholder = ""; 69 | } 70 | var match = pattern.match(/((?:[0#]+,)?[0#]+)(?:\.([0#]+))?(%)?/); 71 | if (!match) { 72 | throw TypeError("Invalid pattern"); 73 | } 74 | var header = pattern.substr(0, match.index); 75 | var footer = pattern.substr(match.index + match[0].length); 76 | if (header.search(/-/) == -1) { 77 | header = header + "-"; 78 | } 79 | var whole = match[1]; 80 | var frac = (typeof(match[2]) == "string" && match[2] != "") ? match[2] : ""; 81 | var isPercent = (typeof(match[3]) == "string" && match[3] != ""); 82 | var tmp = whole.split(/,/); 83 | var separatorAt; 84 | if (typeof(locale) == "undefined") { 85 | locale = "default"; 86 | } 87 | if (tmp.length == 1) { 88 | separatorAt = null; 89 | } else { 90 | separatorAt = tmp[1].length; 91 | } 92 | var leadingZeros = whole.length - whole.replace(/0/g, "").length; 93 | var trailingZeros = frac.length - frac.replace(/0/g, "").length; 94 | var precision = frac.length; 95 | var rval = MochiKit.Format._numberFormatter( 96 | placeholder, header, footer, locale, isPercent, precision, 97 | leadingZeros, separatorAt, trailingZeros 98 | ); 99 | var m = MochiKit.Base; 100 | if (m) { 101 | var fn = arguments.callee; 102 | var args = m.concat(arguments); 103 | rval.repr = function () { 104 | return [ 105 | self.NAME, 106 | "(", 107 | map(m.repr, args).join(", "), 108 | ")" 109 | ].join(""); 110 | }; 111 | } 112 | return rval; 113 | }; 114 | 115 | /** @id MochiKit.Format.formatLocale */ 116 | MochiKit.Format.formatLocale = function (locale) { 117 | if (typeof(locale) == "undefined" || locale === null) { 118 | locale = "default"; 119 | } 120 | if (typeof(locale) == "string") { 121 | var rval = MochiKit.Format.LOCALE[locale]; 122 | if (typeof(rval) == "string") { 123 | rval = arguments.callee(rval); 124 | MochiKit.Format.LOCALE[locale] = rval; 125 | } 126 | return rval; 127 | } else { 128 | return locale; 129 | } 130 | }; 131 | 132 | /** @id MochiKit.Format.twoDigitAverage */ 133 | MochiKit.Format.twoDigitAverage = function (numerator, denominator) { 134 | if (denominator) { 135 | var res = numerator / denominator; 136 | if (!isNaN(res)) { 137 | return MochiKit.Format.twoDigitFloat(res); 138 | } 139 | } 140 | return "0"; 141 | }; 142 | 143 | /** @id MochiKit.Format.twoDigitFloat */ 144 | MochiKit.Format.twoDigitFloat = function (aNumber) { 145 | var res = roundToFixed(aNumber, 2); 146 | if (res.indexOf(".00") > 0) { 147 | return res.substring(0, res.length - 3); 148 | } else if (res.charAt(res.length - 1) == "0") { 149 | return res.substring(0, res.length - 1); 150 | } else { 151 | return res; 152 | } 153 | }; 154 | 155 | /** @id MochiKit.Format.lstrip */ 156 | MochiKit.Format.lstrip = function (str, /* optional */chars) { 157 | str = str + ""; 158 | if (typeof(str) != "string") { 159 | return null; 160 | } 161 | if (!chars) { 162 | return str.replace(/^\s+/, ""); 163 | } else { 164 | return str.replace(new RegExp("^[" + chars + "]+"), ""); 165 | } 166 | }; 167 | 168 | /** @id MochiKit.Format.rstrip */ 169 | MochiKit.Format.rstrip = function (str, /* optional */chars) { 170 | str = str + ""; 171 | if (typeof(str) != "string") { 172 | return null; 173 | } 174 | if (!chars) { 175 | return str.replace(/\s+$/, ""); 176 | } else { 177 | return str.replace(new RegExp("[" + chars + "]+$"), ""); 178 | } 179 | }; 180 | 181 | /** @id MochiKit.Format.strip */ 182 | MochiKit.Format.strip = function (str, /* optional */chars) { 183 | var self = MochiKit.Format; 184 | return self.rstrip(self.lstrip(str, chars), chars); 185 | }; 186 | 187 | /** @id MochiKit.Format.truncToFixed */ 188 | MochiKit.Format.truncToFixed = function (aNumber, precision) { 189 | var fixed = MochiKit.Format._numberToFixed(aNumber, precision); 190 | var fracPos = fixed.indexOf("."); 191 | if (fracPos > 0 && fracPos + precision + 1 < fixed.length) { 192 | fixed = fixed.substring(0, fracPos + precision + 1); 193 | fixed = MochiKit.Format._shiftNumber(fixed, 0); 194 | } 195 | return fixed; 196 | } 197 | 198 | /** @id MochiKit.Format.roundToFixed */ 199 | MochiKit.Format.roundToFixed = function (aNumber, precision) { 200 | var fixed = MochiKit.Format._numberToFixed(aNumber, precision); 201 | var fracPos = fixed.indexOf("."); 202 | if (fracPos > 0 && fracPos + precision + 1 < fixed.length) { 203 | var str = MochiKit.Format._shiftNumber(fixed, precision); 204 | str = MochiKit.Format._numberToFixed(Math.round(parseFloat(str)), 0); 205 | fixed = MochiKit.Format._shiftNumber(str, -precision); 206 | } 207 | return fixed; 208 | } 209 | 210 | /** 211 | * Converts a number to a fixed format string. This function handles 212 | * conversion of exponents by shifting the decimal point to the left 213 | * or the right. It also guarantees a specified minimum number of 214 | * fractional digits (but no maximum). 215 | * 216 | * @param {Number} aNumber the number to convert 217 | * @param {Number} precision the minimum number of decimal digits 218 | * 219 | * @return {String} the fixed format number string 220 | */ 221 | MochiKit.Format._numberToFixed = function (aNumber, precision) { 222 | var str = aNumber.toString(); 223 | var parts = str.split(/[eE]/); 224 | var exp = (parts.length === 1) ? 0 : parseInt(parts[1]) || 0; 225 | var fixed = MochiKit.Format._shiftNumber(parts[0], exp); 226 | parts = fixed.split(/\./); 227 | var whole = parts[0]; 228 | var frac = (parts.length === 1) ? "" : parts[1]; 229 | while (frac.length < precision) { 230 | frac += "0"; 231 | } 232 | if (frac.length > 0) { 233 | return whole + "." + frac; 234 | } else { 235 | return whole; 236 | } 237 | } 238 | 239 | /** 240 | * Shifts the decimal dot location in a fixed format number string. 241 | * This function handles negative values and will add and remove 242 | * leading and trailing zeros as needed. 243 | * 244 | * @param {String} num the fixed format number string 245 | * @param {Number} exp the base-10 exponent to apply 246 | * 247 | * @return {String} the new fixed format number string 248 | */ 249 | MochiKit.Format._shiftNumber = function (num, exp) { 250 | var pos = num.indexOf("."); 251 | if (pos < 0) { 252 | pos = num.length; 253 | } else { 254 | num = num.substring(0, pos) + num.substring(pos + 1); 255 | } 256 | pos += exp; 257 | while (pos <= 0 || (pos <= 1 && num.charAt(0) === "-")) { 258 | if (num.charAt(0) === "-") { 259 | num = "-0" + num.substring(1); 260 | } else { 261 | num = "0" + num; 262 | } 263 | pos++; 264 | } 265 | while (pos > num.length) { 266 | num += "0"; 267 | } 268 | if (pos < num.length) { 269 | num = num.substring(0, pos) + "." + num.substring(pos); 270 | } 271 | while (/^0[^.]/.test(num)) { 272 | num = num.substring(1); 273 | } 274 | while (/^-0[^.]/.test(num)) { 275 | num = "-" + num.substring(2); 276 | } 277 | return num; 278 | } 279 | 280 | /** @id MochiKit.Format.percentFormat */ 281 | MochiKit.Format.percentFormat = function (aNumber) { 282 | return MochiKit.Format.twoDigitFloat(100 * aNumber) + '%'; 283 | }; 284 | 285 | MochiKit.Format.LOCALE = { 286 | en_US: {separator: ",", decimal: ".", percent: "%"}, 287 | de_DE: {separator: ".", decimal: ",", percent: "%"}, 288 | pt_BR: {separator: ".", decimal: ",", percent: "%"}, 289 | fr_FR: {separator: " ", decimal: ",", percent: "%"}, 290 | "default": "en_US", 291 | __export__: false 292 | }; 293 | 294 | MochiKit.Format.__new__ = function () { 295 | MochiKit.Base.nameFunctions(this); 296 | var base = this.NAME + "."; 297 | var k, v, o; 298 | for (k in this.LOCALE) { 299 | o = this.LOCALE[k]; 300 | if (typeof(o) == "object") { 301 | o.repr = function () { return this.NAME; }; 302 | o.NAME = base + "LOCALE." + k; 303 | } 304 | } 305 | }; 306 | 307 | MochiKit.Format.__new__(); 308 | 309 | MochiKit.Base._exportSymbols(this, MochiKit.Format); 310 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MochiKit is dual-licensed software. It is available under the terms of the 2 | MIT License, or the Academic Free License version 2.1. The full text of 3 | each license is included below. 4 | 5 | The MochiKit.Style.getElementPosition function is adapted from 6 | YAHOO.util.Dom.getXY v0.9.0. which is copyrighted by Yahoo! Inc. and 7 | licensed under the BSD license also reproduced in full below. 8 | 9 | MIT License 10 | =========== 11 | 12 | Copyright (c) 2005 Bob Ippolito. All rights reserved. 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | Academic Free License v. 2.1 22 | ============================ 23 | 24 | Copyright (c) 2005 Bob Ippolito. All rights reserved. 25 | 26 | This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work: 27 | 28 | Licensed under the Academic Free License version 2.1 29 | 30 | 1) Grant of Copyright License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license to do the following: 31 | 32 | a) to reproduce the Original Work in copies; 33 | 34 | b) to prepare derivative works ("Derivative Works") based upon the Original Work; 35 | 36 | c) to distribute copies of the Original Work and Derivative Works to the public; 37 | 38 | d) to perform the Original Work publicly; and 39 | 40 | e) to display the Original Work publicly. 41 | 42 | 2) Grant of Patent License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, to make, use, sell and offer for sale the Original Work and Derivative Works. 43 | 44 | 3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor hereby agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work, and by publishing the address of that information repository in a notice immediately following the copyright notice that applies to the Original Work. 45 | 46 | 4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior written permission of the Licensor. Nothing in this License shall be deemed to grant any rights to trademarks, copyrights, patents, trade secrets or any other intellectual property of Licensor except as expressly stated herein. No patent license is granted to make, use, sell or offer to sell embodiments of any patent claims other than the licensed claims defined in Section 2. No right is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under different terms from this License any Original Work that Licensor otherwise would have a right to license. 47 | 48 | 5) This section intentionally omitted. 49 | 50 | 6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. 51 | 52 | 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately proceeding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to Original Work is granted hereunder except under this disclaimer. 53 | 54 | 8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to any person for any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to liability for death or personal injury resulting from Licensor's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You. 55 | 56 | 9) Acceptance and Termination. If You distribute copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. Nothing else but this License (or another written agreement between Licensor and You) grants You permission to create Derivative Works based upon the Original Work or to exercise any of the rights granted in Section 1 herein, and any attempt to do so except under the terms of this License (or another written agreement between Licensor and You) is expressly prohibited by U.S. copyright law, the equivalent laws of other countries, and by international treaty. Therefore, by exercising any of the rights granted to You in Section 1 herein, You indicate Your acceptance of this License and all of its terms and conditions. 57 | 58 | 10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. 59 | 60 | 11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et seq., the equivalent laws of other countries, and international treaty. This section shall survive the termination of this License. 61 | 62 | 12) Attorneys Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. 63 | 64 | 13) Miscellaneous. This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. 65 | 66 | 14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 67 | 68 | 15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. 69 | 70 | This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved. Permission is hereby granted to copy and distribute this license without modification. This license may not be modified without the express written permission of its copyright owner. 71 | 72 | 73 | BSD License 74 | =========== 75 | 76 | Copyright (c) 2006, Yahoo! Inc. 77 | All rights reserved. 78 | 79 | Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 80 | 81 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the 82 | following disclaimer. 83 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 84 | * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc. 85 | 86 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /other_libraries/MochiKit/Logging.js: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | MochiKit.Logging 1.5 4 | 5 | See for documentation, downloads, license, etc. 6 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. 8 | 9 | ***/ 10 | 11 | MochiKit.Base._module('Logging', '1.5', ['Base']); 12 | 13 | /** @id MochiKit.Logging.LogMessage */ 14 | MochiKit.Logging.LogMessage = function (num, level, info) { 15 | this.num = num; 16 | this.level = level; 17 | this.info = info; 18 | this.timestamp = new Date(); 19 | }; 20 | 21 | MochiKit.Logging.LogMessage.prototype = { 22 | /** @id MochiKit.Logging.LogMessage.prototype.repr */ 23 | repr: function () { 24 | var m = MochiKit.Base; 25 | return 'LogMessage(' + 26 | m.map( 27 | m.repr, 28 | [this.num, this.level, this.info] 29 | ).join(', ') + ')'; 30 | }, 31 | /** @id MochiKit.Logging.LogMessage.prototype.toString */ 32 | toString: MochiKit.Base.forwardCall("repr") 33 | }; 34 | 35 | MochiKit.Base.update(MochiKit.Logging, { 36 | /** @id MochiKit.Logging.logLevelAtLeast */ 37 | logLevelAtLeast: function (minLevel) { 38 | var self = MochiKit.Logging; 39 | if (typeof(minLevel) == 'string') { 40 | minLevel = self.LogLevel[minLevel]; 41 | } 42 | return function (msg) { 43 | var msgLevel = msg.level; 44 | if (typeof(msgLevel) == 'string') { 45 | msgLevel = self.LogLevel[msgLevel]; 46 | } 47 | return msgLevel >= minLevel; 48 | }; 49 | }, 50 | 51 | /** @id MochiKit.Logging.isLogMessage */ 52 | isLogMessage: function (/* ... */) { 53 | var LogMessage = MochiKit.Logging.LogMessage; 54 | for (var i = 0; i < arguments.length; i++) { 55 | if (!(arguments[i] instanceof LogMessage)) { 56 | return false; 57 | } 58 | } 59 | return true; 60 | }, 61 | 62 | /** @id MochiKit.Logging.compareLogMessage */ 63 | compareLogMessage: function (a, b) { 64 | return MochiKit.Base.compare([a.level, a.info], [b.level, b.info]); 65 | }, 66 | 67 | /** @id MochiKit.Logging.alertListener */ 68 | alertListener: function (msg) { 69 | alert( 70 | "num: " + msg.num + 71 | "\nlevel: " + msg.level + 72 | "\ninfo: " + msg.info.join(" ") 73 | ); 74 | } 75 | 76 | }); 77 | 78 | /** @id MochiKit.Logging.Logger */ 79 | MochiKit.Logging.Logger = function (/* optional */maxSize) { 80 | this.counter = 0; 81 | if (typeof(maxSize) == 'undefined' || maxSize === null) { 82 | maxSize = -1; 83 | } 84 | this.maxSize = maxSize; 85 | this._messages = []; 86 | this.listeners = {}; 87 | this.useNativeConsole = false; 88 | }; 89 | 90 | MochiKit.Logging.Logger.prototype = { 91 | /** @id MochiKit.Logging.Logger.prototype.clear */ 92 | clear: function () { 93 | this._messages.splice(0, this._messages.length); 94 | }, 95 | 96 | /** @id MochiKit.Logging.Logger.prototype.logToConsole */ 97 | logToConsole: function (msg) { 98 | if (typeof(window) != "undefined" && window.console 99 | && window.console.log) { 100 | // Safari and FireBug 0.4 101 | // Percent replacement is a workaround for cute Safari crashing bug 102 | window.console.log(msg.replace(/%/g, '\uFF05')); 103 | } else if (typeof(opera) != "undefined" && opera.postError) { 104 | // Opera 105 | opera.postError(msg); 106 | } else if (typeof(Debug) != "undefined" && Debug.writeln) { 107 | // IE Web Development Helper (?) 108 | // http://www.nikhilk.net/Entry.aspx?id=93 109 | Debug.writeln(msg); 110 | } else if (typeof(debug) != "undefined" && debug.trace) { 111 | // Atlas framework (?) 112 | // http://www.nikhilk.net/Entry.aspx?id=93 113 | debug.trace(msg); 114 | } 115 | }, 116 | 117 | /** @id MochiKit.Logging.Logger.prototype.dispatchListeners */ 118 | dispatchListeners: function (msg) { 119 | for (var k in this.listeners) { 120 | var pair = this.listeners[k]; 121 | if (pair.ident != k || (pair[0] && !pair[0](msg))) { 122 | continue; 123 | } 124 | pair[1](msg); 125 | } 126 | }, 127 | 128 | /** @id MochiKit.Logging.Logger.prototype.addListener */ 129 | addListener: function (ident, filter, listener) { 130 | if (typeof(filter) == 'string') { 131 | filter = MochiKit.Logging.logLevelAtLeast(filter); 132 | } 133 | var entry = [filter, listener]; 134 | entry.ident = ident; 135 | this.listeners[ident] = entry; 136 | }, 137 | 138 | /** @id MochiKit.Logging.Logger.prototype.removeListener */ 139 | removeListener: function (ident) { 140 | delete this.listeners[ident]; 141 | }, 142 | 143 | /** @id MochiKit.Logging.Logger.prototype.baseLog */ 144 | baseLog: function (level, message/*, ...*/) { 145 | if (typeof(level) == "number") { 146 | if (level >= MochiKit.Logging.LogLevel.FATAL) { 147 | level = 'FATAL'; 148 | } else if (level >= MochiKit.Logging.LogLevel.ERROR) { 149 | level = 'ERROR'; 150 | } else if (level >= MochiKit.Logging.LogLevel.WARNING) { 151 | level = 'WARNING'; 152 | } else if (level >= MochiKit.Logging.LogLevel.INFO) { 153 | level = 'INFO'; 154 | } else { 155 | level = 'DEBUG'; 156 | } 157 | } 158 | var msg = new MochiKit.Logging.LogMessage( 159 | this.counter, 160 | level, 161 | MochiKit.Base.extend(null, arguments, 1) 162 | ); 163 | this._messages.push(msg); 164 | this.dispatchListeners(msg); 165 | if (this.useNativeConsole) { 166 | this.logToConsole(msg.level + ": " + msg.info.join(" ")); 167 | } 168 | this.counter += 1; 169 | while (this.maxSize >= 0 && this._messages.length > this.maxSize) { 170 | this._messages.shift(); 171 | } 172 | }, 173 | 174 | /** @id MochiKit.Logging.Logger.prototype.getMessages */ 175 | getMessages: function (howMany) { 176 | var firstMsg = 0; 177 | if (!(typeof(howMany) == 'undefined' || howMany === null)) { 178 | firstMsg = Math.max(0, this._messages.length - howMany); 179 | } 180 | return this._messages.slice(firstMsg); 181 | }, 182 | 183 | /** @id MochiKit.Logging.Logger.prototype.getMessageText */ 184 | getMessageText: function (howMany) { 185 | if (typeof(howMany) == 'undefined' || howMany === null) { 186 | howMany = 30; 187 | } 188 | var messages = this.getMessages(howMany); 189 | if (messages.length) { 190 | var lst = map(function (m) { 191 | return '\n [' + m.num + '] ' + m.level + ': ' + m.info.join(' '); 192 | }, messages); 193 | lst.unshift('LAST ' + messages.length + ' MESSAGES:'); 194 | return lst.join(''); 195 | } 196 | return ''; 197 | }, 198 | 199 | /** @id MochiKit.Logging.Logger.prototype.debuggingBookmarklet */ 200 | debuggingBookmarklet: function (inline) { 201 | if (typeof(MochiKit.LoggingPane) == "undefined") { 202 | alert(this.getMessageText()); 203 | } else { 204 | MochiKit.LoggingPane.createLoggingPane(inline || false); 205 | } 206 | } 207 | }; 208 | 209 | MochiKit.Logging.__new__ = function () { 210 | this.LogLevel = { 211 | ERROR: 40, 212 | FATAL: 50, 213 | WARNING: 30, 214 | INFO: 20, 215 | DEBUG: 10 216 | }; 217 | 218 | var m = MochiKit.Base; 219 | m.registerComparator("LogMessage", 220 | this.isLogMessage, 221 | this.compareLogMessage 222 | ); 223 | 224 | var partial = m.partial; 225 | 226 | var Logger = this.Logger; 227 | var baseLog = Logger.prototype.baseLog; 228 | m.update(this.Logger.prototype, { 229 | debug: partial(baseLog, 'DEBUG'), 230 | log: partial(baseLog, 'INFO'), 231 | error: partial(baseLog, 'ERROR'), 232 | fatal: partial(baseLog, 'FATAL'), 233 | warning: partial(baseLog, 'WARNING') 234 | }); 235 | 236 | // indirectly find logger so it can be replaced 237 | var self = this; 238 | var connectLog = function (name) { 239 | return function () { 240 | self.logger[name].apply(self.logger, arguments); 241 | }; 242 | }; 243 | 244 | /** @id MochiKit.Logging.log */ 245 | this.log = connectLog('log'); 246 | /** @id MochiKit.Logging.logError */ 247 | this.logError = connectLog('error'); 248 | /** @id MochiKit.Logging.logDebug */ 249 | this.logDebug = connectLog('debug'); 250 | /** @id MochiKit.Logging.logFatal */ 251 | this.logFatal = connectLog('fatal'); 252 | /** @id MochiKit.Logging.logWarning */ 253 | this.logWarning = connectLog('warning'); 254 | this.logger = new Logger(); 255 | this.logger.useNativeConsole = true; 256 | 257 | m.nameFunctions(this); 258 | }; 259 | 260 | MochiKit.Logging.__new__(); 261 | 262 | MochiKit.Base._exportSymbols(this, MochiKit.Logging); 263 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/LoggingPane.js: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | MochiKit.LoggingPane 1.5 4 | 5 | See for documentation, downloads, license, etc. 6 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. 8 | 9 | ***/ 10 | 11 | MochiKit.Base._module('LoggingPane', '1.5', ['Base', 'Logging']); 12 | 13 | /** @id MochiKit.LoggingPane.createLoggingPane */ 14 | MochiKit.LoggingPane.createLoggingPane = function (inline/* = false */) { 15 | var m = MochiKit.LoggingPane; 16 | inline = !(!inline); 17 | if (m._loggingPane && m._loggingPane.inline != inline) { 18 | m._loggingPane.closePane(); 19 | m._loggingPane = null; 20 | } 21 | if (!m._loggingPane || m._loggingPane.closed) { 22 | m._loggingPane = new m.LoggingPane(inline, MochiKit.Logging.logger); 23 | } 24 | return m._loggingPane; 25 | }; 26 | 27 | /** @id MochiKit.LoggingPane.LoggingPane */ 28 | MochiKit.LoggingPane.LoggingPane = function (inline/* = false */, logger/* = MochiKit.Logging.logger */) { 29 | 30 | /* Use a div if inline, pop up a window if not */ 31 | /* Create the elements */ 32 | if (typeof(logger) == "undefined" || logger === null) { 33 | logger = MochiKit.Logging.logger; 34 | } 35 | this.logger = logger; 36 | var update = MochiKit.Base.update; 37 | var updatetree = MochiKit.Base.updatetree; 38 | var bind = MochiKit.Base.bind; 39 | var clone = MochiKit.Base.clone; 40 | var win = window; 41 | var uid = "_MochiKit_LoggingPane"; 42 | if (typeof(MochiKit.DOM) != "undefined") { 43 | win = MochiKit.DOM.currentWindow(); 44 | } 45 | if (!inline) { 46 | // name the popup with the base URL for uniqueness 47 | var url = win.location.href.split("?")[0].replace(/[#:\/.><&%-]/g, "_"); 48 | var name = uid + "_" + url; 49 | var nwin = win.open("", name, "dependent,resizable,height=200"); 50 | if (!nwin) { 51 | alert("Not able to open debugging window due to pop-up blocking."); 52 | return undefined; 53 | } 54 | nwin.document.write( 55 | '' 57 | + '[MochiKit.LoggingPane]' 58 | + '' 59 | ); 60 | nwin.document.close(); 61 | nwin.document.title += ' ' + win.document.title; 62 | win = nwin; 63 | } 64 | var doc = win.document; 65 | this.doc = doc; 66 | 67 | // Connect to the debug pane if it already exists (i.e. in a window orphaned by the page being refreshed) 68 | var debugPane = doc.getElementById(uid); 69 | var existing_pane = !!debugPane; 70 | if (debugPane && typeof(debugPane.loggingPane) != "undefined") { 71 | debugPane.loggingPane.logger = this.logger; 72 | debugPane.loggingPane.buildAndApplyFilter(); 73 | return debugPane.loggingPane; 74 | } 75 | 76 | if (existing_pane) { 77 | // clear any existing contents 78 | var child; 79 | while ((child = debugPane.firstChild)) { 80 | debugPane.removeChild(child); 81 | } 82 | } else { 83 | debugPane = doc.createElement("div"); 84 | debugPane.id = uid; 85 | } 86 | debugPane.loggingPane = this; 87 | var levelFilterField = doc.createElement("input"); 88 | var infoFilterField = doc.createElement("input"); 89 | var filterButton = doc.createElement("button"); 90 | var loadButton = doc.createElement("button"); 91 | var clearButton = doc.createElement("button"); 92 | var closeButton = doc.createElement("button"); 93 | var logPaneArea = doc.createElement("div"); 94 | var logPane = doc.createElement("div"); 95 | 96 | /* Set up the functions */ 97 | var listenerId = uid + "_Listener"; 98 | this.colorTable = clone(this.colorTable); 99 | var messages = []; 100 | var messageFilter = null; 101 | 102 | /** @id MochiKit.LoggingPane.messageLevel */ 103 | var messageLevel = function (msg) { 104 | var level = msg.level; 105 | if (typeof(level) == "number") { 106 | level = MochiKit.Logging.LogLevel[level]; 107 | } 108 | return level; 109 | }; 110 | 111 | /** @id MochiKit.LoggingPane.messageText */ 112 | var messageText = function (msg) { 113 | return msg.info.join(" "); 114 | }; 115 | 116 | /** @id MochiKit.LoggingPane.addMessageText */ 117 | var addMessageText = bind(function (msg) { 118 | var level = messageLevel(msg); 119 | var text = messageText(msg); 120 | var c = this.colorTable[level]; 121 | var p = doc.createElement("span"); 122 | p.className = "MochiKit-LogMessage MochiKit-LogLevel-" + level; 123 | p.style.cssText = "margin: 0px; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; white-space: pre-line; word-wrap: break-word; wrap-option: emergency; color: " + c; 124 | p.appendChild(doc.createTextNode(level + ": " + text)); 125 | logPane.appendChild(p); 126 | logPane.appendChild(doc.createElement("br")); 127 | if (logPaneArea.offsetHeight > logPaneArea.scrollHeight) { 128 | logPaneArea.scrollTop = 0; 129 | } else { 130 | logPaneArea.scrollTop = logPaneArea.scrollHeight; 131 | } 132 | }, this); 133 | 134 | /** @id MochiKit.LoggingPane.addMessage */ 135 | var addMessage = function (msg) { 136 | messages[messages.length] = msg; 137 | addMessageText(msg); 138 | }; 139 | 140 | /** @id MochiKit.LoggingPane.buildMessageFilter */ 141 | var buildMessageFilter = function () { 142 | var levelre, infore; 143 | try { 144 | /* Catch any exceptions that might arise due to invalid regexes */ 145 | levelre = new RegExp(levelFilterField.value); 146 | infore = new RegExp(infoFilterField.value); 147 | } catch(e) { 148 | /* If there was an error with the regexes, do no filtering */ 149 | logDebug("Error in filter regex: " + e.message); 150 | return null; 151 | } 152 | 153 | return function (msg) { 154 | return ( 155 | levelre.test(messageLevel(msg)) && 156 | infore.test(messageText(msg)) 157 | ); 158 | }; 159 | }; 160 | 161 | /** @id MochiKit.LoggingPane.clearMessagePane */ 162 | var clearMessagePane = function () { 163 | while (logPane.firstChild) { 164 | logPane.removeChild(logPane.firstChild); 165 | } 166 | }; 167 | 168 | /** @id MochiKit.LoggingPane.clearMessages */ 169 | var clearMessages = function () { 170 | messages = []; 171 | clearMessagePane(); 172 | }; 173 | 174 | /** @id MochiKit.LoggingPane.closePane */ 175 | var closePane = bind(function () { 176 | if (this.closed) { 177 | return; 178 | } 179 | this.closed = true; 180 | if (MochiKit.LoggingPane._loggingPane == this) { 181 | MochiKit.LoggingPane._loggingPane = null; 182 | } 183 | this.logger.removeListener(listenerId); 184 | try { 185 | try { 186 | debugPane.loggingPane = null; 187 | } catch(e) { logFatal("Bookmarklet was closed incorrectly."); } 188 | if (inline) { 189 | debugPane.parentNode.removeChild(debugPane); 190 | } else { 191 | this.win.close(); 192 | } 193 | } catch(e) {} 194 | }, this); 195 | 196 | /** @id MochiKit.LoggingPane.filterMessages */ 197 | var filterMessages = function () { 198 | clearMessagePane(); 199 | 200 | for (var i = 0; i < messages.length; i++) { 201 | var msg = messages[i]; 202 | if (messageFilter === null || messageFilter(msg)) { 203 | addMessageText(msg); 204 | } 205 | } 206 | }; 207 | 208 | this.buildAndApplyFilter = function () { 209 | messageFilter = buildMessageFilter(); 210 | 211 | filterMessages(); 212 | 213 | this.logger.removeListener(listenerId); 214 | this.logger.addListener(listenerId, messageFilter, addMessage); 215 | }; 216 | 217 | 218 | /** @id MochiKit.LoggingPane.loadMessages */ 219 | var loadMessages = bind(function () { 220 | messages = this.logger.getMessages(); 221 | filterMessages(); 222 | }, this); 223 | 224 | /** @id MochiKit.LoggingPane.filterOnEnter */ 225 | var filterOnEnter = bind(function (event) { 226 | event = event || window.event; 227 | key = event.which || event.keyCode; 228 | if (key == 13) { 229 | this.buildAndApplyFilter(); 230 | } 231 | }, this); 232 | 233 | /* Create the debug pane */ 234 | var style = "display: block; z-index: 1000; left: 0px; bottom: 0px; position: fixed; width: 100%; background-color: white; font: " + this.logFont; 235 | if (inline) { 236 | style += "; height: 10em; border-top: 2px solid black"; 237 | } else { 238 | style += "; height: 100%;"; 239 | } 240 | debugPane.style.cssText = style; 241 | 242 | if (!existing_pane) { 243 | doc.body.appendChild(debugPane); 244 | } 245 | 246 | /* Create the filter fields */ 247 | style = {"cssText": "width: 33%; display: inline; font: " + this.logFont}; 248 | 249 | updatetree(levelFilterField, { 250 | "value": "FATAL|ERROR|WARNING|INFO|DEBUG", 251 | "onkeypress": filterOnEnter, 252 | "style": style 253 | }); 254 | debugPane.appendChild(levelFilterField); 255 | 256 | updatetree(infoFilterField, { 257 | "value": ".*", 258 | "onkeypress": filterOnEnter, 259 | "style": style 260 | }); 261 | debugPane.appendChild(infoFilterField); 262 | 263 | /* Create the buttons */ 264 | style = "width: 8%; display:inline; font: " + this.logFont; 265 | 266 | filterButton.appendChild(doc.createTextNode("Filter")); 267 | filterButton.onclick = bind("buildAndApplyFilter", this); 268 | filterButton.style.cssText = style; 269 | debugPane.appendChild(filterButton); 270 | 271 | loadButton.appendChild(doc.createTextNode("Load")); 272 | loadButton.onclick = loadMessages; 273 | loadButton.style.cssText = style; 274 | debugPane.appendChild(loadButton); 275 | 276 | clearButton.appendChild(doc.createTextNode("Clear")); 277 | clearButton.onclick = clearMessages; 278 | clearButton.style.cssText = style; 279 | debugPane.appendChild(clearButton); 280 | 281 | closeButton.appendChild(doc.createTextNode("Close")); 282 | closeButton.onclick = closePane; 283 | closeButton.style.cssText = style; 284 | debugPane.appendChild(closeButton); 285 | 286 | /* Create the logging pane */ 287 | logPaneArea.style.cssText = "overflow: auto; width: 100%"; 288 | logPane.style.cssText = "width: 100%; height: " + (inline ? "8em" : "100%"); 289 | 290 | logPaneArea.appendChild(logPane); 291 | debugPane.appendChild(logPaneArea); 292 | 293 | this.buildAndApplyFilter(); 294 | loadMessages(); 295 | 296 | if (inline) { 297 | this.win = undefined; 298 | } else { 299 | this.win = win; 300 | } 301 | this.inline = inline; 302 | this.closePane = closePane; 303 | this.closed = false; 304 | 305 | 306 | return this; 307 | }; 308 | 309 | MochiKit.LoggingPane.LoggingPane.prototype = { 310 | "logFont": "8pt Verdana,sans-serif", 311 | "colorTable": { 312 | "ERROR": "red", 313 | "FATAL": "darkred", 314 | "WARNING": "blue", 315 | "INFO": "black", 316 | "DEBUG": "green" 317 | } 318 | }; 319 | 320 | MochiKit.LoggingPane.__new__ = function () { 321 | MochiKit.Base.nameFunctions(this); 322 | MochiKit.LoggingPane._loggingPane = null; 323 | }; 324 | 325 | MochiKit.LoggingPane.__new__(); 326 | 327 | MochiKit.Base._exportSymbols(this, MochiKit.LoggingPane); 328 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/MochiKit.js: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | MochiKit.MochiKit 1.5 4 | 5 | See for documentation, downloads, license, etc. 6 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. 8 | 9 | ***/ 10 | 11 | if (typeof(MochiKit) == 'undefined') { 12 | MochiKit = {}; 13 | } 14 | 15 | if (typeof(MochiKit.MochiKit) == 'undefined') { 16 | /** @id MochiKit.MochiKit */ 17 | MochiKit.MochiKit = {}; 18 | } 19 | 20 | MochiKit.MochiKit.NAME = "MochiKit.MochiKit"; 21 | MochiKit.MochiKit.VERSION = "1.5"; 22 | MochiKit.MochiKit.__repr__ = function () { 23 | return "[" + this.NAME + " " + this.VERSION + "]"; 24 | }; 25 | 26 | /** @id MochiKit.MochiKit.toString */ 27 | MochiKit.MochiKit.toString = function () { 28 | return this.__repr__(); 29 | }; 30 | 31 | /** @id MochiKit.MochiKit.SUBMODULES */ 32 | MochiKit.MochiKit.SUBMODULES = [ 33 | "Base", 34 | "Iter", 35 | "Logging", 36 | "DateTime", 37 | "Format", 38 | "Text", 39 | "Async", 40 | "DOM", 41 | "Selector", 42 | "Style", 43 | "LoggingPane", 44 | "Color", 45 | "Signal", 46 | "Position", 47 | "Visual", 48 | "DragAndDrop", 49 | "Sortable" 50 | ]; 51 | 52 | (function () { 53 | if (typeof(document) == "undefined") { 54 | return; 55 | } 56 | var scripts = document.getElementsByTagName("script"); 57 | var kXHTMLNSURI = "http://www.w3.org/1999/xhtml"; 58 | var kSVGNSURI = "http://www.w3.org/2000/svg"; 59 | var kXLINKNSURI = "http://www.w3.org/1999/xlink"; 60 | var kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; 61 | var base = null; 62 | var baseElem = null; 63 | var allScripts = {}; 64 | var i; 65 | var src; 66 | for (i = 0; i < scripts.length; i++) { 67 | src = null; 68 | switch (scripts[i].namespaceURI) { 69 | case kSVGNSURI: 70 | src = scripts[i].getAttributeNS(kXLINKNSURI, "href"); 71 | break; 72 | /* 73 | case null: // HTML 74 | case '': // HTML 75 | case kXHTMLNSURI: 76 | case kXULNSURI: 77 | */ 78 | default: 79 | src = scripts[i].getAttribute("src"); 80 | break; 81 | } 82 | if (!src) { 83 | continue; 84 | } 85 | allScripts[src] = true; 86 | if (src.match(/MochiKit.js(\?.*)?$/)) { 87 | base = src.substring(0, src.lastIndexOf('MochiKit.js')); 88 | baseElem = scripts[i]; 89 | } 90 | } 91 | if (base === null) { 92 | return; 93 | } 94 | var modules = MochiKit.MochiKit.SUBMODULES; 95 | for (var i = 0; i < modules.length; i++) { 96 | if (MochiKit[modules[i]]) { 97 | continue; 98 | } 99 | var uri = base + modules[i] + '.js'; 100 | if (uri in allScripts) { 101 | continue; 102 | } 103 | if (baseElem.namespaceURI == kSVGNSURI || 104 | baseElem.namespaceURI == kXULNSURI) { 105 | // SVG, XUL 106 | /* 107 | SVG does not support document.write, so if Safari wants to 108 | support SVG tests it should fix its deferred loading bug 109 | (see following below). 110 | */ 111 | var s = document.createElementNS(baseElem.namespaceURI, 'script'); 112 | s.setAttribute("id", "MochiKit_" + base + modules[i]); 113 | if (baseElem.namespaceURI == kSVGNSURI) { 114 | s.setAttributeNS(kXLINKNSURI, 'href', uri); 115 | } else { 116 | s.setAttribute('src', uri); 117 | } 118 | s.setAttribute("type", "application/x-javascript"); 119 | baseElem.parentNode.appendChild(s); 120 | } else { 121 | // HTML, XHTML 122 | /* 123 | DOM can not be used here because Safari does 124 | deferred loading of scripts unless they are 125 | in the document or inserted with document.write 126 | 127 | This is not XHTML compliant. If you want XHTML 128 | compliance then you must use the packed version of MochiKit 129 | or include each script individually (basically unroll 130 | these document.write calls into your XHTML source) 131 | */ 132 | document.write('<' + baseElem.nodeName + ' src="' + uri + 133 | '" type="text/javascript">'); 134 | } 135 | }; 136 | })(); 137 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/MockDOM.js: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | MochiKit.MockDOM 1.5 4 | 5 | See for documentation, downloads, license, etc. 6 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. 8 | 9 | ***/ 10 | 11 | if (typeof(MochiKit) == "undefined") { 12 | MochiKit = {}; 13 | } 14 | 15 | if (typeof(MochiKit.MockDOM) == "undefined") { 16 | MochiKit.MockDOM = {}; 17 | } 18 | 19 | MochiKit.MockDOM.NAME = "MochiKit.MockDOM"; 20 | MochiKit.MockDOM.VERSION = "1.5"; 21 | 22 | MochiKit.MockDOM.__repr__ = function () { 23 | return "[" + this.NAME + " " + this.VERSION + "]"; 24 | }; 25 | 26 | /** @id MochiKit.MockDOM.toString */ 27 | MochiKit.MockDOM.toString = function () { 28 | return this.__repr__(); 29 | }; 30 | 31 | /** @id MochiKit.MockDOM.createDocument */ 32 | MochiKit.MockDOM.createDocument = function () { 33 | var doc = new MochiKit.MockDOM.MockElement("DOCUMENT"); 34 | doc.body = doc.createElement("BODY"); 35 | doc.appendChild(doc.body); 36 | return doc; 37 | }; 38 | 39 | /** @id MochiKit.MockDOM.MockElement */ 40 | MochiKit.MockDOM.MockElement = function (name, data, ownerDocument) { 41 | this.tagName = this.nodeName = name.toUpperCase(); 42 | this.ownerDocument = ownerDocument || null; 43 | if (name == "DOCUMENT") { 44 | this.nodeType = 9; 45 | this.childNodes = []; 46 | } else if (typeof(data) == "string") { 47 | this.nodeValue = data; 48 | this.nodeType = 3; 49 | } else { 50 | this.nodeType = 1; 51 | this.childNodes = []; 52 | } 53 | if (name.substring(0, 1) == "<") { 54 | var nameattr = name.substring( 55 | name.indexOf('"') + 1, name.lastIndexOf('"')); 56 | name = name.substring(1, name.indexOf(" ")); 57 | this.tagName = this.nodeName = name.toUpperCase(); 58 | this.setAttribute("name", nameattr); 59 | } 60 | }; 61 | 62 | MochiKit.MockDOM.MockElement.prototype = { 63 | /** @id MochiKit.MockDOM.MockElement.prototype.createElement */ 64 | createElement: function (tagName) { 65 | return new MochiKit.MockDOM.MockElement(tagName, null, this.nodeType == 9 ? this : this.ownerDocument); 66 | }, 67 | /** @id MochiKit.MockDOM.MockElement.prototype.createTextNode */ 68 | createTextNode: function (text) { 69 | return new MochiKit.MockDOM.MockElement("text", text, this.nodeType == 9 ? this : this.ownerDocument); 70 | }, 71 | /** @id MochiKit.MockDOM.MockElement.prototype.setAttribute */ 72 | setAttribute: function (name, value) { 73 | this[name] = value; 74 | }, 75 | /** @id MochiKit.MockDOM.MockElement.prototype.getAttribute */ 76 | getAttribute: function (name) { 77 | return this[name]; 78 | }, 79 | /** @id MochiKit.MockDOM.MockElement.prototype.appendChild */ 80 | appendChild: function (child) { 81 | this.childNodes.push(child); 82 | }, 83 | /** @id MochiKit.MockDOM.MockElement.prototype.toString */ 84 | toString: function () { 85 | return "MockElement(" + this.tagName + ")"; 86 | }, 87 | /** @id MochiKit.MockDOM.MockElement.prototype.getElementsByTagName */ 88 | getElementsByTagName: function (tagName) { 89 | var foundElements = []; 90 | MochiKit.Base.nodeWalk(this, function(node){ 91 | if (tagName == '*' || tagName == node.tagName) { 92 | foundElements.push(node); 93 | return node.childNodes; 94 | } 95 | }); 96 | return foundElements; 97 | } 98 | }; 99 | 100 | /** @id MochiKit.MockDOM.EXPORT_OK */ 101 | MochiKit.MockDOM.EXPORT_OK = [ 102 | "mockElement", 103 | "createDocument" 104 | ]; 105 | 106 | /** @id MochiKit.MockDOM.EXPORT */ 107 | MochiKit.MockDOM.EXPORT = [ 108 | "document" 109 | ]; 110 | 111 | MochiKit.MockDOM.__new__ = function () { 112 | this.document = this.createDocument(); 113 | }; 114 | 115 | MochiKit.MockDOM.__new__(); 116 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/Position.js: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | MochiKit.Position 1.5 4 | 5 | See for documentation, downloads, license, etc. 6 | 7 | (c) 2005-2006 Bob Ippolito and others. All rights Reserved. 8 | 9 | ***/ 10 | 11 | MochiKit.Base._module('Position', '1.5', ['Base', 'DOM', 'Style']); 12 | 13 | MochiKit.Base.update(MochiKit.Position, { 14 | // Don't export from this module 15 | __export__: false, 16 | 17 | // set to true if needed, warning: firefox performance problems 18 | // NOT neeeded for page scrolling, only if draggable contained in 19 | // scrollable elements 20 | includeScrollOffsets: false, 21 | 22 | /** @id MochiKit.Position.prepare */ 23 | prepare: function () { 24 | var deltaX = window.pageXOffset 25 | || document.documentElement.scrollLeft 26 | || document.body.scrollLeft 27 | || 0; 28 | var deltaY = window.pageYOffset 29 | || document.documentElement.scrollTop 30 | || document.body.scrollTop 31 | || 0; 32 | this.windowOffset = new MochiKit.Style.Coordinates(deltaX, deltaY); 33 | }, 34 | 35 | /** @id MochiKit.Position.cumulativeOffset */ 36 | cumulativeOffset: function (element) { 37 | var valueT = 0; 38 | var valueL = 0; 39 | do { 40 | valueT += element.offsetTop || 0; 41 | valueL += element.offsetLeft || 0; 42 | element = element.offsetParent; 43 | } while (element); 44 | return new MochiKit.Style.Coordinates(valueL, valueT); 45 | }, 46 | 47 | /** @id MochiKit.Position.realOffset */ 48 | realOffset: function (element) { 49 | var valueT = 0; 50 | var valueL = 0; 51 | do { 52 | valueT += element.scrollTop || 0; 53 | valueL += element.scrollLeft || 0; 54 | element = element.parentNode; 55 | } while (element); 56 | return new MochiKit.Style.Coordinates(valueL, valueT); 57 | }, 58 | 59 | /** @id MochiKit.Position.within */ 60 | within: function (element, x, y) { 61 | if (this.includeScrollOffsets) { 62 | return this.withinIncludingScrolloffsets(element, x, y); 63 | } 64 | this.xcomp = x; 65 | this.ycomp = y; 66 | this.offset = this.cumulativeOffset(element); 67 | if (element.style.position == "fixed") { 68 | this.offset.x += this.windowOffset.x; 69 | this.offset.y += this.windowOffset.y; 70 | } 71 | 72 | return (y >= this.offset.y && 73 | y < this.offset.y + element.offsetHeight && 74 | x >= this.offset.x && 75 | x < this.offset.x + element.offsetWidth); 76 | }, 77 | 78 | /** @id MochiKit.Position.withinIncludingScrolloffsets */ 79 | withinIncludingScrolloffsets: function (element, x, y) { 80 | var offsetcache = this.realOffset(element); 81 | 82 | this.xcomp = x + offsetcache.x - this.windowOffset.x; 83 | this.ycomp = y + offsetcache.y - this.windowOffset.y; 84 | this.offset = this.cumulativeOffset(element); 85 | 86 | return (this.ycomp >= this.offset.y && 87 | this.ycomp < this.offset.y + element.offsetHeight && 88 | this.xcomp >= this.offset.x && 89 | this.xcomp < this.offset.x + element.offsetWidth); 90 | }, 91 | 92 | // within must be called directly before 93 | /** @id MochiKit.Position.overlap */ 94 | overlap: function (mode, element) { 95 | if (!mode) { 96 | return 0; 97 | } 98 | if (mode == 'vertical') { 99 | return ((this.offset.y + element.offsetHeight) - this.ycomp) / 100 | element.offsetHeight; 101 | } 102 | if (mode == 'horizontal') { 103 | return ((this.offset.x + element.offsetWidth) - this.xcomp) / 104 | element.offsetWidth; 105 | } 106 | }, 107 | 108 | /** @id MochiKit.Position.absolutize */ 109 | absolutize: function (element) { 110 | element = MochiKit.DOM.getElement(element); 111 | if (element.style.position == 'absolute') { 112 | return; 113 | } 114 | MochiKit.Position.prepare(); 115 | 116 | var offsets = MochiKit.Position.positionedOffset(element); 117 | var width = element.clientWidth; 118 | var height = element.clientHeight; 119 | 120 | var oldStyle = { 121 | 'position': element.style.position, 122 | 'left': offsets.x - parseFloat(element.style.left || 0), 123 | 'top': offsets.y - parseFloat(element.style.top || 0), 124 | 'width': element.style.width, 125 | 'height': element.style.height 126 | }; 127 | 128 | element.style.position = 'absolute'; 129 | element.style.top = offsets.y + 'px'; 130 | element.style.left = offsets.x + 'px'; 131 | element.style.width = width + 'px'; 132 | element.style.height = height + 'px'; 133 | 134 | return oldStyle; 135 | }, 136 | 137 | /** @id MochiKit.Position.positionedOffset */ 138 | positionedOffset: function (element) { 139 | var valueT = 0, valueL = 0; 140 | do { 141 | valueT += element.offsetTop || 0; 142 | valueL += element.offsetLeft || 0; 143 | element = element.offsetParent; 144 | if (element) { 145 | var p = MochiKit.Style.getStyle(element, 'position'); 146 | if (p == 'relative' || p == 'absolute') { 147 | break; 148 | } 149 | } 150 | } while (element); 151 | return new MochiKit.Style.Coordinates(valueL, valueT); 152 | }, 153 | 154 | /** @id MochiKit.Position.relativize */ 155 | relativize: function (element, oldPos) { 156 | element = MochiKit.DOM.getElement(element); 157 | if (element.style.position == 'relative') { 158 | return; 159 | } 160 | MochiKit.Position.prepare(); 161 | 162 | var top = parseFloat(element.style.top || 0) - 163 | (oldPos['top'] || 0); 164 | var left = parseFloat(element.style.left || 0) - 165 | (oldPos['left'] || 0); 166 | 167 | element.style.position = oldPos['position']; 168 | element.style.top = top + 'px'; 169 | element.style.left = left + 'px'; 170 | element.style.width = oldPos['width']; 171 | element.style.height = oldPos['height']; 172 | }, 173 | 174 | /** @id MochiKit.Position.clone */ 175 | clone: function (source, target) { 176 | source = MochiKit.DOM.getElement(source); 177 | target = MochiKit.DOM.getElement(target); 178 | target.style.position = 'absolute'; 179 | var offsets = this.cumulativeOffset(source); 180 | target.style.top = offsets.y + 'px'; 181 | target.style.left = offsets.x + 'px'; 182 | target.style.width = source.offsetWidth + 'px'; 183 | target.style.height = source.offsetHeight + 'px'; 184 | }, 185 | 186 | /** @id MochiKit.Position.page */ 187 | page: function (forElement) { 188 | var valueT = 0; 189 | var valueL = 0; 190 | 191 | var element = forElement; 192 | do { 193 | valueT += element.offsetTop || 0; 194 | valueL += element.offsetLeft || 0; 195 | 196 | // Safari fix 197 | if (element.offsetParent == document.body && MochiKit.Style.getStyle(element, 'position') == 'absolute') { 198 | break; 199 | } 200 | } while (element = element.offsetParent); 201 | 202 | element = forElement; 203 | do { 204 | valueT -= element.scrollTop || 0; 205 | valueL -= element.scrollLeft || 0; 206 | } while (element = element.parentNode); 207 | 208 | return new MochiKit.Style.Coordinates(valueL, valueT); 209 | } 210 | }); 211 | 212 | MochiKit.Position.__new__ = function (win) { 213 | MochiKit.Base.nameFunctions(this); 214 | }; 215 | 216 | MochiKit.Position.__new__(this); 217 | 218 | MochiKit.Base._exportSymbols(this, MochiKit.Position); 219 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/Test.js: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | MochiKit.Test 1.5 4 | 5 | See for documentation, downloads, license, etc. 6 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. 8 | 9 | ***/ 10 | 11 | MochiKit.Base._module('Test', '1.5', ['Base']); 12 | 13 | MochiKit.Test.runTests = function (obj) { 14 | if (typeof(obj) == "string") { 15 | // TODO: Remove this temporary API change advertisement 16 | throw new TypeError("Automatic module import not supported, call runTests() with proper object: " + obj); 17 | } 18 | var suite = new MochiKit.Test.Suite(); 19 | suite.run(obj); 20 | }; 21 | 22 | MochiKit.Test.Suite = function () { 23 | this.testIndex = 0; 24 | MochiKit.Base.bindMethods(this); 25 | }; 26 | 27 | MochiKit.Test.Suite.prototype = { 28 | run: function (obj) { 29 | try { 30 | obj(this); 31 | } catch (e) { 32 | this.traceback(e); 33 | } 34 | }, 35 | traceback: function (e) { 36 | var items = MochiKit.Iter.sorted(MochiKit.Base.items(e)); 37 | print("not ok " + this.testIndex + " - Error thrown"); 38 | for (var i = 0; i < items.length; i++) { 39 | var kv = items[i]; 40 | if (kv[0] == "stack") { 41 | kv[1] = kv[1].split(/\n/)[0]; 42 | } 43 | this.print("# " + kv.join(": ")); 44 | } 45 | }, 46 | print: function (s) { 47 | print(s); 48 | }, 49 | is: function (got, expected, /* optional */message) { 50 | var res = 1; 51 | var msg = null; 52 | try { 53 | res = MochiKit.Base.compare(got, expected); 54 | } catch (e) { 55 | msg = "Can not compare " + typeof(got) + ":" + typeof(expected); 56 | } 57 | if (res) { 58 | msg = "Expected value did not compare equal"; 59 | } 60 | if (!res) { 61 | return this.testResult(true, message); 62 | } 63 | return this.testResult(false, message, 64 | [[msg], ["got:", got], ["expected:", expected]]); 65 | }, 66 | 67 | testResult: function (pass, msg, failures) { 68 | this.testIndex += 1; 69 | if (pass) { 70 | this.print("ok " + this.testIndex + " - " + msg); 71 | return; 72 | } 73 | this.print("not ok " + this.testIndex + " - " + msg); 74 | if (failures) { 75 | for (var i = 0; i < failures.length; i++) { 76 | this.print("# " + failures[i].join(" ")); 77 | } 78 | } 79 | }, 80 | 81 | isDeeply: function (got, expected, /* optional */message) { 82 | var m = MochiKit.Base; 83 | var res = 1; 84 | try { 85 | res = m.compare(got, expected); 86 | } catch (e) { 87 | // pass 88 | } 89 | if (res === 0) { 90 | return this.ok(true, message); 91 | } 92 | var gk = m.keys(got); 93 | var ek = m.keys(expected); 94 | gk.sort(); 95 | ek.sort(); 96 | if (m.compare(gk, ek)) { 97 | // differing keys 98 | var cmp = {}; 99 | var i; 100 | for (i = 0; i < gk.length; i++) { 101 | cmp[gk[i]] = "got"; 102 | } 103 | for (i = 0; i < ek.length; i++) { 104 | if (ek[i] in cmp) { 105 | delete cmp[ek[i]]; 106 | } else { 107 | cmp[ek[i]] = "expected"; 108 | } 109 | } 110 | var diffkeys = m.keys(cmp); 111 | diffkeys.sort(); 112 | var gotkeys = []; 113 | var expkeys = []; 114 | while (diffkeys.length) { 115 | var k = diffkeys.shift(); 116 | if (k in Object.prototype) { 117 | continue; 118 | } 119 | (cmp[k] == "got" ? gotkeys : expkeys).push(k); 120 | } 121 | 122 | 123 | } 124 | 125 | return this.testResult((!res), msg, 126 | (msg ? [["got:", got], ["expected:", expected]] : undefined) 127 | ); 128 | }, 129 | 130 | ok: function (res, message) { 131 | return this.testResult(res, message); 132 | } 133 | }; 134 | 135 | MochiKit.Test.__new__ = function () { 136 | var m = MochiKit.Base; 137 | this.Suite.__export__ = false; 138 | m.nameFunctions(this); 139 | 140 | }; 141 | 142 | MochiKit.Test.__new__(); 143 | 144 | MochiKit.Base._exportSymbols(this, MochiKit.Test); 145 | -------------------------------------------------------------------------------- /other_libraries/MochiKit/__package__.js: -------------------------------------------------------------------------------- 1 | dojo.kwCompoundRequire({ 2 | "common": [ 3 | "MochiKit.Base", 4 | "MochiKit.Iter", 5 | "MochiKit.Logging", 6 | "MochiKit.DateTime", 7 | "MochiKit.Format", 8 | "MochiKit.Async", 9 | "MochiKit.DOM", 10 | "MochiKit.Style", 11 | "MochiKit.LoggingPane", 12 | "MochiKit.Color", 13 | "MochiKit.Signal", 14 | "MochiKit.Position", 15 | "MochiKit.Visual" 16 | ] 17 | }); 18 | dojo.provide("MochiKit.*"); 19 | -------------------------------------------------------------------------------- /tests/SimpleTest/SimpleTest.Async.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | MochiKit.Base.update(Clipperz.Async.Deferred.prototype, { 24 | /* 25 | '_addTest': function(anExpectedValue, aDescription, isDeep, aResult) { 26 | if (isDeep) { 27 | SimpleTest.isDeeply(aResult, anExpectedValue, aDescription); 28 | } else { 29 | SimpleTest.is(aResult, anExpectedValue, aDescription); 30 | } 31 | 32 | return aResult; 33 | }, 34 | */ 35 | 'addTest': function (anExpectedValue, aDescription, isDeep) { 36 | // this.addMethod(this, '_addTest', anExpectedValue, aDescription, isDeep); 37 | // this.addCallback(Clipperz.Async.test, anExpectedValue, aDescription, isDeep); 38 | 39 | if (isDeep) { 40 | // SimpleTest.isDeeply(aResult, anExpectedValue, aDescription); 41 | this.addCallback(Clipperz.Async.Test.isDeeply(anExpectedValue, aDescription)); 42 | } else { 43 | // SimpleTest.is(aResult, anExpectedValue, aDescription); 44 | this.addCallback(Clipperz.Async.Test.is(anExpectedValue, aDescription)); 45 | } 46 | }, 47 | 48 | //------------------------------------------------------------------------- 49 | 50 | 'shouldSucceed': function (aDescription) { 51 | this.addCallbackPass(SimpleTest.ok, true, aDescription); 52 | this.addErrbackPass (SimpleTest.ok, false, aDescription); 53 | this.addBoth(MochiKit.Async.succeed, null); 54 | }, 55 | 56 | 'shouldFail': function (aDescription) { 57 | this.addCallbackPass(SimpleTest.ok, false, aDescription); 58 | this.addErrbackPass (SimpleTest.ok, true, aDescription); 59 | this.addBoth(MochiKit.Async.succeed, null); 60 | }, 61 | 62 | //------------------------------------------------------------------------- 63 | 64 | }); 65 | 66 | 67 | Clipperz.Async.Test = {}; 68 | MochiKit.Base.update(Clipperz.Async.Test, { 69 | 70 | 'is': function (anExpectedResult, aDescription) { 71 | return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) { 72 | SimpleTest.is(aResult, anExpectedResult, aDescription); 73 | 74 | return aResult; 75 | }, anExpectedResult, aDescription); 76 | }, 77 | 78 | //------------------------------------------------------------------------- 79 | 80 | 'ok': function (aDescription) { 81 | return MochiKit.Base.partial(function (aDescription, aResult) { 82 | SimpleTest.ok(aResult, aDescription); 83 | 84 | return aResult; 85 | }, aDescription); 86 | }, 87 | 88 | //------------------------------------------------------------------------- 89 | 90 | 'fail': function(aDescription) { 91 | return MochiKit.Base.partial(function (aDescription, aResult) { 92 | SimpleTest.ok(!aResult, aDescription); 93 | 94 | return aResult; 95 | }, aDescription); 96 | }, 97 | 98 | //------------------------------------------------------------------------- 99 | 100 | 'isDeeply': function (anExpectedResult, aDescription) { 101 | return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) { 102 | SimpleTest.isDeeply(aResult, anExpectedResult, aDescription); 103 | 104 | return aResult; 105 | }, anExpectedResult, aDescription); 106 | }, 107 | 108 | //------------------------------------------------------------------------- 109 | __syntaxFix__: "syntax fix" 110 | }); 111 | 112 | 113 | SimpleTest.runDeferredTests = function (aName, aTestSet, aTestArguments) { 114 | try { 115 | var deferredTests; 116 | var aTestName; 117 | var title; 118 | 119 | deferredTests = new Clipperz.Async.Deferred(aName + " ", aTestArguments); 120 | 121 | title = aName; 122 | 123 | aTestName = window.location.href.match(/#.*/); 124 | if (aTestName && (aTestName != '#')) { 125 | aTestName = aTestName[0].slice(1); 126 | if (aTestName in aTestSet) { 127 | //Clipperz.log("single test execution, via fragment identifier", aTestName); 128 | title += ' [' + aTestName + ']'; 129 | deferredTests.addCallback(aTestSet[aTestName], aTestArguments); 130 | deferredTests.addErrback(SimpleTest.ok, false, aTestName); 131 | } else { 132 | title = 'WRONG TEST NAME' 133 | deferredTests.addBoth(is, aTestName, null, "Wrong test name selected to run"); 134 | } 135 | } else { 136 | for (aTestName in aTestSet) { 137 | deferredTests.addCallback(aTestSet[aTestName], aTestArguments); 138 | deferredTests.addErrback(SimpleTest.ok, false, aTestName); 139 | deferredTests.addBoth(MochiKit.Async.wait, 0.5); 140 | } 141 | deferredTests.addBoth(is, true, true, "FINISH: completed the full stack of tests"); 142 | } 143 | 144 | MochiKit.DOM.currentDocument().title = title; 145 | 146 | deferredTests.addBoth(SimpleTest.finish); 147 | deferredTests.callback(); 148 | 149 | SimpleTest.waitForExplicitFinish(); 150 | } catch (err) { 151 | var s = "test suite failure!\n"; 152 | var o = {}; 153 | var k = null; 154 | for (k in err) { 155 | // ensure unique keys?! 156 | if (!o[k]) { 157 | s += k + ": " + err[k] + "\n"; 158 | o[k] = err[k]; 159 | } 160 | } 161 | ok ( false, s ); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /tests/SimpleTest/TestRunner.js: -------------------------------------------------------------------------------- 1 | /** 2 | * TestRunner: A test runner for SimpleTest 3 | * TODO: 4 | * 5 | * * Avoid moving iframes: That causes reloads on mozilla and opera. 6 | * 7 | * 8 | **/ 9 | var TestRunner = {}; 10 | TestRunner.logEnabled = false; 11 | TestRunner._iframes = {}; 12 | TestRunner._iframeDocuments = {}; 13 | TestRunner._iframeRows = {}; 14 | TestRunner._currentTest = 0; 15 | TestRunner._urls = []; 16 | TestRunner._testsDiv = DIV(); 17 | TestRunner._progressDiv = DIV(); 18 | TestRunner._summaryDiv = DIV(null, 19 | H1(null, "Tests Summary"), 20 | TABLE(null, 21 | THEAD(null, 22 | TR(null, 23 | TH(null, "Test"), 24 | TH(null, "Passed"), 25 | TH(null, "Failed") 26 | ) 27 | ), 28 | TFOOT(/*null, TR(null, TH(null, "-"), TH(null, "--"), TH(null, "---"))*/), 29 | TBODY() 30 | ) 31 | ); 32 | 33 | /** 34 | * This function is called after generating the summary. 35 | **/ 36 | TestRunner.onComplete = null; 37 | 38 | /** 39 | * If logEnabled is true, this is the logger that will be used. 40 | **/ 41 | TestRunner.logger = MochiKit.Logging.logger; 42 | 43 | /** 44 | * Toggle element visibility 45 | **/ 46 | TestRunner._toggle = function(el) { 47 | if (el.className == "noshow") { 48 | el.className = ""; 49 | el.style.cssText = ""; 50 | } else { 51 | el.className = "noshow"; 52 | el.style.cssText = "width:0px; height:0px; border:0px;"; 53 | } 54 | }; 55 | 56 | 57 | /** 58 | * Creates the iframe that contains a test 59 | **/ 60 | TestRunner._makeIframe = function (url) { 61 | var iframe = document.createElement('iframe'); 62 | iframe.src = url; 63 | iframe.name = url; 64 | iframe.width = "500"; 65 | var tbody = TestRunner._summaryDiv.getElementsByTagName("tbody")[0]; 66 | var tr = TR(null, TD({'colspan': '3'}, iframe)); 67 | iframe._row = tr; 68 | tbody.appendChild(tr); 69 | return iframe; 70 | }; 71 | 72 | /** 73 | * TestRunner entry point. 74 | * 75 | * The arguments are the URLs of the test to be ran. 76 | * 77 | **/ 78 | TestRunner.runTests = function (/*url...*/) { 79 | if (TestRunner.logEnabled) 80 | TestRunner.logger.log("SimpleTest START"); 81 | 82 | var body = document.getElementsByTagName("body")[0]; 83 | appendChildNodes(body, 84 | TestRunner._testsDiv, 85 | TestRunner._progressDiv, 86 | TestRunner._summaryDiv 87 | ); 88 | for (var i = 0; i < arguments.length; i++) { 89 | TestRunner._urls.push(arguments[i]); 90 | } 91 | 92 | TestRunner.runNextTest(); 93 | }; 94 | 95 | /** 96 | * Run the next test. If no test remains, calls makeSummary 97 | **/ 98 | TestRunner.runNextTest = function() { 99 | if (TestRunner._currentTest < TestRunner._urls.length) { 100 | var url = TestRunner._urls[TestRunner._currentTest]; 101 | var progress = SPAN(null, 102 | "Running ", A({href:url}, url), "..." 103 | ); 104 | 105 | if (TestRunner.logEnabled) 106 | TestRunner.logger.log(scrapeText(progress)); 107 | 108 | TestRunner._progressDiv.appendChild(progress); 109 | TestRunner._iframes[url] = TestRunner._makeIframe(url); 110 | } else { 111 | TestRunner.makeSummary(); 112 | if (TestRunner.onComplete) { 113 | TestRunner.onComplete(); 114 | } 115 | } 116 | }; 117 | 118 | /** 119 | * This stub is called by SimpleTest when a test is finished. 120 | **/ 121 | TestRunner.testFinished = function (doc) { 122 | appendChildNodes(TestRunner._progressDiv, SPAN(null, "Done"), BR()); 123 | var finishedURL = TestRunner._urls[TestRunner._currentTest]; 124 | 125 | if (TestRunner.logEnabled) 126 | TestRunner.logger.debug("SimpleTest finished " + finishedURL); 127 | 128 | TestRunner._iframeDocuments[finishedURL] = doc; 129 | // TestRunner._iframes[finishedURL].style.display = "none"; 130 | if (finishedURL != null) { 131 | TestRunner._toggle(TestRunner._iframes[finishedURL]); 132 | TestRunner._currentTest++; 133 | TestRunner.runNextTest(); 134 | } 135 | }; 136 | 137 | /** 138 | * Display the summary in the browser 139 | **/ 140 | /* 141 | TestRunner.makeSummary = function() { 142 | if (TestRunner.logEnabled) 143 | TestRunner.logger.log("SimpleTest FINISHED"); 144 | var rows = []; 145 | for (var url in TestRunner._iframeDocuments) { 146 | var doc = TestRunner._iframeDocuments[url]; 147 | var nOK = withDocument(doc, 148 | partial(getElementsByTagAndClassName, 'div', 'test_ok') 149 | ).length; 150 | var nNotOK = withDocument(doc, 151 | partial(getElementsByTagAndClassName, 'div', 'test_not_ok') 152 | ).length; 153 | var toggle = partial(TestRunner._toggle, TestRunner._iframes[url]); 154 | var jsurl = "TestRunner._toggle(TestRunner._iframes['" + url + "'])"; 155 | var row = TR( 156 | {'style': {'backgroundColor': nNotOK > 0 ? "#f00":"#0f0"}}, 157 | TD(null, url), 158 | TD(null, nOK), 159 | TD(null, nNotOK) 160 | ); 161 | row.onclick = toggle; 162 | var tbody = TestRunner._summaryDiv.getElementsByTagName("tbody")[0]; 163 | tbody.insertBefore(row, TestRunner._iframes[url]._row) 164 | } 165 | }; 166 | */ 167 | 168 | TestRunner.makeSummary = function() { 169 | var base = MochiKit.Base; 170 | var dom = MochiKit.DOM; 171 | var iter = MochiKit.Iter; 172 | var total_Ok, total_not_Ok; 173 | 174 | total_Ok = 0; 175 | total_not_Ok = 0; 176 | 177 | if (TestRunner.logEnabled) 178 | TestRunner.logger.log("SimpleTest FINISHED"); 179 | var rows = []; 180 | for (var url in TestRunner._iframeDocuments) { 181 | var doc = TestRunner._iframeDocuments[url]; 182 | var nOK = withDocument(doc, 183 | partial(getElementsByTagAndClassName, 'div', 'test_ok') 184 | ).length; 185 | var nNotOK = withDocument(doc, 186 | partial(getElementsByTagAndClassName, 'div', 'test_not_ok') 187 | ).length; 188 | var toggle = partial(TestRunner._toggle, TestRunner._iframes[url]); 189 | var jsurl = "TestRunner._toggle(TestRunner._iframes['" + url + "'])"; 190 | var row = TR( 191 | {'style': {'backgroundColor': nNotOK > 0 ? "#f00":"#0f0"}}, 192 | TD(null, url), 193 | TD(null, nOK), 194 | TD(null, nNotOK) 195 | ); 196 | row.onclick = toggle; 197 | var tbody = TestRunner._summaryDiv.getElementsByTagName("tbody")[0]; 198 | tbody.insertBefore(row, TestRunner._iframes[url]._row); 199 | 200 | total_Ok += nOK; 201 | total_not_Ok += nNotOK; 202 | } 203 | 204 | { 205 | var tfoot = TestRunner._summaryDiv.getElementsByTagName("tfoot")[0]; 206 | tfoot.appendChild(TR(null, 207 | TH(null, ""), 208 | TH({'style':"color:green;"}, total_Ok), 209 | TH({'style':"color:" + ((total_not_Ok == 0) ? 'black' : 'red') + ";"}, total_not_Ok) 210 | )); 211 | } 212 | 213 | var testRunnerResults; 214 | var i, c; 215 | 216 | testRunnerResults = dom.DIV({'style': 'display:none; visibility:hidden;'}, null); 217 | 218 | c = total_Ok; 219 | for (i=0; i. 19 | 20 | --> 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 33 | 34 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Async.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | Clipperz.Async - test 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
42 | 
43 | 
44 | 
45 | 46 | 47 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Base.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | Clipperz.Base - TEST 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 
45 | 
46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/ECC.B283.deferred.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
 61 | 
146 | 
147 | 148 | 149 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.B283.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
 42 | 
199 | 
200 | 201 | 202 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
 42 | 
173 | 
174 | 175 | 176 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/ECC.K283.deferred.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
 66 | 
151 | 
152 | 153 | 154 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/PRNG.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
 46 | 
107 | 
108 | 109 | 110 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/RSA.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
38 | 
80 | 
81 | 82 | 83 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/SHA.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | Clipperz.Crypto.SHA - TEST 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
 47 | 
 48 | 
49 | 50 | 51 | 52 | 53 | 54 | 168 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/SHA.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2008-2014 Clipperz Srl - All rights reserved. 4 | 5 | This file is part of Clipperz's Javascript Crypto Library. 6 | 7 | The Javascript Crypto Library provides web developers with an extensive 8 | and efficient set of cryptographic functions. 9 | For further information about its features and functionalities please 10 | refer to https://clipperz.is 11 | 12 | * The Javascript Crypto Library is free software: you can redistribute 13 | it and/or modify it under the terms of the BSD 3-Clause License 14 | as published by the Free Software Foundation. 15 | 16 | * You should have received a copy of the BSD 3-Clause License 17 | along with the Javascript Crypto Library in the LICENSE.TXT file. 18 | If not, see . 19 | 20 | */ 21 | 22 | 23 | var testSHA = function (aValue, anExpectedResult) { 24 | var byteArrayValue; 25 | 26 | byteArrayValue = new Clipperz.ByteArray(aValue); 27 | hash = Clipperz.Crypto.SHA.sha256(byteArrayValue); 28 | is(hash.toHexString(), anExpectedResult, "sha256(' " + byteArrayValue.toHexString() + "')"); 29 | 30 | } 31 | 32 | 33 | var tests = { 34 | 35 | 'basic_tests': function (someTestArgs) { 36 | testSHA('', '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'); 37 | testSHA('0xbd', '0x68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b'); 38 | testSHA('0x5fd4', '0x7c4fbf484498d21b487b9d61de8914b2eadaf2698712936d47c3ada2558f6788'); 39 | testSHA('0xc98c8e55', '0x7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504'); 40 | testSHA('0x0df1cd526b5a4edd', '0x47f527210d6e8f940b5082fec01b7305908fa2b49ea3ae597c19a3986097153c'); 41 | testSHA('0xfdf4700984ee11b70af1880d0e0fefd4', '0xb01ae16eed3b4a770f127b98469ba26fe3d8e9f59d8a2983214afe6cff0e6b6c'); 42 | testSHA('0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb', '0x56059e8cb3c2978b198208bf5ca1e1ea5659b737a506324b7cec75b5ebaf057d'); 43 | testSHA('0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a', '0xc117b9dce689c399ec99008788cd5d24d8396fab7d96315c4f3fe6d56da63bb3'); 44 | testSHA('0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad', '0x105a60865830ac3a371d3843324d4bb5fa8ec0e02ddaa389ad8da4f10215c454'); 45 | 46 | }, 47 | 48 | //------------------------------------------------------------------------- 49 | 50 | 'aldo_cortesi_tests': function (someTestArgs) { 51 | testSHA('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', '0xa3f01b6939256127582ac8ae9fb47a382a244680806a3f613a118851c1ca1d47'); 52 | testSHA('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', '0xb35439a4ac6f0948b6d6f9e3c6af0f5f590ce20f1bde7090ef7970686ec6738a'); 53 | testSHA('0x79', '0xa1fce4363854ff888cff4b8e7875d600c2682390412a8cf79b37d0b11148b0fa'); 54 | testSHA('0x80', '0x76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71'); 55 | }, 56 | 57 | //------------------------------------------------------------------------- 58 | 59 | 'longTextPerformance_test': function (someTestArgs) { 60 | var longText; 61 | var startTime; 62 | var endTime; 63 | 64 | longText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nunc sapien, condimentum vitae, varius vel, pharetra in, augue. Mauris quam magna, pretium sit amet, accumsan id, volutpat lobortis, nibh. Fusce sagittis. Aenean justo. Curabitur euismod pede. Morbi at ante. Proin nisl leo, ultrices sed, facilisis et, nonummy sit amet, lorem. Praesent mauris tellus, pulvinar sed, nonummy vitae, rhoncus non, nunc. Proin placerat malesuada nisl. Nunc id enim. Maecenas commodo enim ac nibh. Sed condimentum, urna sit amet euismod gravida, mi urna varius odio, luctus pretium lectus justo nec felis. Ut in augue et est malesuada rhoncus. Sed vel orci. Mauris suscipit. Praesent cursus velit non turpis. Donec tristique dolor ac est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla est sapien, vulputate eget, bibendum id, pharetra nec, mauris. Aliquam faucibus tincidunt dui. Proin iaculis. Maecenas sagittis. Integer et augue. Donec vitae urna in orci aliquet commodo. Vestibulum lorem sem, suscipit ac, placerat nec, mollis in, felis. Donec laoreet odio a mauris. Integer rutrum, sapien id varius molestie, mauris odio egestas orci, non bibendum sem felis in metus. Phasellus consectetuer lectus adipiscing mauris. Ut magna tellus, euismod ac, suscipit tincidunt, ullamcorper adipiscing, massa. Etiam orci. Phasellus a urna. Cras neque quam, laoreet at, tempus eget, euismod nec, nibh. Etiam hendrerit. Aenean vel lorem. Ut ligula lacus, congue eu, lobortis sit amet, venenatis in, magna. Nullam cursus felis quis est. Sed sem est, condimentum eu, vestibulum a, mattis vel, diam. Curabitur tincidunt pede quis pede. Sed neque diam, convallis vel, luctus at, porta id, nisl. Suspendisse potenti. Sed volutpat lobortis orci. Praesent mi. In interdum. Suspendisse suscipit ipsum eget dolor. Curabitur et tellus sed velit hendrerit varius. Cras sit amet est. Donec arcu nulla, vehicula et, pretium in, placerat id, felis. Integer mollis auctor lectus. Integer ultrices elementum sapien. Nam et erat. Nam pulvinar porta tortor. Nam at risus. Quisque nulla. Integer vestibulum, lacus id bibendum laoreet, ligula mi pharetra lorem, sit amet pharetra felis mauris quis justo. Aliquam ultricies. Duis a pede eget lorem dapibus rhoncus. Aenean eu elit non libero consectetuer viverra. Maecenas velit mi, eleifend vel, malesuada vel, condimentum quis, odio. Mauris tempus augue sed turpis. Pellentesque condimentum, lacus vitae pellentesque ultricies, risus tellus posuere nisi, et dictum turpis pede nec elit. Sed eu lectus eu justo sagittis euismod. Vestibulum lobortis, urna id mollis rhoncus, orci quam euismod ligula, at malesuada lacus magna vitae massa. Phasellus mattis fermentum velit. Nulla vulputate consequat enim. Maecenas quis neque. Curabitur sagittis facilisis neque. In elementum, eros non porttitor rhoncus, libero turpis sodales odio, vitae porta tellus purus et ante. Nullam molestie sollicitudin metus. Donec a elit. Morbi ut lacus. Donec at arcu. Quisque velit diam, interdum a, lacinia at, varius et, odio. Cras neque magna, ornare id, sollicitudin id, consequat a, est. Phasellus vestibulum est at leo. Nam facilisis, nulla dapibus condimentum pellentesque, est magna viverra ligula, at sollicitudin urna augue ut sapien. Fusce justo."; 65 | startTime = new Date(); 66 | testSHA(longText, '0xf6fac13c06784e0fbc61a3d25c41c9984840a8b617a2beb57cf6fa3e5e4a8949'); 67 | endTime = new Date(); 68 | 69 | is((endTime - startTime) < 100, true, "Long text hash performance (" + (endTime - startTime) + ")"); 70 | }, 71 | 72 | //------------------------------------------------------------------------- 73 | 'syntaxFix': MochiKit.Base.noop 74 | } 75 | 76 | //============================================================================= 77 | 78 | SimpleTest.runDeferredTests("Clipperz.Crypto.SHA", tests, {trace:false}); 79 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/SRP.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
 42 | 
151 | 
152 | 153 | 154 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/Usage.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | Clipperz.Crypto.Usage - TEST 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
 45 | 
112 | 
113 | 114 | 115 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/Crypto/index.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | Clipperz.Crypto.* - tests 25 | 26 | 27 | 28 | 29 | 30 | 49 | 50 | -------------------------------------------------------------------------------- /tests/tests/Clipperz/index.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | Clipperz.* - tests 25 | 26 | 27 | 28 | 29 | 36 | 37 | -------------------------------------------------------------------------------- /tests/tests/index.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | Complete TEST suite 25 | 26 | 27 | 28 | 29 | 35 | 36 | --------------------------------------------------------------------------------