Skip to content

Commit 1525349

Browse files
committed
🐛 uuid v5 namespace validation
1 parent e61690f commit 1525349

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/uuid.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export function fromBuffer(buffer: Buffer): string {
6363

6464
export function v5(name: string, namespace: string): string {
6565
const namespaceBuffer = Buffer.from(namespace.replace(/-/g, ""), "hex");
66+
if (namespaceBuffer.length !== 16) {
67+
throw new Error("Namespace must be a 128-bit UUID");
68+
}
6669
const nameBuffer = Buffer.from(name, "utf8");
6770

6871
const hash = crypto.createHash("sha1");
@@ -83,3 +86,10 @@ export function v5(name: string, namespace: string): string {
8386
digest.subarray(10, 16).toString("hex"),
8487
].join("-");
8588
}
89+
90+
export const NameSpace = {
91+
DNS: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
92+
URL: "6ba7b811-9dad-11d1-80b4-00c04fd430c8",
93+
OID: "6ba7b812-9dad-11d1-80b4-00c04fd430c8",
94+
X500: "6ba7b814-9dad-11d1-80b4-00c04fd430c8",
95+
};

0 commit comments

Comments
 (0)