sshpk
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -14,5 +14,8 @@ // Copyright 2015 Joyent, Inc. | ||
function read(buf) { | ||
assert.buffer(buf, 'buf'); | ||
if (typeof (buf) !== 'string') { | ||
assert.buffer(buf, 'buf'); | ||
buf = buf.toString('ascii'); | ||
} | ||
var lines = utils.bufferSplit(buf, '\n'); | ||
var lines = buf.split('\n'); | ||
@@ -23,7 +26,7 @@ /* Defer until runtime due to circular deps */ | ||
var m = lines[0].toString().match(/*JSSTYLED*/ | ||
var m = lines[0].match(/*JSSTYLED*/ | ||
/BEGIN ([A-Z]+ )?(PUBLIC|PRIVATE) KEY/); | ||
assert.ok(m); | ||
var m2 = lines[lines.length - 2].toString().match(/*JSSTYLED*/ | ||
var m2 = lines[lines.length - 2].match(/*JSSTYLED*/ | ||
/END ([A-Z]+ )?(PUBLIC|PRIVATE) KEY/); | ||
@@ -44,5 +47,4 @@ assert.ok(m2); | ||
/* Chop off the first and last lines */ | ||
lines = lines.slice(1, -2); | ||
lines = Buffer.concat(lines); | ||
buf = new Buffer(lines.toString('ascii'), 'base64'); | ||
lines = lines.slice(1, -2).join(''); | ||
buf = new Buffer(lines, 'base64'); | ||
@@ -49,0 +51,0 @@ var der = new asn1.BerReader(buf); |
@@ -32,2 +32,4 @@ // Copyright 2015 Joyent, Inc. | ||
function read(buf) { | ||
if (typeof (buf) === 'string') | ||
buf = new Buffer(buf); | ||
assert.buffer(buf, 'buf'); | ||
@@ -34,0 +36,0 @@ |
@@ -8,5 +8,8 @@ // Copyright 2015 Joyent, Inc. | ||
function read(buf) { | ||
assert.buffer(buf); | ||
if (typeof (buf) !== 'string') { | ||
assert.buffer(buf, 'buf'); | ||
buf = buf.toString('ascii'); | ||
} | ||
var parts = buf.toString('ascii').split(' '); | ||
var parts = buf.split(' '); | ||
assert.ok(parts.length >= 2); | ||
@@ -13,0 +16,0 @@ |
@@ -121,5 +121,4 @@ // Copyright 2015 Joyent, Inc. | ||
Key.parse = function (data, format, name) { | ||
if (typeof (data) === 'string') | ||
data = new Buffer(data); | ||
assert.buffer(data, 'data'); | ||
if (typeof (data) !== 'string') | ||
assert.buffer(data, 'data'); | ||
if (format === undefined) | ||
@@ -126,0 +125,0 @@ format = 'ssh'; |
{ | ||
"name": "sshpk", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A library for finding and using SSH public keys", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
58
test.js
@@ -5,10 +5,60 @@ var fs = require('fs'); | ||
var sshf = require('ssh-fingerprint'); | ||
var httpsig = require('http-signature'); | ||
var keyPem = fs.readFileSync('foo.pem'); | ||
var keySsh = fs.readFileSync('foo.pub'); | ||
var Benchmark = require('benchmark'); | ||
var key = sk.Key.parse(keyPem, 'pem'); | ||
console.log('a %d bit %s key', key.size, key.type); | ||
console.log(key.toString('ssh')); | ||
console.log(key.fingerprint('sha256').toString()); | ||
console.log('-> using a %d bit %s key', key.size, key.type); | ||
console.log('-> fingerprint: %s', key.fingerprint('sha256').toString()); | ||
var fp = sk.Fingerprint.parse('MD5:0a:b6:37:a4:5f:e7:94:d3:31:e4:72:91:fc:0c:bb:2f'); | ||
console.log(fp.matches(key)); | ||
var keySshString = keySsh.toString(); | ||
var keyPemString = keyPem.toString(); | ||
var suite = new Benchmark.Suite(); | ||
suite.add('Key.parse(pem)', function() { | ||
sk.Key.parse(keyPem, 'pem'); | ||
}); | ||
suite.add('Key.parse(ssh)', function() { | ||
sk.Key.parse(keySsh, 'ssh'); | ||
}); | ||
suite.add('Key#fingerprint(md5).toString', function() { | ||
key.fingerprint('md5').toString(); | ||
}); | ||
suite.add('Key.parse(ssh)#fingerprint(md5).toString', function() { | ||
var k = sk.Key.parse(keySsh, 'ssh'); | ||
k.fingerprint('md5').toString(); | ||
}); | ||
suite.add('Fingerprint.parse', function() { | ||
sk.Fingerprint.parse('MD5:0a:b6:37:a4:5f:e7:94:d3:31:e4:72:91:fc:0c:bb:2f'); | ||
}); | ||
suite.add('Fingerprint#matches(Key)', function() { | ||
fp.matches(key); | ||
}); | ||
suite.add('Key#toBuffer(pem)', function() { | ||
key.toBuffer('pem'); | ||
}); | ||
suite.add('Key#toBuffer(ssh)', function() { | ||
key.toBuffer('ssh'); | ||
}); | ||
suite.add('ssh-fingerprint(md5)', function() { | ||
sshf.calculate(keySshString, {algorithm: 'md5'}); | ||
}); | ||
suite.add('node-http-sig.pemToRsaSSHKey', function() { | ||
httpsig.pemToRsaSSHKey(keyPemString, 'foo@foo.com'); | ||
}); | ||
suite.add('node-http-sig.sshKeyFingerprint', function() { | ||
httpsig.sshKeyFingerprint(keySshString); | ||
}); | ||
suite.on('cycle', function(evt) { | ||
console.log(String(evt.target)); | ||
}); | ||
suite.run({async: true}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
39054
985
1