try { var binding = process.binding('crypto'); var SecureContext = binding.SecureContext; var Hmac = binding.Hmac; var Hash = _AN_Read_hash('Hash', binding); var Cipher = binding.Cipher; var Decipher = binding.Decipher; var Sign = binding.Sign; var Verify = binding.Verify; var crypto = true ; } catch (e) { var crypto = false ; } function Credentials(secureProtocol){ if (!(this instanceof Credentials)) { return new Credentials(secureProtocol); } if (!crypto) { throw new Error('node.js not compiled with openssl crypto support.') } this.context = new SecureContext(); if (secureProtocol) { _AN_Call_init('init', this.context, secureProtocol); } else { _AN_Call_init('init', this.context); } } exports.Credentials = Credentials; exports.createCredentials = function (options){ if (!options) options = { } ; var c = new Credentials(options.secureProtocol); if (options.key) c.context.setKey(options.key); if (options.cert) c.context.setCert(options.cert); if (options.ca) { if (Array.isArray(options.ca)) { for (var i = 0, len = _AN_Read_length('length', options.ca); i < len; i++ ){ c.context.addCACert(options.ca[i]); } } else { c.context.addCACert(options.ca); } } else { c.context.addRootCerts(); } return c; } ; _AN_Write_hash('Hash', exports, false , Hash); exports.createHash = function (hash){ return new Hash(hash); } ; exports.Hmac = Hmac; exports.createHmac = function (hmac, key){ return _AN_Call_init('init', (new Hmac()), hmac, key); } ; exports.Cipher = Cipher; exports.createCipher = function (cipher, key){ return _AN_Call_init('init', (new Cipher()), cipher, key); } ; exports.createCipheriv = function (cipher, key, iv){ return (new Cipher()).initiv(cipher, key, iv); } ; exports.Decipher = Decipher; exports.createDecipher = function (cipher, key){ return _AN_Call_init('init', (new Decipher()), cipher, key); } ; exports.createDecipheriv = function (cipher, key, iv){ return (new Decipher()).initiv(cipher, key, iv); } ; exports.Sign = Sign; exports.createSign = function (algorithm){ return _AN_Call_init('init', (new Sign()), algorithm); } ; exports.Verify = Verify; exports.createVerify = function (algorithm){ return _AN_Call_init('init', (new Verify()), algorithm); } ;