updated createIntegrityMetadataSet to accept more flexible input types

This commit is contained in:
Nebel 2024-10-02 18:01:14 +09:00
parent 90f6a0844a
commit d740f57970
Signed by: nebel
GPG key ID: 79807D08C6EF6460
2 changed files with 5 additions and 5 deletions

View file

@ -211,15 +211,15 @@ export class IntegrityMetadataSet {
} }
export async function createIntegrityMetadataSet( export async function createIntegrityMetadataSet(
hashAlgorithms: HashAlgorithm[], hashAlgorithms: ReadonlyArray<HashAlgorithm> | HashAlgorithm,
data: ArrayBuffer, data: ArrayBuffer,
options: IntegrityMetadataSetOptions = { options: IntegrityMetadataSetOptions = {
getPrioritizedHashAlgorithm, getPrioritizedHashAlgorithm,
}, },
): Promise<IntegrityMetadataSet> { ): Promise<IntegrityMetadataSet> {
const integrityMetadata = await Promise.all( const set = await Promise.all(
hashAlgorithms.map((alg) => createIntegrityMetadata(alg, data)), [hashAlgorithms].flat().map((alg) => createIntegrityMetadata(alg, data)),
); );
return new IntegrityMetadataSet(integrityMetadata.join(" "), options); return new IntegrityMetadataSet(set, options);
} }

View file

@ -9,7 +9,7 @@ import {
test("instantiate a new IntegrityMetadataSet", async function () { test("instantiate a new IntegrityMetadataSet", async function () {
const res = new Response("Hello, world!"); const res = new Response("Hello, world!");
const data = await res.arrayBuffer(); const data = await res.arrayBuffer();
const set = await createIntegrityMetadataSet(["sha256"], data); const set = await createIntegrityMetadataSet("sha256", data);
assert(set instanceof IntegrityMetadataSet); assert(set instanceof IntegrityMetadataSet);
}); });