Skip to content

Commit 5344d0c

Browse files
seishuntrevnorris
authored andcommitted
crypto, zlib: replace _binding with _handle
Also include whitespace fixes to appease jslint. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
1 parent a4f2f9e commit 5344d0c

File tree

2 files changed

+78
-78
lines changed

2 files changed

+78
-78
lines changed

lib/crypto.js

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -94,35 +94,35 @@ exports.createHash = exports.Hash = Hash;
9494
function Hash(algorithm, options) {
9595
if (!(this instanceof Hash))
9696
return new Hash(algorithm, options);
97-
this._binding = new binding.Hash(algorithm);
97+
this._handle = new binding.Hash(algorithm);
9898
LazyTransform.call(this, options);
9999
}
100100

101101
util.inherits(Hash, LazyTransform);
102102

103103
Hash.prototype._transform = function(chunk, encoding, callback) {
104-
this._binding.update(chunk, encoding);
104+
this._handle.update(chunk, encoding);
105105
callback();
106106
};
107107

108108
Hash.prototype._flush = function(callback) {
109109
var encoding = this._readableState.encoding || 'buffer';
110-
this.push(this._binding.digest(encoding), encoding);
110+
this.push(this._handle.digest(encoding), encoding);
111111
callback();
112112
};
113113

114114
Hash.prototype.update = function(data, encoding) {
115115
encoding = encoding || exports.DEFAULT_ENCODING;
116116
if (encoding === 'buffer' && util.isString(data))
117117
encoding = 'binary';
118-
this._binding.update(data, encoding);
118+
this._handle.update(data, encoding);
119119
return this;
120120
};
121121

122122

123123
Hash.prototype.digest = function(outputEncoding) {
124124
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
125-
return this._binding.digest(outputEncoding);
125+
return this._handle.digest(outputEncoding);
126126
};
127127

128128

@@ -131,8 +131,8 @@ exports.createHmac = exports.Hmac = Hmac;
131131
function Hmac(hmac, key, options) {
132132
if (!(this instanceof Hmac))
133133
return new Hmac(hmac, key, options);
134-
this._binding = new binding.Hmac();
135-
this._binding.init(hmac, toBuf(key));
134+
this._handle = new binding.Hmac();
135+
this._handle.init(hmac, toBuf(key));
136136
LazyTransform.call(this, options);
137137
}
138138

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

161-
this._binding.init(cipher, toBuf(password));
161+
this._handle.init(cipher, toBuf(password));
162162
this._decoder = null;
163163

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

169169
Cipher.prototype._transform = function(chunk, encoding, callback) {
170-
this.push(this._binding.update(chunk, encoding));
170+
this.push(this._handle.update(chunk, encoding));
171171
callback();
172172
};
173173

