From b4824ae54daaa4bc036685b90305db03dd3cad87 Mon Sep 17 00:00:00 2001 From: Alexey Lunin <alexey.lunin@vereign.com> Date: Fri, 31 May 2019 15:00:11 +0400 Subject: [PATCH] replace var with let --- javascript/src/iframe/viamapi-iframe.js | 88 ++++++++-------- javascript/src/lib/pdfjs.parser.js | 100 +++++++++---------- javascript/src/utilities/signingUtilities.js | 8 +- 3 files changed, 98 insertions(+), 98 deletions(-) diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 2348078..49aa87d 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -36,15 +36,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++; @@ -56,7 +56,7 @@ function getNextColor() { } function setKeyForUUID(uuid, key) { - var storedIdentityForUuid = localStorage.getItem("keyperuuid/" + uuid); + let storedIdentityForUuid = localStorage.getItem("keyperuuid/" + uuid); if ( storedIdentityForUuid !== key && storedIdentityForUuid != null && @@ -69,7 +69,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(); @@ -80,7 +80,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; @@ -94,7 +94,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); } @@ -121,7 +121,7 @@ function getProfileData(identity) { null ).then(executeResult => { if (executeResult.code === "200") { - var listItem = {}; + let listItem = {}; listItem.identityColor = getColorForIdentity( identity.authentication.publicKey @@ -168,19 +168,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); } @@ -196,9 +196,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 { @@ -397,13 +397,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( @@ -415,17 +415,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])); } @@ -469,7 +469,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"] = ""; @@ -518,8 +518,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"]); @@ -546,7 +546,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" }); }); }, @@ -799,7 +799,7 @@ const connection = Penpal.connectToParent({ }); } - var success = extendPinCodeTtl(authenticationPublicKey); + let success = extendPinCodeTtl(authenticationPublicKey); if (success === false) { result({ @@ -816,8 +816,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); @@ -848,7 +848,7 @@ const connection = Penpal.connectToParent({ }); } - var success = extendPinCodeTtl(authenticationPublicKey); + let success = extendPinCodeTtl(authenticationPublicKey); if (success === false) { result({ @@ -936,7 +936,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({ @@ -997,7 +997,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({ @@ -1010,10 +1010,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, @@ -1021,12 +1021,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); @@ -1339,7 +1339,7 @@ const connection = Penpal.connectToParent({ }); } - var success = extendPinCodeTtl(authenticationPublicKey); + let success = extendPinCodeTtl(authenticationPublicKey); if (success === false) { result({ diff --git a/javascript/src/lib/pdfjs.parser.js b/javascript/src/lib/pdfjs.parser.js index f65c838..c0329bd 100644 --- a/javascript/src/lib/pdfjs.parser.js +++ b/javascript/src/lib/pdfjs.parser.js @@ -25,7 +25,7 @@ factory((root.pdfjsSharedGlobal = {})); //} })(window, function(exports) { - var globalScope = + let globalScope = typeof window !== "undefined" ? window : typeof global !== "undefined" @@ -34,7 +34,7 @@ ? self : this; - var isWorker = typeof window === "undefined"; + let isWorker = typeof window === "undefined"; // The global PDFJS object exposes the API // In production, it will be declared outside a global wrapper @@ -77,12 +77,12 @@ factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal); //} })(window, function(exports, sharedGlobal) { - var PDFJS = sharedGlobal.PDFJS; - var globalScope = sharedGlobal.globalScope; + let PDFJS = sharedGlobal.PDFJS; + let globalScope = sharedGlobal.globalScope; - var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; + let FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; - var TextRenderingMode = { + let TextRenderingMode = { FILL: 0, STROKE: 1, FILL_STROKE: 2, @@ -95,13 +95,13 @@ ADD_TO_PATH_FLAG: 4 }; - var ImageKind = { + let ImageKind = { GRAYSCALE_1BPP: 1, RGB_24BPP: 2, RGBA_32BPP: 3 }; - var AnnotationType = { + let AnnotationType = { TEXT: 1, LINK: 2, FREETEXT: 3, @@ -130,7 +130,7 @@ REDACT: 26 }; - var AnnotationFlag = { + let AnnotationFlag = { INVISIBLE: 0x01, HIDDEN: 0x02, PRINT: 0x04, @@ -143,7 +143,7 @@ LOCKEDCONTENTS: 0x200 }; - var AnnotationBorderStyleType = { + let AnnotationBorderStyleType = { SOLID: 1, DASHED: 2, BEVELED: 3, @@ -151,7 +151,7 @@ UNDERLINE: 5 }; - var StreamType = { + let StreamType = { UNKNOWN: 0, FLATE: 1, LZW: 2, @@ -164,7 +164,7 @@ RL: 9 }; - var FontType = { + let FontType = { UNKNOWN: 0, TYPE1: 1, TYPE1C: 2, @@ -185,7 +185,7 @@ }; // All the possible operations for an operator list. - var OPS = (PDFJS.OPS = { + let OPS = (PDFJS.OPS = { // Intentionally start from 1 so it is easy to spot bad operators that will be // 0's. dependency: 1, @@ -331,7 +331,7 @@ } } - var UNSUPPORTED_FEATURES = (PDFJS.UNSUPPORTED_FEATURES = { + let UNSUPPORTED_FEATURES = (PDFJS.UNSUPPORTED_FEATURES = { unknown: "unknown", forms: "forms", javaScript: "javaScript", @@ -349,7 +349,7 @@ if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) { return url; } - var i; + let i; if (url.charAt(0) === "/") { // absolute path i = baseUrl.indexOf("://"); @@ -361,12 +361,12 @@ return baseUrl.substring(0, i) + url; } else { // relative path - var pathLength = baseUrl.length; + let pathLength = baseUrl.length; i = baseUrl.lastIndexOf("#"); pathLength = i >= 0 ? i : pathLength; i = baseUrl.lastIndexOf("?", pathLength); pathLength = i >= 0 ? i : pathLength; - var prefixLength = baseUrl.lastIndexOf("/", pathLength); + let prefixLength = baseUrl.lastIndexOf("/", pathLength); return baseUrl.substring(0, prefixLength + 1) + url; } } @@ -378,7 +378,7 @@ } // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1) // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) - var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url); + let protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url); if (!protocol) { return allowRelative; } @@ -407,14 +407,14 @@ } PDFJS.shadow = shadow; - var LinkTarget = (PDFJS.LinkTarget = { + let LinkTarget = (PDFJS.LinkTarget = { NONE: 0, // Default value. SELF: 1, BLANK: 2, PARENT: 3, TOP: 4 }); - var LinkTargetStringMap = ["", "_self", "_blank", "_parent", "_top"]; + let LinkTargetStringMap = ["", "_self", "_blank", "_parent", "_top"]; function isExternalLinkTargetSet() { //#if !MOZCENTRAL @@ -446,12 +446,12 @@ } PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet; - var PasswordResponses = (PDFJS.PasswordResponses = { + let PasswordResponses = (PDFJS.PasswordResponses = { NEED_PASSWORD: 1, INCORRECT_PASSWORD: 2 }); - var PasswordException = (function PasswordExceptionClosure() { + let PasswordException = (function PasswordExceptionClosure() { function PasswordException(msg, code) { this.name = "PasswordException"; this.message = msg; @@ -465,7 +465,7 @@ })(); PDFJS.PasswordException = PasswordException; - var UnknownErrorException = (function UnknownErrorExceptionClosure() { + let UnknownErrorException = (function UnknownErrorExceptionClosure() { function UnknownErrorException(msg, details) { this.name = "UnknownErrorException"; this.message = msg; @@ -479,7 +479,7 @@ })(); PDFJS.UnknownErrorException = UnknownErrorException; - var InvalidPDFException = (function InvalidPDFExceptionClosure() { + let InvalidPDFException = (function InvalidPDFExceptionClosure() { function InvalidPDFException(msg) { this.name = "InvalidPDFException"; this.message = msg; @@ -492,7 +492,7 @@ })(); PDFJS.InvalidPDFException = InvalidPDFException; - var MissingPDFException = (function MissingPDFExceptionClosure() { + let MissingPDFException = (function MissingPDFExceptionClosure() { function MissingPDFException(msg) { this.name = "MissingPDFException"; this.message = msg; @@ -505,7 +505,7 @@ })(); PDFJS.MissingPDFException = MissingPDFException; - var UnexpectedResponseException = (function UnexpectedResponseExceptionClosure() { + let UnexpectedResponseException = (function UnexpectedResponseExceptionClosure() { function UnexpectedResponseException(msg, status) { this.name = "UnexpectedResponseException"; this.message = msg; @@ -519,7 +519,7 @@ })(); PDFJS.UnexpectedResponseException = UnexpectedResponseException; - var NotImplementedException = (function NotImplementedExceptionClosure() { + let NotImplementedException = (function NotImplementedExceptionClosure() { function NotImplementedException(msg) { this.message = msg; } @@ -531,7 +531,7 @@ return NotImplementedException; })(); - var MissingDataException = (function MissingDataExceptionClosure() { + let MissingDataException = (function MissingDataExceptionClosure() { function MissingDataException(begin, end) { this.begin = begin; this.end = end; @@ -545,7 +545,7 @@ return MissingDataException; })(); - var XRefParseException = (function XRefParseExceptionClosure() { + let XRefParseException = (function XRefParseExceptionClosure() { function XRefParseException(msg) { this.message = msg; } @@ -562,15 +562,15 @@ bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString" ); - var length = bytes.length; - var MAX_ARGUMENT_COUNT = 8192; + let length = bytes.length; + let MAX_ARGUMENT_COUNT = 8192; if (length < MAX_ARGUMENT_COUNT) { return String.fromCharCode.apply(null, bytes); } - var strBuf = []; - for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) { - var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length); - var chunk = bytes.subarray(i, chunkEnd); + let strBuf = []; + for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) { + let chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length); + let chunk = bytes.subarray(i, chunkEnd); strBuf.push(String.fromCharCode.apply(null, chunk)); } return strBuf.join(""); @@ -578,9 +578,9 @@ function stringToBytes(str) { assert(typeof str === "string", "Invalid argument for stringToBytes"); - var length = str.length; - var bytes = new Uint8Array(length); - for (var i = 0; i < length; ++i) { + let length = str.length; + let bytes = new Uint8Array(length); + for (let i = 0; i < length; ++i) { bytes[i] = str.charCodeAt(i) & 0xff; } return bytes; @@ -596,7 +596,7 @@ } function log2(x) { - var n = 1, + let n = 1, i = 0; while (x > n) { n <<= 1; @@ -626,9 +626,9 @@ // Lazy test the endianness of the platform // NOTE: This will be 'true' for simulated TypedArrays function isLittleEndian() { - var buffer8 = new Uint8Array(2); + let buffer8 = new Uint8Array(2); buffer8[0] = 1; - var buffer16 = new Uint16Array(buffer8.buffer); + let buffer16 = new Uint16Array(buffer8.buffer); return buffer16[0] === 1; } @@ -642,10 +642,10 @@ //#if !(FIREFOX || MOZCENTRAL || CHROME) //// Lazy test if the userAgent support CanvasTypedArrays function hasCanvasTypedArrays() { - var canvas = document.createElement("canvas"); + let canvas = document.createElement("canvas"); canvas.width = canvas.height = 1; - var ctx = canvas.getContext("2d"); - var imageData = ctx.createImageData(1, 1); + let ctx = canvas.getContext("2d"); + let imageData = ctx.createImageData(1, 1); return typeof imageData.data.buffer !== "undefined"; } @@ -656,7 +656,7 @@ } }); - var Uint32ArrayView = (function Uint32ArrayViewClosure() { + let Uint32ArrayView = (function Uint32ArrayViewClosure() { function Uint32ArrayView(buffer, length) { this.buffer = buffer; this.byteLength = buffer.length; @@ -665,11 +665,11 @@ } Uint32ArrayView.prototype = Object.create(null); - var uint32ArrayViewSetters = 0; + let uint32ArrayViewSetters = 0; function createUint32ArrayProp(index) { return { get: function() { - var buffer = this.buffer, + let buffer = this.buffer, offset = index << 2; return ( (buffer[offset] | @@ -680,7 +680,7 @@ ); }, set: function(value) { - var buffer = this.buffer, + let buffer = this.buffer, offset = index << 2; buffer[offset] = value & 255; buffer[offset + 1] = (value >> 8) & 255; @@ -709,9 +709,9 @@ //PDFJS.hasCanvasTypedArrays = true; //#endif - var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; + let IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; - var Util = (PDFJS.Util = (function UtilClosure() { + let Util = (PDFJS.Util = (function UtilClosure() { function Util() {} var rgbBuf = ["rgb(", 0, ",", 0, ",", 0, ")"]; diff --git a/javascript/src/utilities/signingUtilities.js b/javascript/src/utilities/signingUtilities.js index bcaad7e..27d23e4 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 == "") { emailArg = null; } @@ -766,7 +766,7 @@ Vereign - Authentic Communication const hashAlg = "SHA-256"; let cmsSignedSimpl; - var mimeHeadersTitles = [ + let mimeHeadersTitles = [ "Content-Type", "Content-Transfer-Encoding", "Content-ID", @@ -790,7 +790,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