Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed May 21, 2021
1 parent 89ed17d commit 4a0b631
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
35 changes: 24 additions & 11 deletions lib/formats/putty.js
Expand Up @@ -64,7 +64,7 @@ function read(buf, options) {
assert.equal(parts[0].toLowerCase(), 'private-lines');
var privateLines = parseInt(parts[1], 10);
if (!isFinite(privateLines) || privateLines < 0 ||
privateLines > lines.length) {
privateLines > lines.length) {
throw (new Error('Invalid private-lines count'));
}

Expand All @@ -77,9 +77,7 @@ function read(buf, options) {
options.filename, 'PEM'));
}

var iv = Buffer.from(Array
.from({length: 16})
.map(function () { return 0; }));
var iv = Buffer.alloc(16, 0);
var decipher = crypto.createDecipheriv(
'aes-256-cbc',
derivePPK2EncryptionKey(options.passphrase),
Expand All @@ -95,20 +93,35 @@ function read(buf, options) {
}

var sshbuf = new SSHBuffer({buffer: privateBuf});
var privateKeyParts;
if (alg === 'ssh-dss') {
key.addPart('x', sshbuf.readPart());
privateKeyParts = [ {
name: 'x',
data: sshbuf.readBuffer()
}];
} else if (alg === 'ssh-rsa') {
key.addPart('d', sshbuf.readPart());
key.addPart('p', sshbuf.readPart());
key.addPart('q', sshbuf.readPart());
key.addPart('iqmp', sshbuf.readPart());
privateKeyParts = [
{ name: 'd', data: sshbuf.readBuffer() },
{ name: 'p', data: sshbuf.readBuffer() },
{ name: 'q', data: sshbuf.readBuffer() },
{ name: 'iqmp', data: sshbuf.readBuffer() }
];
} else if (alg.startsWith('ecdsa-sha2-nistp')) {
key.addPart('d', sshbuf.readPart());
privateKeyParts = [ {
name: 'd', data: sshbuf.readBuffer()
} ];
} else if (alg === 'ssh-ed25519') {
key.addPart('k', sshbuf.readPart());
privateKeyParts = [ {
name: 'k', data: sshbuf.readBuffer()
} ];
} else {
throw new Error('Unsupported PPK key type: ' + alg);
}

key = new PrivateKey({
type: key.type,
parts: key.parts.concat(privateKeyParts)
});
}

key.comment = comment;
Expand Down
6 changes: 0 additions & 6 deletions lib/key.js
Expand Up @@ -80,12 +80,6 @@ function Key(opts) {

Key.formats = formats;

Key.prototype.addPart = function (name, options) {
var part = Object.assign({ name: name }, options);
this.parts.push(part);
this.part[part.name] = part;
};

Key.prototype.toBuffer = function (format, options) {
if (format === undefined)
format = 'ssh';
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "sshpk",
"version": "1.16.1",
"name": "@terminus-term/sshpk",
"version": "1.17.0-beta.1",
"description": "A library for finding and using SSH public keys",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 4a0b631

Please sign in to comment.