1 |
3a515b92
|
cagy
|
var test = require('tape')
|
2 |
|
|
var crypto = require('browserify-cipher/browser')
|
3 |
|
|
var randomBytes = require('pseudorandombytes')
|
4 |
|
|
|
5 |
|
|
function runIt (i) {
|
6 |
|
|
crypto.listCiphers().forEach(function (cipher) {
|
7 |
|
|
test('run: ' + i, function (t) {
|
8 |
|
|
t.test('ciphers: ' + cipher, function (t) {
|
9 |
|
|
t.plan(1)
|
10 |
|
|
var data = randomBytes(562)
|
11 |
|
|
var password = randomBytes(20)
|
12 |
|
|
var crypter = crypto.createCipher(cipher, password)
|
13 |
|
|
var decrypter = crypto.createDecipher(cipher, password)
|
14 |
|
|
var out = []
|
15 |
|
|
out.push(decrypter.update(crypter.update(data)))
|
16 |
|
|
out.push(decrypter.update(crypter.final()))
|
17 |
|
|
if (cipher.indexOf('gcm') > -1) {
|
18 |
|
|
decrypter.setAuthTag(crypter.getAuthTag())
|
19 |
|
|
}
|
20 |
|
|
out.push(decrypter.final())
|
21 |
|
|
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'))
|
22 |
|
|
})
|
23 |
|
|
})
|
24 |
|
|
})
|
25 |
|
|
if (i < 4) {
|
26 |
|
|
setTimeout(runIt, 0, i + 1)
|
27 |
|
|
}
|
28 |
|
|
}
|
29 |
|
|
runIt(1)
|
30 |
|
|
test('getCiphers', function (t) {
|
31 |
|
|
t.plan(1)
|
32 |
|
|
t.ok(crypto.getCiphers().length, 'get ciphers returns an array')
|
33 |
|
|
})
|
34 |
|
|
|
35 |
|
|
test('through crypto browserify works', function (t) {
|
36 |
|
|
t.plan(2)
|
37 |
|
|
var crypto = require('../')
|
38 |
|
|
var cipher = 'aes-128-ctr'
|
39 |
|
|
var data = randomBytes(562)
|
40 |
|
|
var password = randomBytes(20)
|
41 |
|
|
var crypter = crypto.createCipher(cipher, password)
|
42 |
|
|
var decrypter = crypto.createDecipher(cipher, password)
|
43 |
|
|
var out = []
|
44 |
|
|
out.push(decrypter.update(crypter.update(data)))
|
45 |
|
|
out.push(decrypter.update(crypter.final()))
|
46 |
|
|
out.push(decrypter.final())
|
47 |
|
|
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'))
|
48 |
|
|
t.ok(crypto.getCiphers().length, 'get ciphers returns an array')
|
49 |
|
|
})
|