From 94b7dbfdea0aab431c24cc34e98284c17c4972d9 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 23 Nov 2021 00:01:32 +0100 Subject: [PATCH] chore: update deps (#44) --- deps.ts | 12 +++--------- docker-compose.yml | 3 +-- src/request.ts | 14 ++++++++++++-- test_deps.ts | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/deps.ts b/deps.ts index 3d582c3..dcf4cee 100644 --- a/deps.ts +++ b/deps.ts @@ -2,17 +2,11 @@ export { AWSSignerV4, toAmz, toDateStamp, -} from "https://deno.land/x/aws_sign_v4@1.0.1/mod.ts"; +} from "https://deno.land/x/aws_sign_v4@1.0.2/mod.ts"; export type { Credentials, Signer, -} from "https://deno.land/x/aws_sign_v4@1.0.0/mod.ts"; -import { createHash } from "https://deno.land/std@0.95.0/hash/mod.ts"; -export function sha256Hex(data: string | Uint8Array): string { - const hasher = createHash("sha256"); - hasher.update(data); - return hasher.toString("hex"); -} +} from "https://deno.land/x/aws_sign_v4@1.0.2/mod.ts"; export { default as parseXML } from "https://raw.githubusercontent.com/nekobato/deno-xml-parser/0bc4c2bd2f5fad36d274279978ca57eec57c680c/index.ts"; export { decode as decodeXMLEntities } from "https://deno.land/x/html_entities@v1.0/lib/xml-entities.js"; -export { pooledMap } from "https://deno.land/std@0.95.0/async/pool.ts"; +export { pooledMap } from "https://deno.land/std@0.115.1/async/pool.ts"; diff --git a/docker-compose.yml b/docker-compose.yml index f014e1e..4dfef0f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,9 @@ version: "3" services: minio: image: minio/minio - command: server /data --console-address ":9001" + command: server /data environment: MINIO_ACCESS_KEY: AKIAIOSFODNN7EXAMPLE MINIO_SECRET_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY ports: - "9000:9000" - - "9001:9001" \ No newline at end of file diff --git a/src/request.ts b/src/request.ts index 05ac574..4c14b08 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,4 +1,3 @@ -import { sha256Hex } from "../deps.ts"; import type { Signer } from "../deps.ts"; export interface Params { @@ -39,7 +38,8 @@ export async function doRequest({ }); const signedRequest = await signer.sign("s3", request); - signedRequest.headers.set("x-amz-content-sha256", sha256Hex(body ?? "")); + const contentHash = await sha256Hex(body ?? ""); + signedRequest.headers.set("x-amz-content-sha256", contentHash); if (body) { signedRequest.headers.set("content-length", body.length.toFixed(0)); } @@ -74,3 +74,13 @@ function stringToHex(input: string) { .join("") .toUpperCase(); } + +async function sha256Hex(data: string | Uint8Array): Promise { + if (typeof data === "string") { + data = encoder.encode(data); + } + const hash = await crypto.subtle.digest("SHA-256", data); + return [...new Uint8Array(hash)] + .map((b) => b.toString(16).padStart(2, "0")) + .join(""); +} diff --git a/test_deps.ts b/test_deps.ts index 7af7619..6136724 100644 --- a/test_deps.ts +++ b/test_deps.ts @@ -2,4 +2,4 @@ export { assert, assertEquals, assertThrowsAsync, -} from "https://deno.land/std@0.95.0/testing/asserts.ts"; +} from "https://deno.land/std@0.115.1/testing/asserts.ts";