New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ursa

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ursa - npm Package Compare versions

Comparing version 0.6.3 to 0.6.4

test/zorch.pem

42

lib/ursa.js

@@ -450,2 +450,42 @@ // Copyright 2012 The Obvious Corporation.

/**
* Check whether the two objects are both keys of some sort and
* have the same public part.
*/
function matchingPublicKeys(key1, key2) {
if (!(isKey(key1) && isKey(key2))) {
return false;
}
// This isn't the most efficient implementation, but it will suffice:
// We convert both to ssh form, which has very little leeway for
// variation, and compare bytes.
var ssh1 = key1.toPublicSsh(UTF8);
var ssh2 = key2.toPublicSsh(UTF8);
return ssh1 === ssh2;
}
/**
* Check whether the two objects are both keys of some sort, are
* both public or both private, and have the same contents.
*/
function equalKeys(key1, key2) {
// See above for rationale. In this case, there's no ssh form for
// private keys, so we just use PEM for that.
if (isPrivateKey(key1) && isPrivateKey(key2)) {
var pem1 = key1.toPrivatePem(UTF8);
var pem2 = key2.toPrivatePem(UTF8);
return pem1 === pem2;
}
if (isPublicKey(key1) && isPublicKey(key2)) {
return matchingPublicKeys(key1, key2);
}
return false;
}
/**
* Create a signer object.

@@ -508,2 +548,3 @@ */

createVerifier: createVerifier,
equalKeys: equalKeys,
generatePrivateKey: generatePrivateKey,

@@ -513,3 +554,4 @@ isKey: isKey,

isPublicKey: isPublicKey,
matchingPublicKeys: matchingPublicKeys,
sshFingerprint: sshFingerprint
};

2

package.json
{
"name": "ursa",
"version": "0.6.3",
"version": "0.6.4",
"keywords": [

@@ -5,0 +5,0 @@ "crypto", "key", "openssl", "private", "public", "rsa", "sign",

@@ -123,2 +123,7 @@ ursa

### ursa.equalKeys(key1, key2)
This returns `true` if and only if both arguments are key objects of
the same type (public or private) and their contents match.
### ursa.generatePrivateKey(modulusBits, exponent)

@@ -162,2 +167,8 @@

### ursa.matchingPublicKeys(key1, key2)
This returns `true` if and only if both arguments are key objects of
some sort (either can be public or private, and they don't have to
be the same) and their public aspects match each other.
### ursa.sshFingerprint(sshKey, sshEncoding, outEncoding)

@@ -164,0 +175,0 @@

@@ -34,2 +34,4 @@ // Copyright 2012 The Obvious Corporation.

var SSH_PUBLIC_KEY_FILE = fs.readFileSync(__dirname + "/blort.sshpub");
var PRIVATE_KEY_2 = fs.readFileSync(__dirname + "/zorch.pem");
var PUBLIC_KEY_2 = fs.readFileSync(__dirname + "/zorch.pub");

@@ -119,4 +121,6 @@ var PASSWORD = new Buffer("biscuits", UTF8);

PRIVATE_KEY: PRIVATE_KEY,
PRIVATE_KEY_2: PRIVATE_KEY_2,
PUBLIC_CIPHERTEXT_HEX: PUBLIC_CIPHERTEXT_HEX,
PUBLIC_KEY: PUBLIC_KEY,
PUBLIC_KEY_2: PUBLIC_KEY_2,
SSH_PUBLIC_KEY: SSH_PUBLIC_KEY,

@@ -123,0 +127,0 @@ SSH_PUBLIC_KEY_FINGERPRINT_HEX: SSH_PUBLIC_KEY_FINGERPRINT_HEX,

@@ -289,3 +289,3 @@ // Copyright 2012 The Obvious Corporation.

function testSshFingerprint() {
function test_sshFingerprint() {
var key = fixture.SSH_PUBLIC_KEY;

@@ -306,2 +306,56 @@ var finger = ursa.sshFingerprint(fixture.SSH_PUBLIC_KEY);

function test_equalKeys() {
var pub = ursa.createPublicKey(fixture.PUBLIC_KEY);
var priv = ursa.createPrivateKey(fixture.PRIVATE_KEY);
var samePub = ursa.createPublicKey(fixture.PUBLIC_KEY);
var samePriv = ursa.createPrivateKey(fixture.PRIVATE_KEY);
var diffPub = ursa.createPublicKey(fixture.PUBLIC_KEY_2);
var diffPriv = ursa.createPrivateKey(fixture.PRIVATE_KEY_2);
assert.equal(ursa.equalKeys("1", "2"), false);
assert.equal(ursa.equalKeys(123, 123), false);
assert.equal(ursa.equalKeys(pub, null), false);
assert.equal(ursa.equalKeys(true, pub), false);
assert.equal(ursa.equalKeys(pub, pub), true);
assert.equal(ursa.equalKeys(priv, priv), true);
assert.equal(ursa.equalKeys(pub, priv), false);
assert.equal(ursa.equalKeys(priv, pub), false);
assert.equal(ursa.equalKeys(pub, samePub), true);
assert.equal(ursa.equalKeys(priv, samePriv), true);
assert.equal(ursa.equalKeys(pub, diffPub), false);
assert.equal(ursa.equalKeys(priv, diffPriv), false);
}
function test_matchingPublicKeys() {
var pub = ursa.createPublicKey(fixture.PUBLIC_KEY);
var priv = ursa.createPrivateKey(fixture.PRIVATE_KEY);
var samePub = ursa.createPublicKey(fixture.PUBLIC_KEY);
var samePriv = ursa.createPrivateKey(fixture.PRIVATE_KEY);
var diffPub = ursa.createPublicKey(fixture.PUBLIC_KEY_2);
var diffPriv = ursa.createPrivateKey(fixture.PRIVATE_KEY_2);
assert.equal(ursa.matchingPublicKeys("1", "2"), false);
assert.equal(ursa.matchingPublicKeys(123, 123), false);
assert.equal(ursa.matchingPublicKeys(pub, null), false);
assert.equal(ursa.matchingPublicKeys(true, pub), false);
assert.equal(ursa.matchingPublicKeys(pub, pub), true);
assert.equal(ursa.matchingPublicKeys(priv, priv), true);
assert.equal(ursa.matchingPublicKeys(pub, priv), true);
assert.equal(ursa.matchingPublicKeys(priv, pub), true);
assert.equal(ursa.matchingPublicKeys(pub, samePub), true);
assert.equal(ursa.matchingPublicKeys(priv, samePriv), true);
assert.equal(ursa.matchingPublicKeys(pub, samePriv), true);
assert.equal(ursa.matchingPublicKeys(priv, samePub), true);
assert.equal(ursa.matchingPublicKeys(pub, diffPub), false);
assert.equal(ursa.matchingPublicKeys(pub, diffPriv), false);
assert.equal(ursa.matchingPublicKeys(priv, diffPriv), false);
assert.equal(ursa.matchingPublicKeys(priv, diffPub), false);
}
function testSigner() {

@@ -346,3 +400,5 @@ var key = ursa.createPrivateKey(fixture.PRIVATE_KEY);

testGeneratedKey();
testSshFingerprint();
test_sshFingerprint();
test_equalKeys();
test_matchingPublicKeys();
testSigner();

@@ -349,0 +405,0 @@ testVerifier();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc