Skip to content

Commit 00fb851

Browse files
authored
feat: Use @smithy/util-utf8 (#730)
@aws-sdk/util-utf8-browser is depricated, update to the new version fixes: #699
1 parent c1531d0 commit 00fb851

File tree

11 files changed

+2940
-10169
lines changed

11 files changed

+2940
-10169
lines changed

package-lock.json

Lines changed: 2926 additions & 10147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@aws-sdk/types": "^3.222.0",
4242
"@aws-sdk/util-buffer-from": "^3.29.0",
4343
"@aws-sdk/util-hex-encoding": "^3.29.0",
44-
"@aws-sdk/util-utf8-browser": "^3.29.0",
44+
"@smithy/util-utf8": "^2.0.0",
4545
"@types/chai": "^4.2.12",
4646
"@types/mocha": "^10.0.0",
4747
"@types/node": "^18.7.18",

packages/crc32/test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "mocha";
22
import { expect } from "chai";
33
import { Crc32, AwsCrc32 } from "../src/index";
4-
import { fromUtf8 } from "@aws-sdk/util-utf8-browser";
4+
import { fromUtf8 } from "@smithy/util-utf8";
55

66
type TestVector = [Uint8Array, number];
77

packages/crc32c/test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "mocha";
22
import { expect } from "chai";
33
import { Crc32c, AwsCrc32c } from "../src";
4-
import { fromUtf8 } from "@aws-sdk/util-utf8-browser";
4+
import { fromUtf8 } from "@smithy/util-utf8";
55

66
type TestVector = [Uint8Array, number];
77

packages/sha1-browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@aws-crypto/util": "file:../util",
2323
"@aws-sdk/types": "^3.222.0",
2424
"@aws-sdk/util-locate-window": "^3.0.0",
25-
"@aws-sdk/util-utf8-browser": "^3.0.0",
25+
"@smithy/util-utf8": "^2.0.0",
2626
"tslib": "^1.11.1"
2727
},
2828
"main": "./build/index.js",

packages/sha1-browser/src/webCryptoSha1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Checksum, SourceData } from "@aws-sdk/types";
2-
import { fromUtf8 } from "@aws-sdk/util-utf8-browser";
2+
import { fromUtf8 } from "@smithy/util-utf8";
33
import { isEmptyData } from "./isEmptyData";
44
import { EMPTY_DATA_SHA_1, SHA_1_HASH, SHA_1_HMAC_ALGO } from "./constants";
55
import { locateWindow } from "@aws-sdk/util-locate-window";

packages/sha1-browser/test/webCryptoSha1.test.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import {
88
} from "../src/constants";
99
import { flushPromises } from "./testUtils.fixture";
1010
import * as sinon from "sinon";
11-
12-
import * as utf8Browser from "@aws-sdk/util-utf8-browser";
1311
import { locateWindow } from "@aws-sdk/util-locate-window";
1412

1513
describe("Sha1", () => {
@@ -22,7 +20,6 @@ describe("Sha1", () => {
2220
},
2321
};
2422

25-
sinon.stub(utf8Browser, "fromUtf8");
2623
});
2724

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

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

8278
const sha1 = new Sha1("");
8379
await flushPromises();
8480

85-
sinon.assert.calledOnce(utf8Browser.fromUtf8 as sinon.SinonStub);
86-
const [str] = (utf8Browser.fromUtf8 as sinon.SinonStub).firstCall.args;
87-
expect(str).to.eql("");
88-
8981
const [_, key] = (importKey as sinon.SinonStub).firstCall.args;
9082

91-
expect(key).to.deep.equal(new ArrayBuffer(0));
83+
expect(key).to.deep.equal(new Uint8Array(0));
9284
});
9385

9486
it("should import string secrets via the browser UTF-8 decoder", async () => {
87+
const { importKey } = locateWindow().crypto.subtle;
88+
9589
const sha1 = new Sha1("secret");
9690
await flushPromises();
9791

98-
sinon.assert.calledOnce(utf8Browser.fromUtf8 as sinon.SinonStub);
99-
const [str] = (utf8Browser.fromUtf8 as sinon.SinonStub).firstCall.args;
100-
expect(str).to.eql("secret");
92+
const [_, key] = (importKey as sinon.SinonStub).firstCall.args;
93+
94+
expect(key).to.deep.equal(new Uint8Array([ 115, 101, 99, 114, 101, 116 ]));
10195
});
10296

10397
it("should trap UTF-8 errors", async () => {

packages/sha256-browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@aws-crypto/util": "file:../util",
2424
"@aws-sdk/types": "^3.222.0",
2525
"@aws-sdk/util-locate-window": "^3.0.0",
26-
"@aws-sdk/util-utf8-browser": "^3.0.0",
26+
"@smithy/util-utf8": "^2.0.0",
2727
"tslib": "^1.11.1"
2828
},
2929
"main": "./build/index.js",

packages/sha256-browser/test/webCryptoSha256.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import { flushPromises } from "./testUtils.fixture";
1010
import * as sinon from "sinon";
1111

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

1514
describe("Sha256", () => {
@@ -22,7 +21,6 @@ describe("Sha256", () => {
2221
},
2322
};
2423

25-
sinon.stub(utf8Browser, "fromUtf8");
2624
});
2725

2826
afterEach(() => sinon.restore());

packages/util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"license": "Apache-2.0",
2222
"dependencies": {
2323
"@aws-sdk/types": "^3.222.0",
24-
"@aws-sdk/util-utf8-browser": "^3.0.0",
24+
"@smithy/util-utf8": "^2.0.0",
2525
"tslib": "^1.11.1"
2626
},
2727
"publishConfig": {

packages/util/src/convertToBuffer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

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

77
// Quick polyfill
88
const fromUtf8 =

0 commit comments

Comments
 (0)