|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | + |
| 5 | +if (!common.hasCrypto) { |
| 6 | + common.skip('missing crypto'); |
| 7 | + return; |
| 8 | +} |
| 9 | +const crypto = require('crypto'); |
| 10 | + |
| 11 | +// 'ClassName' : ['args', 'for', 'constructor'] |
| 12 | +const TEST_CASES = { |
| 13 | + 'Hash': ['sha1'], |
| 14 | + 'Hmac': ['sha1', 'Node'], |
| 15 | + 'Cipheriv': ['des-ede3-cbc', '0123456789abcd0123456789', '12345678'], |
| 16 | + 'Decipheriv': ['des-ede3-cbc', '0123456789abcd0123456789', '12345678'], |
| 17 | + 'Sign': ['RSA-SHA1'], |
| 18 | + 'Verify': ['RSA-SHA1'], |
| 19 | + 'DiffieHellman': [1024], |
| 20 | + 'DiffieHellmanGroup': ['modp5'], |
| 21 | + 'Credentials': [] |
| 22 | +}; |
| 23 | + |
| 24 | +if (!common.hasFipsCrypto) { |
| 25 | + TEST_CASES.Cipher = ['aes192', 'secret']; |
| 26 | + TEST_CASES.Decipher = ['aes192', 'secret']; |
| 27 | +} |
| 28 | + |
| 29 | +function entries(obj) { |
| 30 | + const ownProps = Object.keys(obj); |
| 31 | + let i = ownProps.length; |
| 32 | + const resArray = new Array(i); // preallocate the Array |
| 33 | + while (i--) |
| 34 | + resArray[i] = [ownProps[i], obj[ownProps[i]]]; |
| 35 | + |
| 36 | + return resArray; |
| 37 | +} |
| 38 | + |
| 39 | +for (const [clazz, args] of entries(TEST_CASES)) { |
| 40 | + assert(crypto[`create${clazz}`](...args) instanceof crypto[clazz]); |
| 41 | +} |
0 commit comments