1 line
219 KiB
Plaintext
1 line
219 KiB
Plaintext
|
{"version":3,"file":"decodeGoogleEarthEnterprisePacket.js","sources":["../../../../Source/Core/decodeGoogleEarthEnterpriseData.js","../../../../Source/Core/isBitSet.js","../../../../Source/Core/GoogleEarthEnterpriseTileInformation.js","../../../../Source/ThirdParty/pako.js","../../../../Source/WorkersES6/decodeGoogleEarthEnterprisePacket.js"],"sourcesContent":["import Check from \"./Check.js\";\nimport RuntimeError from \"./RuntimeError.js\";\n\nconst compressedMagic = 0x7468dead;\nconst compressedMagicSwap = 0xadde6874;\n\n/**\n * Decodes data that is received from the Google Earth Enterprise server.\n *\n * @param {ArrayBuffer} key The key used during decoding.\n * @param {ArrayBuffer} data The data to be decoded.\n *\n * @private\n */\nfunction decodeGoogleEarthEnterpriseData(key, data) {\n if (decodeGoogleEarthEnterpriseData.passThroughDataForTesting) {\n return data;\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"key\", key);\n Check.typeOf.object(\"data\", data);\n //>>includeEnd('debug');\n\n const keyLength = key.byteLength;\n if (keyLength === 0 || keyLength % 4 !== 0) {\n throw new RuntimeError(\n \"The length of key must be greater than 0 and a multiple of 4.\"\n );\n }\n\n const dataView = new DataView(data);\n const magic = dataView.getUint32(0, true);\n if (magic === compressedMagic || magic === compressedMagicSwap) {\n // Occasionally packets don't come back encoded, so just return\n return data;\n }\n\n const keyView = new DataView(key);\n\n let dp = 0;\n const dpend = data.byteLength;\n const dpend64 = dpend - (dpend % 8);\n const kpend = keyLength;\n let kp;\n let off = 8;\n\n // This algorithm is intentionally asymmetric to make it more difficult to\n // guess. Security through obscurity. :-(\n\n // while we have a full uint64 (8 bytes) left to do\n // assumes buffer is 64bit aligned (or processor doesn't care)\n while (dp < dpend64) {\n // rotate the key each time through by using the offets 16,0,8,16,0,8,...\n off = (off + 8) % 24;\n kp = off;\n\n // run through one key length xor'ing one uint64 at a time\n // then drop out to rotate the key for the next bit\n while (dp < dpend64 && kp < kpend) {\n dataView.setUint32(\n dp,\n dataView.getUint32(dp, true) ^ keyView.getUint32(kp, true),\n true\n );\n dataView.setUint32(\n dp + 4,\n dataView.getUint32(dp + 4, true) ^ keyView.getUint32(kp + 4, true),\n true\n );\n dp += 8;\n kp += 24;\n }\n }\n\n // now the remaining 1 to 7 bytes\n if (dp < dpend) {\n if (kp >= kpend) {\n // rotate the key one last time (if necessary)\n off = (off + 8) % 24;\n kp = off;\n }\n\n while (dp < dpend) {\n dataView.setUint8(dp, dataView.getUint8(dp) ^ keyView.getUint8(kp));\n dp++;\n kp++;\n }\n }\n}\n\ndecodeGoogleEarthEnterpriseData.passThroughDataForTesting = false;\nexport default decodeGoogleEarthEnterpriseData;\n","/**\n * @private\n */\nfunction isBitSet(bits, mask) {\n return (bits & mask) !== 0;\n}\nexport default isBitSet;\n","import defined from \"./defined.js\";\nimport isBitSet from \"./isBitSet.js\";\n\n// Bitmask for checking tile properties\nconst childrenBitmasks = [0x01, 0x02, 0x04, 0x08];\nconst anyChildBitmask = 0x0f;\nconst cacheFlagBitmask = 0x10; // True if there is a child subtree\nconst imageBitmask = 0x40;\nconst terrainBitmask = 0x80;\n\n/**\n * Contains information about each tile from a Google Earth Enterprise server\n *\n * @param {Number} bits Bitmask that contains the type of data and available children for each tile.\n * @param {Number} cnodeVersion Version of the request for subtree metadata.\n * @param {Number} imageryVersion Version of the request for imagery tile.\n * @param {Number} terrainVersion Version of the request for terrain tile.\n * @param {Number} imageryProvider Id of imagery provider.\n * @param {Number} terrainProvider Id of terrain provider.\n *\n * @private\n */\nfunction GoogleEarthEnterpriseTileInformation(\n bit
|