accepts an IntegrityMetadata like object as input

This commit is contained in:
Nebel 2024-09-18 15:05:26 +09:00
parent 5ad019029b
commit f8aff38a6b
Signed by: nebel
GPG key ID: 79807D08C6EF6460
2 changed files with 8 additions and 3 deletions

View file

@ -51,12 +51,17 @@ export class IntegrityMetadata implements IntegrityMetadataLike {
alg: PrioritizedHashAlgorithm; alg: PrioritizedHashAlgorithm;
val: string; val: string;
opt: string[]; opt: string[];
constructor(integrity: string | null | undefined) { constructor(integrity: IntegrityMetadataLike | string | null | undefined) {
const integrityString =
typeof integrity === "object" && integrity !== null
? IntegrityMetadata.stringify(integrity)
: String(integrity ?? "").trim();
const { const {
alg = "", alg = "",
val = "", val = "",
opt, opt,
} = IntegrityMetadataRegex.exec((integrity ?? "").trim())?.groups ?? {}; } = IntegrityMetadataRegex.exec(integrityString)?.groups ?? {};
Object.assign(this, { Object.assign(this, {
alg, alg,

View file

@ -50,7 +50,7 @@ test("accepts options", function () {
}); });
}); });
test.todo("accepts an IntegrityMetadata like object as input", function () { test("accepts an IntegrityMetadata like object as input", function () {
const integrityMetadata = new IntegrityMetadata({ const integrityMetadata = new IntegrityMetadata({
alg: "sha256", alg: "sha256",
val: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=", val: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=",