174174
Cipher.prototype._flush = function(callback) {
175175
try {
176-
this.push(this._binding.final());
176+
this.push(this._handle.final());
177177
} catch (e) {
178178
callback(e);
179179
return;
@@ -185,7 +185,7 @@ Cipher.prototype.update = function(data, inputEncoding, outputEncoding) {
185185
inputEncoding = inputEncoding || exports.DEFAULT_ENCODING;
186186
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
187187

188-
var ret = this._binding.update(data, inputEncoding);
188+
var ret = this._handle.update(data, inputEncoding);
189189

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

199199
Cipher.prototype.final = function(outputEncoding) {
200200
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
201-
var ret = this._binding.final();
201+
var ret = this._handle.final();
202202

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

211211

212212
Cipher.prototype.setAutoPadding = function(ap) {
213-
this._binding.setAutoPadding(ap);
213+
this._handle.setAutoPadding(ap);
214214
return this;
215215
};
216216

@@ -220,8 +220,8 @@ exports.createCipheriv = exports.Cipheriv = Cipheriv;
220220
function Cipheriv(cipher, key, iv, options) {
221221
if (!(this instanceof Cipheriv))
222222
return new Cipheriv(cipher, key, iv, options);
223-
this._binding = new binding.CipherBase(true);
224-
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
223+
this._handle = new binding.CipherBase(true);
224+
this._handle.initiv(cipher, toBuf(key), toBuf(iv));
225225
this._decoder = null;
226226

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

238238
Cipheriv.prototype.getAuthTag = function() {
239-
return this._binding.getAuthTag();
239+
return this._handle.getAuthTag();
240240
};
241241

242242

243243
Cipheriv.prototype.setAuthTag = function(tagbuf) {
244-
this._binding.setAuthTag(tagbuf);
244+
this._handle.setAuthTag(tagbuf);
245245
};
246246

247247
Cipheriv.prototype.setAAD = function(aadbuf) {
248-
this._binding.setAAD(aadbuf);
248+
this._handle.setAAD(aadbuf);
249249
};
250250

251251

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

257-
this._binding = new binding.CipherBase(false);
258-
this._binding.init(cipher, toBuf(password));
257+
this._handle = new binding.CipherBase(false);
258+
this._handle.init(cipher, toBuf(password));
259259
this._decoder = null;
260260

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

280-
this._binding = new binding.CipherBase(false);
281-
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
280+
this._handle = new binding.CipherBase(false);
281+
this._handle.initiv(cipher, toBuf(key), toBuf(iv));
282282
this._decoder = null;
283283

284284
LazyTransform.call(this, options);
@@ -302,16 +302,16 @@ exports.createSign = exports.Sign = Sign;
302302
function Sign(algorithm, options) {
303303
if (!(this instanceof Sign))
304304
return new Sign(algorithm, options);
305-
this._binding = new binding.Sign();
306-
this._binding.init(algorithm);
305+
this._handle = new binding.Sign();
306+
this._handle.init(algorithm);
307307

308308
stream.Writable.call(this, options);
309309
}
310310

311311
util.inherits(Sign, stream.Writable);
312312

313313
Sign.prototype._write = function(chunk, encoding, callback) {
314-
this._binding.update(chunk, encoding);
314+
this._handle.update(chunk, encoding);
315315
callback();
316316
};
317317

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

324324
var key = options.key || options;
325325
var passphrase = options.passphrase || null;
326-
var ret = this._binding.sign(toBuf(key), null, passphrase);
326+
var ret = this._handle.sign(toBuf(key), null, passphrase);
327327

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

342-
this._binding = new binding.Verify;
343-
this._binding.init(algorithm);
342+
this._handle = new binding.Verify;
343+
this._handle.init(algorithm);
344344

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

353353
Verify.prototype.verify = function(object, signature, sigEncoding) {
354354
sigEncoding = sigEncoding || exports.DEFAULT_ENCODING;
355-
return this._binding.verify(toBuf(object), toBuf(signature, sigEncoding));
355+
return this._handle.verify(toBuf(object), toBuf(signature, sigEncoding));
356356
};
357357

358358

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

386-
this._binding = new binding.DiffieHellman(sizeOrKey, generator);
386+
this._handle = new binding.DiffieHellman(sizeOrKey, generator);
387387
Object.defineProperty(this, 'verifyError', {
388388
enumerable: true,
389-
value: this._binding.verifyError,
389+
value: this._handle.verifyError,
390390
writable: false
391391
});
392392
}
@@ -399,10 +399,10 @@ exports.DiffieHellmanGroup =
399399
function DiffieHellmanGroup(name) {
400400
if (!(this instanceof DiffieHellmanGroup))
401401
return new DiffieHellmanGroup(name);
402-
this._binding = new binding.DiffieHellmanGroup(name);
402+
this._handle = new binding.DiffieHellmanGroup(name);
403403
Object.defineProperty(this, 'verifyError', {
404404
enumerable: true,
405-
value: this._binding.verifyError,
405+
value: this._handle.verifyError,
406406
writable: false
407407
});
408408
}
@@ -413,7 +413,7 @@ DiffieHellmanGroup.prototype.generateKeys =
413413
dhGenerateKeys;
414414

415415
function dhGenerateKeys(encoding) {
416-
var keys = this._binding.generateKeys();
416+
var keys = this._handle.generateKeys();
417417
encoding = encoding || exports.DEFAULT_ENCODING;
418418
if (encoding && encoding !== 'buffer')
419419
keys = keys.toString(encoding);
@@ -428,7 +428,7 @@ DiffieHellmanGroup.prototype.computeSecret =
428428
function dhComputeSecret(key, inEnc, outEnc) {
429429
inEnc = inEnc || exports.DEFAULT_ENCODING;
430430
outEnc = outEnc || exports.DEFAULT_ENCODING;
431-
var ret = this._binding.computeSecret(toBuf(key, inEnc));
431+
var ret = this._handle.computeSecret(toBuf(key, inEnc));
432432
if (outEnc && outEnc !== 'buffer')
433433
ret = ret.toString(outEnc);
434434
return ret;
@@ -440,7 +440,7 @@ DiffieHellmanGroup.prototype.getPrime =
440440
dhGetPrime;
441441

442442
function dhGetPrime(encoding) {
443-
var prime = this._binding.getPrime();
443+
var prime = this._handle.getPrime();
444444
encoding = encoding || exports.DEFAULT_ENCODING;
445445
if (encoding && encoding !== 'buffer')
446446
prime = prime.toString(encoding);
@@ -453,7 +453,7 @@ DiffieHellmanGroup.prototype.getGenerator =
453453
dhGetGenerator;
454454

455455
function dhGetGenerator(encoding) {
456-
var generator = this._binding.getGenerator();
456+
var generator = this._handle.getGenerator();
457457
encoding = encoding || exports.DEFAULT_ENCODING;
458458
if (encoding && encoding !== 'buffer')
459459
generator = generator.toString(encoding);
@@ -466,7 +466,7 @@ DiffieHellmanGroup.prototype.getPublicKey =
466466
dhGetPublicKey;
467467

468468
function dhGetPublicKey(encoding) {
469-
var key = this._binding.getPublicKey();
469+
var key = this._handle.getPublicKey();
470470
encoding = encoding || exports.DEFAULT_ENCODING;
471471
if (encoding && encoding !== 'buffer')
472472
key = key.toString(encoding);
@@ -479,7 +479,7 @@ DiffieHellmanGroup.prototype.getPrivateKey =
479479
dhGetPrivateKey;
480480

481481
function dhGetPrivateKey(encoding) {
482-
var key = this._binding.getPrivateKey();
482+
var key = this._handle.getPrivateKey();
483483
encoding = encoding || exports.DEFAULT_ENCODING;
484484
if (encoding && encoding !== 'buffer')
485485
key = key.toString(encoding);
@@ -489,14 +489,14 @@ function dhGetPrivateKey(encoding) {
489489

490490
DiffieHellman.prototype.setPublicKey = function(key, encoding) {
491491
encoding = encoding || exports.DEFAULT_ENCODING;
492-
this._binding.setPublicKey(toBuf(key, encoding));
492+
this._handle.setPublicKey(toBuf(key, encoding));
493493
return this;
494494
};
495495

496496

497497
DiffieHellman.prototype.setPrivateKey = function(key, encoding) {
498498
encoding = encoding || exports.DEFAULT_ENCODING;
499-
this._binding.setPrivateKey(toBuf(key, encoding));
499+
this._handle.setPrivateKey(toBuf(key, encoding));
500500
return this;
501501
};
502502

@@ -554,22 +554,22 @@ function Certificate() {
554554
if (!(this instanceof Certificate))
555555
return new Certificate();
556556

557-
this._binding = new binding.Certificate();
557+
this._handle = new binding.Certificate();
558558
}
559559

560560

561561
Certificate.prototype.verifySpkac = function(object) {
562-
return this._binding.verifySpkac(object);
562+
return this._handle.verifySpkac(object);
563563
};
564564

565565

566566
Certificate.prototype.exportPublicKey = function(object, encoding) {
567-
return this._binding.exportPublicKey(toBuf(object, encoding));
567+
return this._handle.exportPublicKey(toBuf(object, encoding));
568568
};
569569

570570

571571
Certificate.prototype.exportChallenge = function(object, encoding) {
572-
return this._binding.exportChallenge(toBuf(object, encoding));
572+
return this._handle.exportChallenge(toBuf(object, encoding));
573573
};
574574

575575

0 commit comments

Comments
 (0)