From d26734c76e1c6a1d3f1f7da831f3d9fda3fae46a Mon Sep 17 00:00:00 2001 From: Ryan Emery Date: Tue, 29 Oct 2019 09:37:57 -0500 Subject: [PATCH] feat(sha256-js): expose synchronous digest Resolves #6 The underlying digest is synchronous. The original version in the aws-sdk v2 exposed this synchronous version. Wrapping up and exposing this function maintains backwards compatibility. --- packages/sha256-js/src/jsSha256.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/sha256-js/src/jsSha256.ts b/packages/sha256-js/src/jsSha256.ts index 407b8b9f..dd5fa811 100644 --- a/packages/sha256-js/src/jsSha256.ts +++ b/packages/sha256-js/src/jsSha256.ts @@ -42,7 +42,10 @@ export class Sha256 implements Hash { } } - async digest(): Promise { + /* This synchronous method keeps compatibility + * with the v2 aws-sdk. + */ + digestSync(): Uint8Array { if (this.error) { throw this.error; } @@ -57,6 +60,15 @@ export class Sha256 implements Hash { return this.hash.digest(); } + + /* The underlying digest method here is synchronous. + * To keep the same interface with the other hash functions + * the default is to expose this as an async method. + * However, it can sometimes be useful to have a sync method. + */ + async digest(): Promise { + return this.digestSync() + } } function bufferFromSecret(secret: SourceData): Uint8Array {