From 88b5e7668f70f7e9d2467687a7dc4e799d5f5950 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Thu, 12 Jul 2018 00:42:34 +0200 Subject: [PATCH] Added image-data hash. --- test/test.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/test/test.js b/test/test.js index 8072570..0878de2 100644 --- a/test/test.js +++ b/test/test.js @@ -2,19 +2,28 @@ (function(){ "use strict"; - function show(container, {url, isPointInPath}){ + function hashToString(hash){ + var chunks = []; + (new Uint32Array(hash)).forEach(function(num){ + chunks.push(num.toString(16)); + }); + return chunks.map(function(chunk){ + return "0".repeat(8 - chunk.length) + chunk; + }).join(""); + } + + function show(container, {url, imageData, isPointInPath}){ var display = container.querySelector(".display"); display.src = url; display.title = url; var buffer = new TextEncoder("utf-8").encode(url); - crypto.subtle.digest("SHA-256", buffer).then(function(hash){ - var chunks = []; - (new Uint32Array(hash)).forEach(function(num){ - chunks.push(num.toString(16)); - }); - container.querySelector(".hash").textContent = chunks.map(function(chunk){ - return "0".repeat(8 - chunk.length) + chunk; - }).join(""); + Promise.all([ + crypto.subtle.digest("SHA-256", buffer), + crypto.subtle.digest("SHA-256", imageData.data) + ]).then(function(hashes){ + container.querySelector(".hash").textContent = + hashToString(hashes[0]) + " / " + + hashToString(hashes[1]); }); container.querySelector(".isPointInPath").textContent = isPointInPath; } @@ -86,6 +95,7 @@ function topTest(){ var ctx = draw(canvas); return { url: canvas.toDataURL(), + imageData: ctx.getImageData(0, 0, canvas.width, canvas.height), isPointInPath: getIsPointInPath(ctx) }; } @@ -110,6 +120,7 @@ function iframeTest(iframe){ return { url: iframe_canvas.toDataURL(), + imageData: iframe_ctx.getImageData(0, 0, iframe_canvas.width, iframe_canvas.height), isPointInPath: getIsPointInPath(iframe_ctx) }; } \ No newline at end of file