Skip to content

Commit

Permalink
perf(crypto/hash): enhance crc generator
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd authored and njfamirm committed May 18, 2023
1 parent 6498852 commit ba8c4bc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/crypto/src/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ba8c4bc

Please sign in to comment.