diff --git a/src/SubtleCrypto.js b/src/SubtleCrypto.js index ce5919a..a5729e9 100644 --- a/src/SubtleCrypto.js +++ b/src/SubtleCrypto.js @@ -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) diff --git a/test/SubtleCryptoSpec.js b/test/SubtleCryptoSpec.js index 956975a..23dffd1 100644 --- a/test/SubtleCryptoSpec.js +++ b/test/SubtleCryptoSpec.js @@ -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 + }) }) }) })