Skip to content

Commit

Permalink
Fixes: #36
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmeteminkartal committed Apr 23, 2024
1 parent da8f88e commit 963fe55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/hashingAlgoritms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export const hashByteLength: Record<HashingAlgorithm, number> = {
'SHA-256': 32,
'SHA-512': 64
};

export const hashAlgorithmNodeJS: Record<HashingAlgorithm, string> = {
'SHA-256': 'sha256',
'SHA-512': 'sha512'
};
8 changes: 4 additions & 4 deletions src/zamane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TssAdressNotParsableError
} from './errors/invalidCredentialsError';
import { createHash } from 'crypto';
import { hashByteLength, HashingAlgorithm } from './hashingAlgoritms';
import { hashAlgorithmNodeJS, hashByteLength, HashingAlgorithm } from './hashingAlgoritms';
import { TimeStampRequest } from './TimeStampRequest';
import { tssRequest } from './http_utils';
import { HashLengthError } from './errors/HashLengthError';
Expand Down Expand Up @@ -46,7 +46,7 @@ export class Zamane {
autoClose: true
});

const hash = createHash(this.hashAlgorithm);
const hash = createHash(hashAlgorithmNodeJS[this.hashAlgorithm]);

stream.on('data', (chunk) => {
hash.update(chunk);
Expand All @@ -67,14 +67,14 @@ export class Zamane {
}
async hashFromContent(content: Buffer): Promise<Buffer> {
return new Promise((resolve) => {
const hash = createHash(this.hashAlgorithm);
const hash = createHash(hashAlgorithmNodeJS[this.hashAlgorithm]);
hash.update(content);
resolve(hash.digest());
});
}
async hashFromString(content: string): Promise<Buffer> {
return new Promise((resolve) => {
const hash = createHash(this.hashAlgorithm);
const hash = createHash(hashAlgorithmNodeJS[this.hashAlgorithm]);
hash.update(content);
resolve(hash.digest());
});
Expand Down

0 comments on commit 963fe55

Please sign in to comment.