From d7d4b46c46e8847c63f7925d5b9bb4f4ae162db4 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 19 Jan 2022 00:57:57 +0800 Subject: [PATCH] sha256 --- package.json | 1 + src/websock.ts | 7 +++++++ yarn.lock | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/package.json b/package.json index f68287840..ae337fb4b 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "vite": "^2.7.2" }, "dependencies": { + "fast-sha256": "^1.3.0", "libsodium": "^0.7.9", "ogv": "^1.8.6", "ts-proto": "^1.101.0" diff --git a/src/websock.ts b/src/websock.ts index 2c6483584..67af1c139 100644 --- a/src/websock.ts +++ b/src/websock.ts @@ -1,5 +1,6 @@ import * as message from "./message.js"; import * as rendezvous from "./rendezvous.js"; +import * as sha256 from "fast-sha256"; type Keys = "message" | "open" | "close" | "error"; @@ -76,4 +77,10 @@ export default class Websock { let bytes = new Uint8Array(e.data); } } + + hash(datas: [Uint8Array]): Uint8Array { + const hasher = new sha256.Hash(); + datas.forEach((data) => hasher.update(data)); + return hasher.digest(); + } } diff --git a/yarn.lock b/yarn.lock index f1a562057..c71b7d1c5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -190,6 +190,11 @@ esbuild@^0.13.12: esbuild-windows-64 "0.13.15" esbuild-windows-arm64 "0.13.15" +fast-sha256@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/fast-sha256/-/fast-sha256-1.3.0.tgz#7916ba2054eeb255982608cccd0f6660c79b7ae6" + integrity sha512-n11RGP/lrWEFI/bWdygLxhI+pVeo1ZYIVwvvPkW7azl/rOy+F3HYRZ2K5zeE9mmkhQppyv9sQFx0JM9UabnpPQ== + fsevents@~2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"