From 5496ca4ad1181c97df6fe9d09e54db3d52008be0 Mon Sep 17 00:00:00 2001
From: Alexey Lunin <alexey.lunin@vereign.com>
Date: Wed, 29 May 2019 19:57:49 +0400
Subject: [PATCH] Change "var" to "let"

---
 javascript/src/CryptoData.js                 |  4 +-
 javascript/src/iframe/viamapi-iframe.js      | 88 ++++++++++----------
 javascript/src/utilities/appUtility.js       | 20 ++---
 javascript/src/utilities/signingUtilities.js |  8 +-
 4 files changed, 60 insertions(+), 60 deletions(-)

diff --git a/javascript/src/CryptoData.js b/javascript/src/CryptoData.js
index 9e78435..dfa79a5 100644
--- a/javascript/src/CryptoData.js
+++ b/javascript/src/CryptoData.js
@@ -1,7 +1,7 @@
 function CryptoData() {}
 
 CryptoData.prototype.set = function(obj) {
-  for (var member in obj) {
+  for (let member in obj) {
     this[member] = JSON.parse(JSON.stringify(obj[member]));
   }
 };
@@ -11,7 +11,7 @@ CryptoData.prototype.serialize = function() {
 };
 
 CryptoData.prototype.deserialize = function(serialized) {
-  var obj = JSON.parse(serialized);
+  let obj = JSON.parse(serialized);
   this.set(obj);
 };
 
diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js
index 29df152..42460b3 100644
--- a/javascript/src/iframe/viamapi-iframe.js
+++ b/javascript/src/iframe/viamapi-iframe.js
@@ -27,15 +27,15 @@ const WopiAPI = require("./wopiapi-iframe");
 const CollaboraAPI = require("./collaboraapi-iframe");
 const ViamAPI = require("../../temp/viamapi");
 
-var identityColors = ["#994392", "#cb0767", "#e51d31", "#ec671b", "#fab610"];
+let identityColors = ["#994392", "#cb0767", "#e51d31", "#ec671b", "#fab610"];
 
 function getNextColor() {
-  var colorIndex = localStorage.getItem("colorIndex");
+  let colorIndex = localStorage.getItem("colorIndex");
   if (colorIndex == null || colorIndex === "") {
     colorIndex = 0;
   }
 
-  var color = identityColors[colorIndex];
+  let color = identityColors[colorIndex];
 
   colorIndex++;
 
@@ -47,7 +47,7 @@ function getNextColor() {
 }
 
 function setKeyForUUID(uuid, key) {
-  var storedIdentityForUuid = localStorage.getItem("keyperuuid/" + uuid);
+  let storedIdentityForUuid = localStorage.getItem("keyperuuid/" + uuid);
   if (
     storedIdentityForUuid !== key &&
     storedIdentityForUuid != null &&
@@ -60,7 +60,7 @@ function setKeyForUUID(uuid, key) {
 }
 
 function getColorForIdentity(key) {
-  var storedColor = localStorage.getItem("colors/" + key);
+  let storedColor = localStorage.getItem("colors/" + key);
 
   if (storedColor == null || storedColor === "") {
     storedColor = getNextColor();
@@ -71,7 +71,7 @@ function getColorForIdentity(key) {
 }
 
 function setIdentityInLocalStorage(identityToStore, extendKey = true) {
-  var pinCode = identityToStore.pinCode;
+  let pinCode = identityToStore.pinCode;
   const serializedIdentity = JSON.stringify(identityToStore);
   const key = identityToStore.authentication.publicKey;
 
@@ -85,7 +85,7 @@ function setIdentityInLocalStorage(identityToStore, extendKey = true) {
 
   return encryptMessage(serializedIdentity, pinCode, "identity").then(
     encryptedIdentity => {
-      var success = true;
+      let success = true;
       if (extendKey === true) {
         success = extendPinCodeTtl(key, pinCode);
       }
@@ -112,7 +112,7 @@ function getProfileData(identity) {
       null
     ).then(executeResult => {
       if (executeResult.code === "200") {
-        var listItem = {};
+        let listItem = {};
 
         listItem.identityColor = getColorForIdentity(
           identity.authentication.publicKey
@@ -159,19 +159,19 @@ async function getIdentityFromLocalStorage(key, pinCode, extendTtl = true) {
 
 function extendPinCodeTtl(key, pinCode) {
   if (pinCode == null || pinCode === "") {
-    var now = new Date();
-    var nowMillis = now.getTime();
-    var ttl = window.sessionStorage.getItem("pincodettls/" + key);
+    let now = new Date();
+    let nowMillis = now.getTime();
+    let ttl = window.sessionStorage.getItem("pincodettls/" + key);
     if (ttl == null || ttl === "" || nowMillis >= parseInt(ttl)) {
       clearPinCodeTtl(key);
       return false;
     } else {
-      var ttl = now.getTime() + 4 * 60 * 60 * 1000;
+      let ttl = now.getTime() + 4 * 60 * 60 * 1000;
       window.sessionStorage.setItem("pincodettls/" + key, ttl);
     }
   } else {
-    var now = new Date();
-    var ttl = now.getTime() + 4 * 60 * 60 * 1000;
+    let now = new Date();
+    let ttl = now.getTime() + 4 * 60 * 60 * 1000;
     window.sessionStorage.setItem("pincodettls/" + key, ttl);
     window.sessionStorage.setItem("pincodes/" + key, pinCode);
   }
@@ -187,9 +187,9 @@ function clearPinCodeTtl(key) {
 }
 
 function getPincode(key) {
-  var now = new Date();
-  var nowMillis = now.getTime();
-  var ttl = window.sessionStorage.getItem("pincodettls/" + key);
+  let now = new Date();
+  let nowMillis = now.getTime();
+  let ttl = window.sessionStorage.getItem("pincodettls/" + key);
   if (ttl == null || ttl === "") {
     return null;
   } else {
@@ -368,13 +368,13 @@ function getCertificateForPassport(passportUUID, internal) {
     }
 
     const passportIdentity = window.currentlyAuthenticatedIdentity;
-    var passport = passportIdentity.getPassport(passportUUID);
+    let passport = passportIdentity.getPassport(passportUUID);
     if (passport === undefined || passport === null) {
       createPassportCertificate(passportUUID).then(function(keys) {
-        var cryptoData = new CryptoData();
+        let cryptoData = new CryptoData();
         cryptoData.setPublicKey(keys["publicKeyPEM"]);
         cryptoData.setPrivateKey(keys["privateKeyPEM"]);
-        var certificate = keys["certificatePEM"];
+        let certificate = keys["certificatePEM"];
         //download("passportCertificateBeforeSigning.crt", "text/plain", certificate)
         //cryptoData.setx509Certificate(keys["certificate"])
         executeRestfulFunction(
@@ -386,17 +386,17 @@ function getCertificateForPassport(passportUUID, internal) {
           passportUUID
         ).then(executeResult => {
           if (executeResult.code === "200") {
-            var signedCertificate = atob(
+            let signedCertificate = atob(
               executeResult.data["SignedCertificate"]
             );
             //download("passportCertificateAfterSigning.crt", "text/plain", signedCertificate)
-            var keyUUID = executeResult.data["CertificateUUID"];
-            var encodedChain = executeResult.data["Chain"];
+            let keyUUID = executeResult.data["CertificateUUID"];
+            let encodedChain = executeResult.data["Chain"];
             //download("rootCertificate.crt", "text/plain", atob(encodedChain[0]))
 
-            var chain = [];
+            let chain = [];
 
-            for (var i = 0; i < encodedChain.length; i++) {
+            for (let i = 0; i < encodedChain.length; i++) {
               chain.push(atob(encodedChain[i]));
             }
 
@@ -440,7 +440,7 @@ function getCertificateForPassport(passportUUID, internal) {
         });
       });
     } else {
-      var copyOfCryptoData = JSON.parse(JSON.stringify(passport));
+      let copyOfCryptoData = JSON.parse(JSON.stringify(passport));
 
       if (internal === false) {
         copyOfCryptoData["privateKey"] = "";
@@ -489,8 +489,8 @@ const connection = Penpal.connectToParent({
     createIdentity(pinCode) {
       return new Penpal.Promise(result => {
         createPassportCertificate(makeid()).then(function(keys) {
-          var newIdentity = new Identity();
-          var cryptoData = new CryptoData();
+          let newIdentity = new Identity();
+          let cryptoData = new CryptoData();
           cryptoData.setPublicKey(keys["publicKeyPEM"]);
           cryptoData.setPrivateKey(keys["privateKeyPEM"]);
           cryptoData.setx509Certificate(keys["certificatePEM"]);
@@ -517,7 +517,7 @@ const connection = Penpal.connectToParent({
     },
     listIdentities() {
       return new Penpal.Promise(result => {
-        var identities = listIdentitiesFromLocalStorage();
+        let identities = listIdentitiesFromLocalStorage();
         result({ data: identities, code: "200", status: "Identities listed" });
       });
     },
@@ -770,7 +770,7 @@ const connection = Penpal.connectToParent({
           });
         }
 
-        var success = extendPinCodeTtl(authenticationPublicKey);
+        let success = extendPinCodeTtl(authenticationPublicKey);
 
         if (success === false) {
           result({
@@ -787,8 +787,8 @@ const connection = Penpal.connectToParent({
           null
         ).then(executeResult => {
           if (executeResult.code === "200") {
-            var actionID = executeResult.data["ActionID"];
-            var QrCode = executeResult.data["QrCode"];
+            let actionID = executeResult.data["ActionID"];
+            let QrCode = executeResult.data["QrCode"];
             QRCode.toDataURL(actionID + "," + QrCode, function(err, url) {
               executeResult.data["image"] = url;
               result(executeResult);
@@ -819,7 +819,7 @@ const connection = Penpal.connectToParent({
           });
         }
 
-        var success = extendPinCodeTtl(authenticationPublicKey);
+        let success = extendPinCodeTtl(authenticationPublicKey);
 
         if (success === false) {
           result({
@@ -907,7 +907,7 @@ const connection = Penpal.connectToParent({
           return { data: "", code: "400", status: "Identity not loaded" };
         }
 
-        var success = extendPinCodeTtl(authenticationPublicKey);
+        let success = extendPinCodeTtl(authenticationPublicKey);
 
         if (success === false) {
           result({
@@ -939,7 +939,7 @@ const connection = Penpal.connectToParent({
           return { data: "", code: "400", status: "Identity not loaded" };
         }
 
-        var success = extendPinCodeTtl(authenticationPublicKey);
+        let success = extendPinCodeTtl(authenticationPublicKey);
 
         if (success === false) {
           result({
@@ -968,7 +968,7 @@ const connection = Penpal.connectToParent({
           return { data: "", code: "400", status: "Identity not loaded" };
         }
 
-        var success = extendPinCodeTtl(authenticationPublicKey);
+        let success = extendPinCodeTtl(authenticationPublicKey);
 
         if (success === false) {
           result({
@@ -981,10 +981,10 @@ const connection = Penpal.connectToParent({
         getCertificateForPassport(passportUUID, true).then(
           certificateResult => {
             if (certificateResult.code === "200") {
-              var passportCertificate =
+              let passportCertificate =
                 certificateResult.data["x509Certificate"];
-              var passportPrivateKey = certificateResult.data["privateKey"];
-              var passportChain = certificateResult.data["chain"];
+              let passportPrivateKey = certificateResult.data["privateKey"];
+              let passportChain = certificateResult.data["chain"];
 
               createOneTimePassportCertificate(
                 makeid() + "-" + passportUUID,
@@ -992,12 +992,12 @@ const connection = Penpal.connectToParent({
                 passportPrivateKey,
                 passportCertificate
               ).then(function(keys) {
-                var publicKeyOneTime = keys["publicKeyPEM"];
-                var privateKeyOneTime = keys["privateKeyPEM"];
-                var certificateOneTime = keys["certificatePEM"];
+                let publicKeyOneTime = keys["publicKeyPEM"];
+                let privateKeyOneTime = keys["privateKeyPEM"];
+                let certificateOneTime = keys["certificatePEM"];
                 passportChain.push(passportCertificate);
 
-                var oneTimeCryptoData = new CryptoData();
+                let oneTimeCryptoData = new CryptoData();
                 oneTimeCryptoData.setx509Certificate(certificateOneTime);
                 oneTimeCryptoData.setPrivateKey(privateKeyOneTime);
                 oneTimeCryptoData.setPublicKey(publicKeyOneTime);
@@ -1174,7 +1174,7 @@ const connection = Penpal.connectToParent({
           });
         }
 
-        var success = extendPinCodeTtl(authenticationPublicKey);
+        let success = extendPinCodeTtl(authenticationPublicKey);
 
         if (success === false) {
           result({
diff --git a/javascript/src/utilities/appUtility.js b/javascript/src/utilities/appUtility.js
index aea06c3..f5f84f4 100644
--- a/javascript/src/utilities/appUtility.js
+++ b/javascript/src/utilities/appUtility.js
@@ -24,11 +24,11 @@ export function makeid(len) {
   if (typeof len === "undefined") {
     len = 10;
   }
-  var text = "";
-  var possible =
+  let text = "";
+  let possible =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 
-  for (var i = 0; i < len; i++)
+  for (let i = 0; i < len; i++)
     text += possible.charAt(Math.floor(Math.random() * possible.length));
 
   return text;
@@ -60,12 +60,12 @@ export function getTimeLeftInLocalStorage() {
 }
 
 export function listIdentitiesFromLocalStorage() {
-  var serializedIdentitiesList = localStorage.getItem("identities");
-  var identities = JSON.parse(serializedIdentitiesList);
-  var identitiesResult = {};
+  let serializedIdentitiesList = localStorage.getItem("identities");
+  let identities = JSON.parse(serializedIdentitiesList);
+  let identitiesResult = {};
 
-  for (var key in identities) {
-    var profile = JSON.parse(
+  for (let key in identities) {
+    let profile = JSON.parse(
       JSON.stringify(localStorage.getItem("profiles/" + key))
     );
     if (profile != null && profile !== "") {
@@ -83,9 +83,9 @@ export function destroyIdentityFromLocalStorage(key) {
   localStorage.removeItem("profiles/" + key);
   localStorage.removeItem("colors/" + key);
 
-  var serializedIdentitiesList = localStorage.getItem("identities");
+  let serializedIdentitiesList = localStorage.getItem("identities");
 
-  var identities = JSON.parse(serializedIdentitiesList);
+  let identities = JSON.parse(serializedIdentitiesList);
 
   identities[key] = null;
 
diff --git a/javascript/src/utilities/signingUtilities.js b/javascript/src/utilities/signingUtilities.js
index db40226..b281320 100644
--- a/javascript/src/utilities/signingUtilities.js
+++ b/javascript/src/utilities/signingUtilities.js
@@ -428,7 +428,7 @@ function createCertificate(certData, issuerData = null) {
           let issuerSubjKeyExt = null;
 
           let extLength = issuerData.certificate.extensions.length;
-          for (var i = 0; i < extLength; i++) {
+          for (let i = 0; i < extLength; i++) {
             let ext = issuerData.certificate.extensions[i];
             if (ext.extnID == "2.5.29.14") {
               issuerSubjKeyExt = ext;
@@ -671,7 +671,7 @@ export function createOneTimePassportCertificate(
   privateKeyIssuerArg,
   certicateIssuerArg
 ) {
-  var certData = null;
+  let certData = null;
   if (emailArg != null && emailArg !== "") {
     certData = {
       algorithms: {
@@ -789,7 +789,7 @@ Vereign - Authentic Communication
   const hashAlg = "SHA-256";
   let cmsSignedSimpl;
 
-  var mimeHeadersTitles = [
+  let mimeHeadersTitles = [
     "Content-Type",
     "Content-Transfer-Encoding",
     "Content-ID",
@@ -813,7 +813,7 @@ Vereign - Authentic Communication
     let mimeHeadersStr = mime.substring(0, headersEnd);
 
     let headers = libmime.decodeHeaders(mimeHeadersStr);
-    for (var i = 0; i < mimeHeadersTitles.length; i++) {
+    for (let i = 0; i < mimeHeadersTitles.length; i++) {
       let key = mimeHeadersTitles[i].toLowerCase();
       if (key in headers) {
         mimeHeaders[key] = headers[key];
-- 
GitLab