Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
crypto, zlib: replace _binding with _handle
Browse files Browse the repository at this point in the history
Also include whitespace fixes to appease jslint.

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
seishun authored and trevnorris committed May 7, 2014
1 parent a4f2f9e commit 5344d0c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 78 deletions.
92 changes: 46 additions & 46 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,35 @@ exports.createHash = exports.Hash = Hash;
function Hash(algorithm, options) {
if (!(this instanceof Hash))
return new Hash(algorithm, options);
this._binding = new binding.Hash(algorithm);
this._handle = new binding.Hash(algorithm);
LazyTransform.call(this, options);
}

util.inherits(Hash, LazyTransform);

Hash.prototype._transform = function(chunk, encoding, callback) {
this._binding.update(chunk, encoding);
this._handle.update(chunk, encoding);
callback();
};

Hash.prototype._flush = function(callback) {
var encoding = this._readableState.encoding || 'buffer';
this.push(this._binding.digest(encoding), encoding);
this.push(this._handle.digest(encoding), encoding);
callback();
};

Hash.prototype.update = function(data, encoding) {
encoding = encoding || exports.DEFAULT_ENCODING;
if (encoding === 'buffer' && util.isString(data))
encoding = 'binary';
this._binding.update(data, encoding);
this._handle.update(data, encoding);
return this;
};


Hash.prototype.digest = function(outputEncoding) {
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
return this._binding.digest(outputEncoding);
return this._handle.digest(outputEncoding);
};


Expand All @@ -131,8 +131,8 @@ exports.createHmac = exports.Hmac = Hmac;
function Hmac(hmac, key, options) {
if (!(this instanceof Hmac))
return new Hmac(hmac, key, options);
this._binding = new binding.Hmac();
this._binding.init(hmac, toBuf(key));
this._handle = new binding.Hmac();
this._handle.init(hmac, toBuf(key));
LazyTransform.call(this, options);
}

