mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 16:08:16 +00:00
add IIntegrityMetadata
interface
This commit is contained in:
parent
5c5d171791
commit
e5f17c3631
1 changed files with 17 additions and 14 deletions
31
src/index.ts
31
src/index.ts
|
@ -26,7 +26,14 @@ export const IntegrityMetadataRegex =
|
|||
export const SeparatorRegex = /[^\x21-\x7e]+/;
|
||||
|
||||
/** Integrity Metadata */
|
||||
export class IntegrityMetadata {
|
||||
export interface IIntegrityMetadata {
|
||||
alg: PrioritizedHashAlgorithm;
|
||||
val: string;
|
||||
opt?: string[];
|
||||
}
|
||||
|
||||
/** Integrity Metadata */
|
||||
export class IntegrityMetadata implements IIntegrityMetadata {
|
||||
alg: PrioritizedHashAlgorithm;
|
||||
val: string;
|
||||
opt: string[];
|
||||
|
@ -45,8 +52,8 @@ export class IntegrityMetadata {
|
|||
});
|
||||
}
|
||||
|
||||
match(integrity: { alg: PrioritizedHashAlgorithm; val: string }): boolean {
|
||||
return integrity.alg === this.alg && integrity.val === this.val;
|
||||
match({ alg, val }: IIntegrityMetadata): boolean {
|
||||
return alg === this.alg && val === this.val;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
|
@ -57,15 +64,11 @@ export class IntegrityMetadata {
|
|||
return this.toString();
|
||||
}
|
||||
|
||||
static stringify(integrity: {
|
||||
alg: PrioritizedHashAlgorithm;
|
||||
val: string;
|
||||
opt: string[];
|
||||
}): string {
|
||||
if (!integrity.alg) return "";
|
||||
if (!integrity.val) return "";
|
||||
if (!(integrity.alg in supportedHashAlgorithms)) return "";
|
||||
return `${integrity.alg}-${[integrity.val, ...integrity.opt].join("?")}`;
|
||||
static stringify({ alg, val, opt = [] }: IIntegrityMetadata): string {
|
||||
if (!alg) return "";
|
||||
if (!val) return "";
|
||||
if (!(alg in supportedHashAlgorithms)) return "";
|
||||
return `${alg}-${[val, ...opt].join("?")}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,8 +136,8 @@ export class IntegrityMetadataSet extends Map<
|
|||
return this.get(hashAlgorithm) ?? new IntegrityMetadata("");
|
||||
}
|
||||
|
||||
match(integrity: { alg: PrioritizedHashAlgorithm; val: string }): boolean {
|
||||
return this.strongest.match(integrity);
|
||||
match(integrityMetadata: IIntegrityMetadata): boolean {
|
||||
return this.strongest.match(integrityMetadata);
|
||||
}
|
||||
|
||||
join(separator = " ") {
|
||||
|
|
Loading…
Add table
Reference in a new issue