mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 16:08:16 +00:00
update getPrioritizedHashAlgorithm to return supported hash algorithm if unsupported one is provided
This commit is contained in:
parent
d7ab327e56
commit
9b64464d81
2 changed files with 15 additions and 15 deletions
11
src/index.ts
11
src/index.ts
|
@ -22,8 +22,15 @@ export function getPrioritizedHashAlgorithm(
|
|||
b: HashAlgorithm,
|
||||
): PrioritizedHashAlgorithm {
|
||||
if (a === b) return "";
|
||||
if (!(a in supportedHashAlgorithms)) return "";
|
||||
if (!(b in supportedHashAlgorithms)) return "";
|
||||
|
||||
if (!(a in supportedHashAlgorithms)) {
|
||||
return b in supportedHashAlgorithms ? b : "";
|
||||
}
|
||||
|
||||
if (!(b in supportedHashAlgorithms)) {
|
||||
return a in supportedHashAlgorithms ? a : "";
|
||||
}
|
||||
|
||||
return a < b ? b : a;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,21 +14,14 @@ test("if both hash algorithms are not supported, return the empty string", funct
|
|||
assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha1"), "");
|
||||
});
|
||||
|
||||
test.todo(
|
||||
"if one of the hash algorithms is unsupported, return the supported hash algorithm",
|
||||
function () {
|
||||
test("if one of the hash algorithms is unsupported, return the supported hash algorithm", function () {
|
||||
assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha256"), "sha256");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("if both strings are empty, return the empty string", function () {
|
||||
assert.strictEqual(getPrioritizedHashAlgorithm("", ""), "");
|
||||
});
|
||||
|
||||
test,
|
||||
todo(
|
||||
"if either is an empty string, it return the supported hash algorithm",
|
||||
function () {
|
||||
test("if either is an empty string, it return the supported hash algorithm", function () {
|
||||
assert.strictEqual(getPrioritizedHashAlgorithm("sha256", ""), "sha256");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue