Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sha256-js): expose synchronous digest #7

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/sha256-js/src/jsSha256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class Sha256 implements Hash {
}
}

async digest(): Promise<Uint8Array> {
/* This synchronous method keeps compatibility
* with the v2 aws-sdk.
*/
digestSync(): Uint8Array {
if (this.error) {
throw this.error;
}
Expand All @@ -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<Uint8Array> {
return this.digestSync()
}
}

function bufferFromSecret(secret: SourceData): Uint8Array {
Expand Down