Skip to content

Commit a53f2be

Browse files
committed
test code against node's crypto
1 parent 4113007 commit a53f2be

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/simple.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var test = require("tape")
2+
3+
var crypto = require('crypto')
4+
var cryptoB = require('../')
5+
6+
function assertSame (fn) {
7+
test(fn.name, function (t) {
8+
t.plan(1)
9+
fn(crypto, function (err, expected) {
10+
fn(cryptoB, function (err, actual) {
11+
t.equal(actual, expected)
12+
t.end()
13+
})
14+
})
15+
})
16+
}
17+
18+
assertSame(function sha1 (crypto, cb) {
19+
cb(null, crypto.createHash('sha1').update('hello', 'utf-8').digest('hex'))
20+
})
21+
22+
assertSame(function md5(crypto, cb) {
23+
cb(null, crypto.createHash('md5').update('hello', 'utf-8').digest('hex'))
24+
})
25+
26+
test('randomBytes', function (t) {
27+
t.plan(5)
28+
t.equal(cryptoB.randomBytes(10).length, 10)
29+
t.ok(cryptoB.randomBytes(10) instanceof Buffer)
30+
cryptoB.randomBytes(10, function(ex, bytes) {
31+
t.error(ex)
32+
t.equal(bytes.length, 10)
33+
t.ok(bytes instanceof Buffer)
34+
t.end()
35+
})
36+
})

0 commit comments

Comments
 (0)