aboutsummaryrefslogtreecommitdiff
path: root/node_modules/create-hmac/test.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/create-hmac/test.js')
-rw-r--r--node_modules/create-hmac/test.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/node_modules/create-hmac/test.js b/node_modules/create-hmac/test.js
new file mode 100644
index 000000000..cb0cd5765
--- /dev/null
+++ b/node_modules/create-hmac/test.js
@@ -0,0 +1,41 @@
+var test = require('tape')
+
+var algorithms = ['sha1', 'sha224','sha256', 'sha384', 'sha512', 'SHA512', 'md5', 'rmd160']
+var formats = [undefined, 'base64', 'hex', 'binary']
+
+var vectors = require('hash-test-vectors/hmac')
+var createHmac = require('./browser')
+algorithms.forEach(function (alg) {
+ vectors.forEach(function (input) {
+ var key = new Buffer(input.key, 'hex')
+ var inputBuffer = new Buffer(input.data, 'hex')
+
+ formats.forEach(function (format) {
+ test('hmac(' + alg + ') w/ ' + input.data.slice(0, 6) + '... as ' + format, function (t) {
+ var hmac = createHmac(alg, key)
+
+ var formattedInput = format ? inputBuffer.toString(format) : inputBuffer
+ hmac.update(formattedInput, format)
+
+ var formattedOutput = hmac.digest(format)
+ var output = new Buffer(formattedOutput, format)
+
+ var truncated = input.truncate ? output.slice(0, input.truncate) : output
+ t.equal(truncated.toString('hex'), input[alg.toLowerCase()])
+ t.end()
+ })
+ })
+ })
+
+ vectors.forEach(function (input) {
+ test('hmac(' + alg + ') as stream w/ ' + input.data.slice(0, 6) + '...', function (t) {
+ var hmac = createHmac(alg, new Buffer(input.key, 'hex'))
+ hmac.end(input.data, 'hex')
+
+ var output = hmac.read()
+ var truncated = input.truncate ? output.slice(0, input.truncate) : output
+ t.equal(truncated.toString('hex'), input[alg.toLowerCase()])
+ t.end()
+ })
+ })
+})