From 5222fa22aff0730893f0813308f6b2413188e061 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Sun, 19 Mar 2023 12:01:38 +0100 Subject: [PATCH] hash to long keys --- readme.md | 2 +- src/defaultHandler.ts | 2 ++ src/tools.ts | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/tools.ts diff --git a/readme.md b/readme.md index 987b7f7..1dda669 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ Features: - [x] remove unused Schema - [x] joins - [x] table alias -- [x] generell aliases +- [x] general aliases - [x] unified response - [ ] change Schema - [ ] Key-Value Store Shortcut diff --git a/src/defaultHandler.ts b/src/defaultHandler.ts index df56e8c..076fd4b 100644 --- a/src/defaultHandler.ts +++ b/src/defaultHandler.ts @@ -3,6 +3,7 @@ import { Attribute, DB, insertResponse, readResponse, Table, writeResponse } fro import { Aggregation, checkConstraint, joinCross, Datatype, foreignConstraint, Modifier, joinNatural, onJoin, uniqueConstraint, usingJoin } from "./dbStructure.js" import { insertQuery, Query, QueryBuilder, removeQuery, selectQuery, updateQuery } from "./query.js" import { allModifierInput, joinType, onAction, primaryData } from "./types.js" +import { sha256 } from "./tools.js" export class Handler { db: DB; @@ -571,6 +572,7 @@ export class Handler { }, escapeID: (key: string): string => { if (!key || key === "" || key.includes('\u0000')) throw new Error("Can not escape empty key or with null unicode!"); + if (key.length > 64) key = sha256(key); if (key.match(/^`.+`$/g)) return key; return `\`${key.replace(/`/g, '``')}\``; }, diff --git a/src/tools.ts b/src/tools.ts new file mode 100644 index 0000000..426c000 --- /dev/null +++ b/src/tools.ts @@ -0,0 +1,3 @@ +import crypto from "crypto"; + +export const sha256 = (d: any) => crypto.createHash('sha256').update(String(d)).digest('base64'); \ No newline at end of file