Expand All @@ -156,9 +156,9 @@ exports.createCipher = exports.Cipher = Cipher;
function Cipher(cipher, password, options) {
if (!(this instanceof Cipher))
return new Cipher(cipher, password, options);
this._binding = new binding.CipherBase(true);
this._handle = new binding.CipherBase(true);

this._binding.init(cipher, toBuf(password));
this._handle.init(cipher, toBuf(password));
this._decoder = null;

LazyTransform.call(this, options);
Expand All @@ -167,13 +167,13 @@ function Cipher(cipher, password, options) {
util.inherits(Cipher, LazyTransform);

Cipher.prototype._transform = function(chunk, encoding, callback) {
this.push(this._binding.update(chunk, encoding));
this.push(this._handle.update(chunk, encoding));
callback();
};

Cipher.prototype._flush = function(callback) {
try {
this.push(this._binding.final());
this.push(this._handle.final());
} catch (e) {
callback(e);
return;
Expand All @@ -185,7 +185,7 @@ Cipher.prototype.update = function(data, inputEncoding, outputEncoding) {
inputEncoding = inputEncoding || exports.DEFAULT_ENCODING;
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;

var ret = this._binding.update(data, inputEncoding);
var ret = this._handle.update(data, inputEncoding);

if (outputEncoding && outputEncoding !== 'buffer') {
this._decoder = getDecoder(this._decoder, outputEncoding);
Expand All @@ -198,7 +198,7 @@ Cipher.prototype.update = function(data, inputEncoding, outputEncoding) {

Cipher.prototype.final = function(outputEncoding) {
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
var ret = this._binding.final();
var ret = this._handle.final();

if (outputEncoding && outputEncoding !== 'buffer') {
this._decoder = getDecoder(this._decoder, outputEncoding);
Expand All @@ -210,7 +210,7 @@ Cipher.prototype.final = function(outputEncoding) {


Cipher.prototype.setAutoPadding = function(ap) {
this._binding.setAutoPadding(ap);
this._handle.setAutoPadding(ap);
return this;
};

Expand All @@ -220,8 +220,8 @@ exports.createCipheriv = exports.Cipheriv = Cipheriv;
function Cipheriv(cipher, key, iv, options) {
if (!(this instanceof Cipheriv))
return new Cipheriv(cipher, key, iv, options);
this._binding = new binding.CipherBase(true);
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
this._handle = new binding.CipherBase(true);
this._handle.initiv(cipher, toBuf(key), toBuf(iv));
this._decoder = null;

LazyTransform.call(this, options);
Expand All @@ -236,16 +236,16 @@ Cipheriv.prototype.final = Cipher.prototype.final;
Cipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;

Cipheriv.prototype.getAuthTag = function() {
return this._binding.getAuthTag();
return this._handle.getAuthTag();
};


Cipheriv.prototype.setAuthTag = function(tagbuf) {
this._binding.setAuthTag(tagbuf);
this._handle.setAuthTag(tagbuf);
};

Cipheriv.prototype.setAAD = function(aadbuf) {
this._binding.setAAD(aadbuf);
this._handle.setAAD(aadbuf);
};


Expand All @@ -254,8 +254,8 @@ function Decipher(cipher, password, options) {
if (!(this instanceof Decipher))
return new Decipher(cipher, password, options);

this._binding = new binding.CipherBase(false);
this._binding.init(cipher, toBuf(password));
this._handle = new binding.CipherBase(false);
this._handle.init(cipher, toBuf(password));
this._decoder = null;

LazyTransform.call(this, options);
Expand All @@ -277,8 +277,8 @@ function Decipheriv(cipher, key, iv, options) {
if (!(this instanceof Decipheriv))
return new Decipheriv(cipher, key, iv, options);

this._binding = new binding.CipherBase(false);
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
this._handle = new binding.CipherBase(false);
this._handle.initiv(cipher, toBuf(key), toBuf(iv));
this._decoder = null;

LazyTransform.call(this, options);
Expand All @@ -302,16 +302,16 @@ exports.createSign = exports.Sign = Sign;
function Sign(algorithm, options) {
if (!(this instanceof Sign))
return new Sign(algorithm, options);
this._binding = new binding.Sign();
this._binding.init(algorithm);
this._handle = new binding.Sign();
this._handle.init(algorithm);

stream.Writable.call(this, options);
}

util.inherits(Sign, stream.Writable);

Sign.prototype._write = function(chunk, encoding, callback) {
this._binding.update(chunk, encoding);
this._handle.update(chunk, encoding);
callback();
};

Expand All @@ -323,7 +323,7 @@ Sign.prototype.sign = function(options, encoding) {

var key = options.key || options;
var passphrase = options.passphrase || null;
var ret = this._binding.sign(toBuf(key), null, passphrase);
var ret = this._handle.sign(toBuf(key), null, passphrase);

encoding = encoding || exports.DEFAULT_ENCODING;
if (encoding && encoding !== 'buffer')
Expand All @@ -339,8 +339,8 @@ function Verify(algorithm, options) {
if (!(this instanceof Verify))
return new Verify(algorithm, options);

this._binding = new binding.Verify;
this._binding.init(algorithm);
this._handle = new binding.Verify;
this._handle.init(algorithm);

stream.Writable.call(this, options);
}
Expand All @@ -352,7 +352,7 @@ Verify.prototype.update = Sign.prototype.update;

Verify.prototype.verify = function(object, signature, sigEncoding) {
sigEncoding = sigEncoding || exports.DEFAULT_ENCODING;
return this._binding.verify(toBuf(object), toBuf(signature, sigEncoding));
return this._handle.verify(toBuf(object), toBuf(signature, sigEncoding));
};


Expand Down Expand Up @@ -383,10 +383,10 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
else if (typeof generator !== 'number')
generator = toBuf(generator, genEncoding);

this._binding = new binding.DiffieHellman(sizeOrKey, generator);
this._handle = new binding.DiffieHellman(sizeOrKey, generator);
Object.defineProperty(this, 'verifyError', {
enumerable: true,
value: this._binding.verifyError,
value: this._handle.verifyError,
writable: false
});
}
Expand All @@ -399,10 +399,10 @@ exports.DiffieHellmanGroup =
function DiffieHellmanGroup(name) {
if (!(this instanceof DiffieHellmanGroup))
return new DiffieHellmanGroup(name);
this._binding = new binding.DiffieHellmanGroup(name);
this._handle = new binding.DiffieHellmanGroup(name);
Object.defineProperty(this, 'verifyError', {
enumerable: true,
value: this._binding.verifyError,
value: this._handle.verifyError,
writable: false
});
}
Expand All @@ -413,7 +413,7 @@ DiffieHellmanGroup.prototype.generateKeys =
dhGenerateKeys;

function dhGenerateKeys(encoding) {
var keys = this._binding.generateKeys();
var keys = this._handle.generateKeys();
encoding = encoding || exports.DEFAULT_ENCODING;
if (encoding && encoding !== 'buffer')
keys = keys.toString(encoding);
Expand All @@ -428,7 +428,7 @@ DiffieHellmanGroup.prototype.computeSecret =
function dhComputeSecret(key, inEnc, outEnc) {
inEnc = inEnc || exports.DEFAULT_ENCODING;
outEnc = outEnc || exports.DEFAULT_ENCODING;
var ret = this._binding.computeSecret(toBuf(key, inEnc));
var ret = this._handle.computeSecret(toBuf(key, inEnc));
if (outEnc && outEnc !== 'buffer')
ret = ret.toString(outEnc);
return ret;
Expand All @@ -440,7 +440,7 @@ DiffieHellmanGroup.prototype.getPrime =
dhGetPrime;

function dhGetPrime(encoding) {
var prime = this._binding.getPrime();
var prime = this._handle.getPrime();
encoding = encoding || exports.DEFAULT_ENCODING;
if (encoding && encoding !== 'buffer')
prime = prime.toString(encoding);
Expand All @@ -453,7 +453,7 @@ DiffieHellmanGroup.prototype.getGenerator =
dhGetGenerator;

function dhGetGenerator(encoding) {
var generator = this._binding.getGenerator();
var generator = this._handle.getGenerator();
encoding = encoding || exports.DEFAULT_ENCODING;
if (encoding && encoding !== 'buffer')
generator = generator.toString(encoding);
Expand All @@ -466,7 +466,7 @@ DiffieHellmanGroup.prototype.getPublicKey =
dhGetPublicKey;

function dhGetPublicKey(encoding) {
var key = this._binding.getPublicKey();
var key = this._handle.getPublicKey();
encoding = encoding || exports.DEFAULT_ENCODING;
if (encoding && encoding !== 'buffer')
key = key.toString(encoding);
Expand All @@ -479,7 +479,7 @@ DiffieHellmanGroup.prototype.getPrivateKey =
dhGetPrivateKey;

function dhGetPrivateKey(encoding) {
var key = this._binding.getPrivateKey();
var key = this._handle.getPrivateKey();
encoding = encoding || exports.DEFAULT_ENCODING;
if (encoding && encoding !== 'buffer')
key = key.toString(encoding);
Expand All @@ -489,14 +489,14 @@ function dhGetPrivateKey(encoding) {

DiffieHellman.prototype.setPublicKey = function(key, encoding) {
encoding = encoding || exports.DEFAULT_ENCODING;
this._binding.setPublicKey(toBuf(key, encoding));
this._handle.setPublicKey(toBuf(key, encoding));
return this;
};


DiffieHellman.prototype.setPrivateKey = function(key, encoding) {
encoding = encoding || exports.DEFAULT_ENCODING;
this._binding.setPrivateKey(toBuf(key, encoding));
this._handle.setPrivateKey(toBuf(key, encoding));
return this;
};

Expand Down Expand Up @@ -554,22 +554,22 @@ function Certificate() {
if (!(this instanceof Certificate))
return new Certificate();

this._binding = new binding.Certificate();
this._handle = new binding.Certificate();
}


Certificate.prototype.verifySpkac = function(object) {
return this._binding.verifySpkac(object);
return this._handle.verifySpkac(object);
};


Certificate.prototype.exportPublicKey = function(object, encoding) {
return this._binding.exportPublicKey(toBuf(object, encoding));
return this._handle.exportPublicKey(toBuf(object, encoding));
};


Certificate.prototype.exportChallenge = function(object, encoding) {
return this._binding.exportChallenge(toBuf(object, encoding));
return this._handle.exportChallenge(toBuf(object, encoding));
};


Expand Down

0 comments on commit 5344d0c

Please sign in to comment.