Skip to content

Commit

Permalink
Make sha256 default hash type, since md4 was deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
koluch committed Jan 21, 2024
1 parent 7603b90 commit dc242b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 3 additions & 7 deletions helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,18 @@ export const SUPPORTED_DIGESTS = ["hex", "base64"] as const;
export type HashType = typeof SUPPORTED_HASHES[number];
export type HashDigest = typeof SUPPORTED_DIGESTS[number];

export function isSupportedHashType(
raw: string
): raw is HashType {
export function isSupportedHashType(raw: string): raw is HashType {
return SUPPORTED_HASHES.indexOf(raw as HashType) !== -1;
}

export function isSupportedHashDigest(
raw: unknown
): raw is HashDigest {
export function isSupportedHashDigest(raw: unknown): raw is HashDigest {
return SUPPORTED_DIGESTS.indexOf(raw as HashDigest) !== -1;
}

export function makeNameHash(
name: string,
maxLength: number = 32,
type: HashType = "md4",
type: HashType = "sha256",
digest: HashDigest = "hex"
) {
const buffer = Buffer.from(name, "utf8");
Expand Down
9 changes: 6 additions & 3 deletions tests/helpers.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ test("helpers: escapeClassName", function (t) {

test("helpers: makeNameHash", function (t) {
t.equals(
makeNameHash("default-hash-md4"),
"h154498c8f95283c6db4ebbc94bc80e69"
makeNameHash("default-hash-sha256"),
"ha62e9f3c8204092baa7c42b71bb51807"
);
t.equals(
makeNameHash("hash-sha256", 32, "sha256"),
Expand Down Expand Up @@ -49,7 +49,10 @@ test("helpers: interpolatePattern", function (t) {
"111222"
);
t.equals(
interpolatePattern("[first:p1:p2]", (name, params) => name + ' -> ' + params.join(',')),
interpolatePattern(
"[first:p1:p2]",
(name, params) => name + " -> " + params.join(",")
),
"first -> p1,p2"
);
t.end();
Expand Down

0 comments on commit dc242b3

Please sign in to comment.