mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 08:05:13 +00:00
add options to createIntegrityMetadataSet
This commit is contained in:
parent
e5f17c3631
commit
bd29bf4dc1
1 changed files with 21 additions and 6 deletions
27
src/index.ts
27
src/index.ts
|
@ -10,6 +10,11 @@ export const supportedHashAlgorithms = {
|
||||||
|
|
||||||
export type PrioritizedHashAlgorithm = "" | HashAlgorithm;
|
export type PrioritizedHashAlgorithm = "" | HashAlgorithm;
|
||||||
|
|
||||||
|
export type GetPrioritizedHashAlgorithm = (
|
||||||
|
a: HashAlgorithm,
|
||||||
|
b: HashAlgorithm,
|
||||||
|
) => PrioritizedHashAlgorithm;
|
||||||
|
|
||||||
export function getPrioritizedHashAlgorithm(
|
export function getPrioritizedHashAlgorithm(
|
||||||
a: HashAlgorithm,
|
a: HashAlgorithm,
|
||||||
b: HashAlgorithm,
|
b: HashAlgorithm,
|
||||||
|
@ -92,17 +97,24 @@ export async function createIntegrityMetadata(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Integrity Metadata Set Options */
|
||||||
|
export type IntegrityMetadataSetOptions = {
|
||||||
|
getPrioritizedHashAlgorithm: GetPrioritizedHashAlgorithm;
|
||||||
|
};
|
||||||
|
|
||||||
/** Integrity Metadata Set */
|
/** Integrity Metadata Set */
|
||||||
export class IntegrityMetadataSet extends Map<
|
export class IntegrityMetadataSet extends Map<
|
||||||
HashAlgorithm,
|
HashAlgorithm,
|
||||||
IntegrityMetadata
|
IntegrityMetadata
|
||||||
> {
|
> {
|
||||||
getPrioritizedHashAlgorithm: (
|
getPrioritizedHashAlgorithm: GetPrioritizedHashAlgorithm;
|
||||||
a: HashAlgorithm,
|
|
||||||
b: HashAlgorithm,
|
|
||||||
) => PrioritizedHashAlgorithm;
|
|
||||||
|
|
||||||
constructor(integrity: string, options = { getPrioritizedHashAlgorithm }) {
|
constructor(
|
||||||
|
integrity: string,
|
||||||
|
options: IntegrityMetadataSetOptions = {
|
||||||
|
getPrioritizedHashAlgorithm,
|
||||||
|
},
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
const integrityMetadata = integrity.split(SeparatorRegex);
|
const integrityMetadata = integrity.split(SeparatorRegex);
|
||||||
|
@ -156,10 +168,13 @@ export class IntegrityMetadataSet extends Map<
|
||||||
export async function createIntegrityMetadataSet(
|
export async function createIntegrityMetadataSet(
|
||||||
hashAlgorithms: HashAlgorithm[],
|
hashAlgorithms: HashAlgorithm[],
|
||||||
data: ArrayBuffer,
|
data: ArrayBuffer,
|
||||||
|
options: IntegrityMetadataSetOptions = {
|
||||||
|
getPrioritizedHashAlgorithm,
|
||||||
|
},
|
||||||
): Promise<IntegrityMetadataSet> {
|
): Promise<IntegrityMetadataSet> {
|
||||||
const integrityMetadata = await Promise.all(
|
const integrityMetadata = await Promise.all(
|
||||||
hashAlgorithms.map((alg) => createIntegrityMetadata(alg, data)),
|
hashAlgorithms.map((alg) => createIntegrityMetadata(alg, data)),
|
||||||
);
|
);
|
||||||
|
|
||||||
return new IntegrityMetadataSet(integrityMetadata.join(" "));
|
return new IntegrityMetadataSet(integrityMetadata.join(" "), options);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue