mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 16:08:16 +00:00
accepts an IntegrityMetadata like object as input
This commit is contained in:
parent
5ad019029b
commit
f8aff38a6b
2 changed files with 8 additions and 3 deletions
|
@ -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,
|
||||||
|
|
|
@ -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=",
|
||||||
|
|
Loading…
Add table
Reference in a new issue