Merge branch 'v0.4'
[platform/upstream/nodejs.git] / lib / crypto.js
index c7bb57b..83b2bb8 100644 (file)
@@ -29,6 +29,7 @@ try {
   var Decipher = binding.Decipher;
   var Sign = binding.Sign;
   var Verify = binding.Verify;
+  var DiffieHellman = binding.DiffieHellman;
   var crypto = true;
 } catch (e) {
 
@@ -36,7 +37,7 @@ try {
 }
 
 
-function Credentials(secureProtocol, context) {
+function Credentials(secureProtocol, flags, context) {
   if (!(this instanceof Credentials)) {
     return new Credentials(secureProtocol);
   }
@@ -56,6 +57,8 @@ function Credentials(secureProtocol, context) {
       this.context.init();
     }
   }
+
+  if (flags) this.context.setOptions(flags);
 }
 
 exports.Credentials = Credentials;
@@ -63,7 +66,10 @@ exports.Credentials = Credentials;
 
 exports.createCredentials = function(options, context) {
   if (!options) options = {};
-  var c = new Credentials(options.secureProtocol, context);
+
+  var c = new Credentials(options.secureProtocol,
+                          options.secureOptions,
+                          context);
 
   if (context) return c;
 
@@ -71,6 +77,8 @@ exports.createCredentials = function(options, context) {
 
   if (options.cert) c.context.setCert(options.cert);
 
+  if (options.ciphers) c.context.setCiphers(options.ciphers);
+
   if (options.ca) {
     if (Array.isArray(options.ca)) {
       for (var i = 0, len = options.ca.length; i < len; i++) {
@@ -140,3 +148,15 @@ exports.Verify = Verify;
 exports.createVerify = function(algorithm) {
   return (new Verify).init(algorithm);
 };
+
+exports.DiffieHellman = DiffieHellman;
+exports.createDiffieHellman = function(size_or_key, enc) {
+  if (!size_or_key) {
+    return new DiffieHellman();
+  } else if (!enc) {
+    return new DiffieHellman(size_or_key);
+  } else {
+    return new DiffieHellman(size_or_key, enc);
+  }
+
+}