From ba8c4bcf8f9ec9767b0bd3b6c3fd5c4f503a84dd Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Sat, 13 May 2023 19:53:37 +0330 Subject: [PATCH] perf(crypto/hash): enhance crc generator --- core/crypto/src/hash.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/crypto/src/hash.ts b/core/crypto/src/hash.ts index 411dc864c..91cd30223 100644 --- a/core/crypto/src/hash.ts +++ b/core/crypto/src/hash.ts @@ -6,7 +6,7 @@ import type {HashGeneratorConfig} from './type.js'; * Secure **self-validate** hash generator. */ export class AlwatrHashGenerator { - constructor(public config: HashGeneratorConfig = {algorithm: 'sha1', encoding: 'base64url', crcLength: 8}) {} + constructor(public config: HashGeneratorConfig) {} /** * Generate simple hash from random data. @@ -51,7 +51,7 @@ export class AlwatrHashGenerator { * Generate crc hash. */ _generateCrc(data: BinaryLike): string { - const crc = this.generate(data); + const crc = createHash('sha1').update(data).digest(this.config.encoding); return this.config.crcLength == null || this.config.crcLength < 1 ? crc : crc.substring(0, this.config.crcLength); }