Skip to content

Commit 4d1aae2

Browse files
committed
code style fix
1 parent 20373fc commit 4d1aae2

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/NodeRSA.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ var utils = require('./utils');
1515
var schemes = require('./schemes/schemes.js');
1616
var formats = require('./formats/formats.js');
1717

18-
var PUBLIC_RSA_OID = '1.2.840.113549.1.1.1';
19-
2018
module.exports = (function () {
2119
var SUPPORTED_HASH_ALGORITHMS = {
2220
node: ['md4', 'md5', 'ripemd160', 'sha', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'],
@@ -68,6 +66,7 @@ module.exports = (function () {
6866
} else if (_.isObject(key)) {
6967
this.generateKeyPair(key.b, key.e);
7068
}
69+
7170
this.setOptions(options);
7271
}
7372

@@ -110,6 +109,7 @@ module.exports = (function () {
110109
if (!schemes.isSignature(this.$options.signingScheme)) {
111110
throw Error('Unsupported signing scheme');
112111
}
112+
113113
if (this.$options.signingSchemeOptions.hash &&
114114
_.indexOf(SUPPORTED_HASH_ALGORITHMS[this.$options.environment], this.$options.signingSchemeOptions.hash) == -1) {
115115
throw Error('Unsupported hashing algorithm for ' + this.$options.environment + ' environment');
@@ -172,9 +172,10 @@ module.exports = (function () {
172172
format = EXPORT_FORMAT_ALIASES[format] || format;
173173
}
174174

175-
if(!formats.detectAndImport(this.keyPair, keyData, format) && format === undefined) {
175+
if (!formats.detectAndImport(this.keyPair, keyData, format) && format === undefined) {
176176
throw Error("Key format must be specified");
177177
}
178+
178179
this.$cache = {};
179180
};
180181

@@ -189,6 +190,7 @@ module.exports = (function () {
189190
if (!this.$cache[format]) {
190191
this.$cache[format] = formats.detectAndExport(this.keyPair, format);
191192
}
193+
192194
return this.$cache[format];
193195
};
194196

@@ -247,9 +249,11 @@ module.exports = (function () {
247249
try {
248250
buffer = _.isString(buffer) ? new Buffer(buffer, 'base64') : buffer;
249251
var res = this.keyPair.decrypt(buffer);
252+
250253
if (res === null) {
251254
throw Error('Key decrypt method returns null.');
252255
}
256+
253257
return this.$getDecryptedData(res, encoding);
254258
} catch (e) {
255259
throw Error('Error during decryption (probably incorrect key). Original error: ' + e);
@@ -268,11 +272,13 @@ module.exports = (function () {
268272
if (!this.isPrivate()) {
269273
throw Error("It is not private key");
270274
}
275+
271276
var res = this.keyPair.sign(this.$getDataForEncrypt(buffer, source_encoding));
272277

273278
if (encoding && encoding != 'buffer') {
274279
res = res.toString(encoding);
275280
}
281+
276282
return res;
277283
};
278284

src/formats/formats.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
var keyType = 'private';
3232
var keyOpt = {type: 'default'};
3333

34-
for(var i = 1; i < fmt.length; i++) {
34+
for (var i = 1; i < fmt.length; i++) {
3535
if (fmt[i]) {
3636
switch (fmt[i]) {
3737
case 'public':
@@ -64,13 +64,13 @@ module.exports = {
6464
return false;
6565
},
6666

67-
detectAndExport: function(key, format) {
67+
detectAndExport: function (key, format) {
6868
if (format) {
6969
var fmt = format.split('-');
7070
var keyType = 'private';
7171
var keyOpt = {type: 'default'};
7272

73-
for(var i = 1; i < fmt.length; i++) {
73+
for (var i = 1; i < fmt.length; i++) {
7474
if (fmt[i]) {
7575
switch (fmt[i]) {
7676
case 'public':

src/formats/pkcs1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = {
9393
}
9494
},
9595

96-
publicImport: function(key, data, options) {
96+
publicImport: function (key, data, options) {
9797
options = options || {};
9898
var buffer;
9999

src/formats/pkcs8.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module.exports = {
7474
reader.readSequence();
7575
reader.readInt(0);
7676
var header = new ber.Reader(reader.readString(0x30, true));
77+
7778
if (header.readOID(0x06, true) !== PUBLIC_RSA_OID) {
7879
throw Error('Invalid Public key format');
7980
}
@@ -93,7 +94,7 @@ module.exports = {
9394
);
9495
},
9596

96-
publicExport: function(key, options) {
97+
publicExport: function (key, options) {
9798
options = options || {};
9899

99100
var n = key.n.toBuffer();
@@ -122,7 +123,7 @@ module.exports = {
122123
}
123124
},
124125

125-
publicImport: function(key, data, options) {
126+
publicImport: function (key, data, options) {
126127
options = options || {};
127128
var buffer;
128129

@@ -146,6 +147,7 @@ module.exports = {
146147
var reader = new ber.Reader(buffer);
147148
reader.readSequence();
148149
var header = new ber.Reader(reader.readString(0x30, true));
150+
149151
if (header.readOID(0x06, true) !== PUBLIC_RSA_OID) {
150152
throw Error('Invalid Public key format');
151153
}

0 commit comments

Comments
 (0)