rename SubresourceIntegrity to IntegrityMetadataSet

This commit is contained in:
Nebel 2024-09-03 09:00:20 +09:00
parent be28d23470
commit 628cc0bdee
Signed by: nebel
GPG key ID: 79807D08C6EF6460
3 changed files with 13 additions and 12 deletions

View file

@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- Rename `SubresourceIntegrity` to `IntegrityMetadataSet`
## [0.0.2] - 2024-09-02
- Add `types` field in package.json
@ -15,7 +17,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- First release
[Unreleased]: https://github.com/kou029w/websri
[0.0.2]: https://github.com/kou029w/websri/compare/v0.0.1...v0.0.2
[0.0.1]: https://github.com/kou029w/usri/releases/tag/v0.0.1

View file

@ -97,8 +97,8 @@ export async function createIntegrityMetadata(
});
}
/** Subresource Integrity */
export class SubresourceIntegrity extends Map<
/** Integrity Metadata Set */
export class IntegrityMetadataSet extends Map<
HashAlgorithm,
IntegrityMetadata
> {
@ -155,13 +155,13 @@ export class SubresourceIntegrity extends Map<
}
}
export async function createSubresourceIntegrity(
export async function createIntegrityMetadataSet(
hashAlgorithms: HashAlgorithm[],
data: ArrayBuffer,
): Promise<SubresourceIntegrity> {
): Promise<IntegrityMetadataSet> {
const integrityMetadata = await Promise.all(
hashAlgorithms.map((alg) => createIntegrityMetadata(alg, data)),
);
return new SubresourceIntegrity(integrityMetadata.join(" "));
return new IntegrityMetadataSet(integrityMetadata.join(" "));
}

View file

@ -2,8 +2,8 @@ import assert from "node:assert/strict";
import { test } from "node:test";
import {
createIntegrityMetadata,
createSubresourceIntegrity,
SubresourceIntegrity,
createIntegrityMetadataSet,
IntegrityMetadataSet,
} from "../dist/index.js";
test("createIntegrityMetadata()", async function () {
@ -17,10 +17,10 @@ test("createIntegrityMetadata()", async function () {
);
});
test("createSubresourceIntegrity()", async function () {
test("createIntegrityMetadataSet()", async function () {
const res = new Response("Hello, world!");
const data = await res.arrayBuffer();
const sri = await createSubresourceIntegrity(["sha384", "sha512"], data);
const sri = await createIntegrityMetadataSet(["sha384", "sha512"], data);
assert.strictEqual(
sri.toString(),
@ -28,8 +28,8 @@ test("createSubresourceIntegrity()", async function () {
);
});
test("SubresourceIntegrity.strongest", async function () {
const { strongest } = new SubresourceIntegrity(`
test("IntegrityMetadataSet.strongest", async function () {
const { strongest } = new IntegrityMetadataSet(`
sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=
sha384-VbxVaw0v4Pzlgrpf4Huq//A1ZTY4x6wNVJTCpkwL6hzFczHHwSpFzbyn9MNKCJ7r
sha512-wVJ82JPBJHc9gRkRlwyP5uhX1t9dySJr2KFgYUwM2WOk3eorlLt9NgIe+dhl1c6ilKgt1JoLsmn1H256V/eUIQ==