Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use @smithy/util-utf8 #730

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13,073 changes: 2,926 additions & 10,147 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@aws-sdk/types": "^3.222.0",
"@aws-sdk/util-buffer-from": "^3.29.0",
"@aws-sdk/util-hex-encoding": "^3.29.0",
"@aws-sdk/util-utf8-browser": "^3.29.0",
"@smithy/util-utf8": "^2.0.0",
"@types/chai": "^4.2.12",
"@types/mocha": "^10.0.0",
"@types/node": "^18.7.18",
Expand Down
2 changes: 1 addition & 1 deletion packages/crc32/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "mocha";
import { expect } from "chai";
import { Crc32, AwsCrc32 } from "../src/index";
import { fromUtf8 } from "@aws-sdk/util-utf8-browser";
import { fromUtf8 } from "@smithy/util-utf8";

type TestVector = [Uint8Array, number];

Expand Down
2 changes: 1 addition & 1 deletion packages/crc32c/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "mocha";
import { expect } from "chai";
import { Crc32c, AwsCrc32c } from "../src";
import { fromUtf8 } from "@aws-sdk/util-utf8-browser";
import { fromUtf8 } from "@smithy/util-utf8";

type TestVector = [Uint8Array, number];

Expand Down
2 changes: 1 addition & 1 deletion packages/sha1-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@aws-crypto/util": "file:../util",
"@aws-sdk/types": "^3.222.0",
"@aws-sdk/util-locate-window": "^3.0.0",
"@aws-sdk/util-utf8-browser": "^3.0.0",
"@smithy/util-utf8": "^2.0.0",
"tslib": "^1.11.1"
},
"main": "./build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/sha1-browser/src/webCryptoSha1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Checksum, SourceData } from "@aws-sdk/types";
import { fromUtf8 } from "@aws-sdk/util-utf8-browser";
import { fromUtf8 } from "@smithy/util-utf8";
import { isEmptyData } from "./isEmptyData";
import { EMPTY_DATA_SHA_1, SHA_1_HASH, SHA_1_HMAC_ALGO } from "./constants";
import { locateWindow } from "@aws-sdk/util-locate-window";
Expand Down
18 changes: 6 additions & 12 deletions packages/sha1-browser/test/webCryptoSha1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
} from "../src/constants";
import { flushPromises } from "./testUtils.fixture";
import * as sinon from "sinon";

import * as utf8Browser from "@aws-sdk/util-utf8-browser";
import { locateWindow } from "@aws-sdk/util-locate-window";

describe("Sha1", () => {
Expand All @@ -22,7 +20,6 @@ describe("Sha1", () => {
},
};

sinon.stub(utf8Browser, "fromUtf8");
});

afterEach(() => sinon.restore());
Expand Down Expand Up @@ -77,27 +74,24 @@ describe("Sha1", () => {

it("should convert empty string secrets to empty ArrayBuffers", async () => {
const { importKey } = locateWindow().crypto.subtle;
(utf8Browser.fromUtf8 as sinon.SinonStub).returns(new ArrayBuffer(0));

const sha1 = new Sha1("");
await flushPromises();

sinon.assert.calledOnce(utf8Browser.fromUtf8 as sinon.SinonStub);
const [str] = (utf8Browser.fromUtf8 as sinon.SinonStub).firstCall.args;
expect(str).to.eql("");

const [_, key] = (importKey as sinon.SinonStub).firstCall.args;

expect(key).to.deep.equal(new ArrayBuffer(0));
expect(key).to.deep.equal(new Uint8Array(0));
});

it("should import string secrets via the browser UTF-8 decoder", async () => {
const { importKey } = locateWindow().crypto.subtle;

const sha1 = new Sha1("secret");
await flushPromises();

sinon.assert.calledOnce(utf8Browser.fromUtf8 as sinon.SinonStub);
const [str] = (utf8Browser.fromUtf8 as sinon.SinonStub).firstCall.args;
expect(str).to.eql("secret");
const [_, key] = (importKey as sinon.SinonStub).firstCall.args;

expect(key).to.deep.equal(new Uint8Array([ 115, 101, 99, 114, 101, 116 ]));
});

it("should trap UTF-8 errors", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sha256-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@aws-crypto/util": "file:../util",
"@aws-sdk/types": "^3.222.0",
"@aws-sdk/util-locate-window": "^3.0.0",
"@aws-sdk/util-utf8-browser": "^3.0.0",
"@smithy/util-utf8": "^2.0.0",
"tslib": "^1.11.1"
},
"main": "./build/index.js",
Expand Down
2 changes: 0 additions & 2 deletions packages/sha256-browser/test/webCryptoSha256.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { flushPromises } from "./testUtils.fixture";
import * as sinon from "sinon";

import * as utf8Browser from "@aws-sdk/util-utf8-browser";
import { locateWindow } from "@aws-sdk/util-locate-window";

describe("Sha256", () => {
Expand All @@ -22,7 +21,6 @@ describe("Sha256", () => {
},
};

sinon.stub(utf8Browser, "fromUtf8");
});

afterEach(() => sinon.restore());
Expand Down
2 changes: 1 addition & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/types": "^3.222.0",
"@aws-sdk/util-utf8-browser": "^3.0.0",
"@smithy/util-utf8": "^2.0.0",
"tslib": "^1.11.1"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/convertToBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { SourceData } from "@aws-sdk/types";
import { fromUtf8 as fromUtf8Browser } from "@aws-sdk/util-utf8-browser";
import { fromUtf8 as fromUtf8Browser } from "@smithy/util-utf8";

// Quick polyfill
const fromUtf8 =
Expand Down
Loading