Skip to content
This repository has been archived by the owner on Feb 25, 2019. It is now read-only.

fix: allow passing an algorithm name to digest #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SubtleCrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class SubtleCrypto {

return new Promise((resolve, reject) => {
try {
let result = normalizedAlgorithm.digest(algorithm, data)
let result = normalizedAlgorithm.digest(normalizedAlgorithm, data)
return resolve(result)
} catch (error) {
return reject(error)
Expand Down
53 changes: 39 additions & 14 deletions test/SubtleCryptoSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,25 +596,50 @@ describe('SubtleCrypto', () => {
})

describe('with valid arguments', () => {
let promise, error
describe('passing the algorithm as an object', () => {
let promise, error

beforeEach(() => {
let algorithm = { name: 'SHA-256' }
promise = crypto.subtle.digest(algorithm, new Buffer('whatever'))
promise.then(digest => result = digest)
promise.catch(err => error = err)
})

beforeEach(() => {
let algorithm = { name: 'SHA-256' }
promise = crypto.subtle.digest(algorithm, new Buffer('whatever'))
promise.then(digest => result = digest)
promise.catch(err => error = err)
})
it('should return a promise', () => {
promise.should.be.instanceof(Promise)
})

it('should return a promise', () => {
promise.should.be.instanceof(Promise)
})
it('should resolve an ArrayBuffer', () => {
result.should.be.instanceof(ArrayBuffer)
})

it('should resolve an ArrayBuffer', () => {
result.should.be.instanceof(ArrayBuffer)
it('should not reject the promise', () => {
expect(error).to.be.undefined
})
})

it('should not reject the promise', () => {
expect(error).to.be.undefined
describe('passing the algorithm as a string', () => {
let promise, error

beforeEach(() => {
let algorithm = 'SHA-256'
promise = crypto.subtle.digest(algorithm, new Buffer('whatever'))
promise.then(digest => result = digest)
promise.catch(err => error = err)
})

it('should return a promise', () => {
promise.should.be.instanceof(Promise)
})

it('should resolve an ArrayBuffer', () => {
result.should.be.instanceof(ArrayBuffer)
})

it('should not reject the promise', () => {
expect(error).to.be.undefined
})
})
})
})
Expand Down