Skip to content

Commit

Permalink
chore: update deps (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Nov 22, 2021
1 parent 11732fd commit 94b7dbf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
12 changes: 3 additions & 9 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ export {
AWSSignerV4,
toAmz,
toDateStamp,
} from "https://deno.land/x/[email protected].1/mod.ts";
} from "https://deno.land/x/[email protected].2/mod.ts";
export type {
Credentials,
Signer,
} from "https://deno.land/x/[email protected]/mod.ts";
import { createHash } from "https://deno.land/[email protected]/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/[email protected]/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/[email protected]/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";
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 12 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { sha256Hex } from "../deps.ts";
import type { Signer } from "../deps.ts";

export interface Params {
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -74,3 +74,13 @@ function stringToHex(input: string) {
.join("")
.toUpperCase();
}

async function sha256Hex(data: string | Uint8Array): Promise<string> {
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("");
}
2 changes: 1 addition & 1 deletion test_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 94b7dbf

Please sign in to comment.