]> git.parisson.com Git - pdf.js.git/commitdiff
Fix jslint warnings and refactor small issues.
authorKalervo Kujala <kkujala@com>
Sun, 6 Nov 2011 20:17:20 +0000 (22:17 +0200)
committerKalervo Kujala <kkujala@com>
Sun, 6 Nov 2011 20:17:20 +0000 (22:17 +0200)
src/crypto.js

index d4d36fb20109e515298ffe02400f3af33251e341..95559864483c2f7d7278b839d674c53c306f64ca 100644 (file)
@@ -26,7 +26,6 @@ var ARCFourCipher = (function arcFourCipher() {
       var a = this.a, b = this.b, s = this.s;
       var output = new Uint8Array(n);
       for (i = 0; i < n; ++i) {
-        var tmp;
         a = (a + 1) & 0xFF;
         tmp = s[a];
         b = (b + tmp) & 0xFF;
@@ -75,8 +74,8 @@ var calculateMD5 = (function calculateMD5() {
       padded[i] = data[offset++];
     padded[i++] = 0x80;
     n = paddedLength - 8;
-    for (; i < n; ++i)
-      padded[i] = 0;
+    while (i < n)
+      padded[i++] = 0;
     padded[i++] = (length << 3) & 0xFF;
     padded[i++] = (length >> 5) & 0xFF;
     padded[i++] = (length >> 13) & 0xFF;
@@ -322,12 +321,12 @@ var AES128Cipher = (function aes128Cipher() {
     state[10] = state[2]; state[6] = t; state[2] = u;
     t = state[15]; u = state[11]; v = state[7]; state[15] = state[3];
     state[11] = t; state[7] = u; state[3] = v;
-    // InvSubBytes
-    for (j = 0; j < 16; ++j)
+    for (j = 0; j < 16; ++j) {
+      // InvSubBytes
       state[j] = inv_s[state[j]];
-    // AddRoundKey
-    for (j = 0; j < 16; ++j)
+      // AddRoundKey
       state[j] ^= key[j];
+    }
     return state;
   }
 
@@ -471,11 +470,11 @@ var CipherTransformFactory = (function cipherTransformFactory() {
       cipher = new ARCFourCipher(encryptionKey);
       var checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
       n = encryptionKey.length;
-      var derrivedKey = new Uint8Array(n), k;
+      var derivedKey = new Uint8Array(n), k;
       for (j = 1; j <= 19; ++j) {
         for (k = 0; k < n; ++k)
-          derrivedKey[k] = encryptionKey[k] ^ j;
-        cipher = new ARCFourCipher(derrivedKey);
+          derivedKey[k] = encryptionKey[k] ^ j;
+        cipher = new ARCFourCipher(derivedKey);
         checkData = cipher.encryptBlock(checkData);
       }
     } else {