Skip to content

Commit bca4182

Browse files
committed
Add tests for Uint8Array
1 parent 3fbb793 commit bca4182

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

test/fixtures.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,32 @@
154154
"sha384": "c0e14f06e49e32d73f9f52ddf1d0c5c7191609233631dadd76a567db42b78676b38fc800cc53ddb642f5c74442e62be44d727702213e3bb9223c53b767fbfb5db9d270d54c45d9cb6003d2967280b22671e2dbc6375f6ebf219c36f0d127be35e19d65a8",
155155
"ripemd160": "b725258b125e0bacb0e2307e34feb16a4d0d6aed6cb4b0eee458fc18290204289e55d962783bf52237d264cbbab25f18d89d8c798f90f558ea7b45bdf3d083340c18b9d23ba842183c5364d18bc0ffde5a8a408dd7ef02dde561a08d21c6d2325a69869b"
156156
}
157+
},
158+
{
159+
"keyuint8": [112, 97, 115, 115, 119, 111, 114, 100],
160+
"salt": "salt",
161+
"iterations": 1,
162+
"dkLen": 32,
163+
"results": {
164+
"sha1": "0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164",
165+
"sha256": "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b",
166+
"sha512": "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252",
167+
"sha224": "3c198cbdb9464b7857966bd05b7bc92bc1cc4e6e63155d4e490557fd85989497",
168+
"sha384": "c0e14f06e49e32d73f9f52ddf1d0c5c7191609233631dadd76a567db42b78676"
169+
}
170+
},
171+
{
172+
"key": "password",
173+
"saltuint8": [115, 97, 108, 116],
174+
"iterations": 1,
175+
"dkLen": 32,
176+
"results": {
177+
"sha1": "0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164",
178+
"sha256": "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b",
179+
"sha512": "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252",
180+
"sha224": "3c198cbdb9464b7857966bd05b7bc92bc1cc4e6e63155d4e490557fd85989497",
181+
"sha384": "c0e14f06e49e32d73f9f52ddf1d0c5c7191609233631dadd76a567db42b78676"
182+
}
157183
}
158184
],
159185
"invalid": [

test/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function runTests (name, compat) {
9797
}, /No callback provided to pbkdf2/)
9898
})
9999

100-
tape(name + ' should throw if the password is not a buffer or string', function (t) {
100+
tape(name + ' should throw if the password is not a buffer or string or Uint8Array', function (t) {
101101
t.plan(2)
102102

103103
t.throws(function () {
@@ -109,7 +109,7 @@ function runTests (name, compat) {
109109
}, /Password must be a buffer or string/)
110110
})
111111

112-
tape(name + ' should throw if the salt is not a buffer or string', function (t) {
112+
tape(name + ' should throw if the salt is not a buffer or string or Uint8Array', function (t) {
113113
t.plan(2)
114114

115115
t.throws(function () {
@@ -124,8 +124,16 @@ function runTests (name, compat) {
124124
var algos = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'ripemd160']
125125
algos.forEach(function (algorithm) {
126126
fixtures.valid.forEach(function (f) {
127-
var key = f.key || Buffer.from(f.keyHex, 'hex')
128-
var salt = f.salt || Buffer.from(f.saltHex, 'hex')
127+
if (f.keyuint8) {
128+
var key = new Uint8Array(f.keyuint8)
129+
} else {
130+
var key = f.key || Buffer.from(f.keyHex, 'hex')
131+
}
132+
if (f.saltuint8) {
133+
var salt = new Uint8Array(f.saltuint8)
134+
} else {
135+
var salt = f.salt || Buffer.from(f.saltHex, 'hex')
136+
}
129137
var expected = f.results[algorithm]
130138
var description = algorithm + ' encodes ' + key + ' (' + f.salt + ') with ' + algorithm + ' to ' + expected
131139

0 commit comments

Comments
 (0)