Skip to content

Commit 473f949

Browse files
authoredJan 15, 2025
fix(crc64-nvme-crt): return checksum for empty string if called without data (#6798)
1 parent e1dff72 commit 473f949

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed
 

‎packages/crc64-nvme-crt/src/CrtCrc64Nvme.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest";
44
import { CrtCrc64Nvme } from "./CrtCrc64Nvme";
55

66
describe(CrtCrc64Nvme.name, () => {
7-
it("should throw an error if digest is called before update", async () => {
7+
it("should return checksum for empty string if digest is called before update", async () => {
88
const crc64 = new CrtCrc64Nvme();
9-
await expect(crc64.digest()).rejects.toThrowError("No data provided to checksum");
9+
const digest = await crc64.digest();
10+
expect(toBase64(digest)).toEqual("AAAAAAAAAAA=");
1011
});
1112

1213
it.each([

‎packages/crc64-nvme-crt/src/CrtCrc64Nvme.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ import { Checksum } from "@smithy/types";
33
import { toUint8Array } from "@smithy/util-utf8";
44

55
export class CrtCrc64Nvme implements Checksum {
6-
private previous: DataView | undefined;
6+
private checksum: DataView = new DataView(new ArrayBuffer(8));
77

8-
update(chunk: Uint8Array) {
9-
this.previous = checksums.crc64nvme(chunk, this.previous);
8+
update(data: Uint8Array) {
9+
this.checksum = checksums.crc64nvme(data, this.checksum);
1010
}
1111

1212
async digest() {
13-
if (!this.previous) {
14-
throw new Error("No data provided to checksum");
15-
}
16-
return toUint8Array(this.previous);
13+
return toUint8Array(this.checksum);
1714
}
1815

1916
reset() {
20-
this.previous = undefined;
17+
this.checksum = new DataView(new ArrayBuffer(8));
2118
}
2219
}

0 commit comments

Comments
 (0)