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.4.12 to 0.4.13

71

lib/ursa.js

@@ -28,11 +28,18 @@ // Copyright 2012 The Obvious Corporation.

/** encoding constant */
var HEX = "hex";
var HEX = "hex";
/** encoding constant */
var UTF8 = "utf8";
var UTF8 = "utf8";
/** hash algorithm constant */
var MD5 = "md5";
var MD5 = "md5";
/** regex that matches PEM files, capturing the file type */
var PEM_REGEX =
/^(-----BEGIN (.*) KEY-----\n[\/+=a-zA-Z0-9\n]*\n-----END \2 KEY-----\n)/m;
/** "unboxer" key object to authenticate objects */
var theUnboxer = [ "ursa unboxer" ];
/*

@@ -49,5 +56,3 @@ * Helper functions

var str = encodeBuffer(buf, UTF8);
var match =
/^(-----BEGIN (.*) KEY-----\n[\/+=a-zA-Z0-9\n]*\n-----END \2 KEY-----\n)/m
.exec(str);
var match = PEM_REGEX.exec(str);

@@ -191,2 +196,4 @@ if (!match) {

function PublicKey(rsa) {
var self;
function getExponent(encoding) {

@@ -222,3 +229,7 @@ return encodeBuffer(rsa.getExponent(), encoding);

return {
function unbox(unboxer) {
return (unboxer === theUnboxer) ? self : undefined;
}
self = {
getExponent: getExponent,

@@ -231,3 +242,6 @@ getModulus: getModulus,

publicDecrypt: publicDecrypt,
}
unbox: unbox
};
return self;
}

@@ -343,3 +357,41 @@

/**
* Return whether the given object is a key object (either public or
* private), as constructed by this module.
*/
function isKey(obj) {
var obj2;
try {
var unbox = obj.unbox;
if (typeof unbox !== "function") {
return false;
}
obj2 = unbox(theUnboxer);
} catch (ex) {
// Ignore; can't assume that other objects obey any particular
// unboxing protocol.
// TODO: Log?
return false;
}
return obj2 !== undefined;
}
/**
* Return whether the given object is a private key object, as
* constructed by this module.
*/
function isPrivateKey(obj) {
return isKey(obj) && (obj.decrypt !== undefined);
}
/**
* Return whether the given object is a public key object (per se), as
* constructed by this module.
*/
function isPublicKey(obj) {
return isKey(obj) && !isPrivateKey(obj);
}
/*

@@ -353,3 +405,6 @@ * Initialization

generatePrivateKey: generatePrivateKey,
isKey: isKey,
isPrivateKey: isPrivateKey,
isPublicKey: isPublicKey,
sshFingerprint: sshFingerprint
};

3

package.json
{
"name": "ursa",
"version": "0.4.12",
"version": "0.4.13",
"keywords": ["crypto", "key", "openssl", "private", "public", "rsa"],

@@ -16,2 +16,3 @@ "description":

} ],
"author": "Dan Bornstein <danfuzz@milk.com>",
"maintainers": [ {

@@ -18,0 +19,0 @@ "name": "Dan Bornstein",

@@ -101,2 +101,21 @@ ursa

### ursa.isKey(obj)
Return `true` if the given object is a key object (public or private) that
was created by this module. Return `false` if not.
### ursa.isPrivateKey(obj)
Return `true` if the given object is a private key object that
was created by this module. Return `false` if not.
### ursa.isPublicKey(obj)
Return `true` if the given object is a public key object that
was created by this module. Return `false` if not.
Note that, even though all the public key operations work on private
keys, this function only returns true if the given object is a
public key, per se.
### ursa.sshFingerprint(sshKey, sshEncoding, outEncoding)

@@ -132,2 +151,15 @@

### encrypt(buf, bufEncoding, outEncoding)
This performs the "public encrypt" operation on the given buffer. The
result is always a byte sequence that is the same size as the key
associated with the instance. (For example, if the key is 2048 bits,
then the result of this operation will be 2048 bits, aka 256 bytes.)
The input buffer is limited to be no larger than the key size
minus 41 bytes.
This operation is always performed using padding mode
`RSA_PKCS1_OAEP_PADDING`.
### getExponent(encoding)

@@ -165,15 +197,2 @@

### encrypt(buf, bufEncoding, outEncoding)
This performs the "public encrypt" operation on the given buffer. The
result is always a byte sequence that is the same size as the key
associated with the instance. (For example, if the key is 2048 bits,
then the result of this operation will be 2048 bits, aka 256 bytes.)
The input buffer is limited to be no larger than the key size
minus 41 bytes.
This operation is always performed using padding mode
`RSA_PKCS1_OAEP_PADDING`.
### publicDecrypt(buf, bufEncoding, outEncoding)

@@ -190,2 +209,9 @@

### unbox(unboxer)
This is an internal method that is used in the implementation of
`ursa.isKey()` `ursa.isPrivateKey()` and `ursa.isPublicKey()`. When
called externally, it should always return `undefined`.
Private Key Methods

@@ -197,9 +223,2 @@ -------------------

### toPrivatePem(encoding)
This converts the private key data into a PEM-format file. The result
is not encrypted, so it behooves the user of this method to take care
with the result if the key is sensitive from a security standpoint,
which is often the case with such things. (YMMV of course.)
### decrypt(buf, bufEncoding, outEncoding)

@@ -216,2 +235,9 @@

### toPrivatePem(encoding)
This converts the private key data into a PEM-format file. The result
is not encrypted, so it behooves the user of this method to take care
with the result if the key is sensitive from a security standpoint,
which is often the case with such things. (YMMV of course.)
### privateEncrypt(buf, bufEncoding, outEncoding)

@@ -218,0 +244,0 @@

@@ -170,2 +170,26 @@ // Copyright 2012 The Obvious Corporation.

function testTypes() {
var pub = ursa.createPublicKey(fixture.PUBLIC_KEY);
var priv = ursa.createPrivateKey(fixture.PRIVATE_KEY);
var msg;
msg = "Problem with isKey()";
assert.equal(ursa.isKey(pub), true, msg);
assert.equal(ursa.isKey(priv), true, msg);
assert.equal(ursa.isKey(undefined), false, msg);
assert.equal(ursa.isKey("x"), false, msg);
msg = "Problem with isPublicKey()";
assert.equal(ursa.isPublicKey(pub), true, msg);
assert.equal(ursa.isPublicKey(priv), false, msg);
assert.equal(ursa.isPublicKey(undefined), false, msg);
assert.equal(ursa.isPublicKey("x"), false, msg);
msg = "Problem with isPrivateKey()";
assert.equal(ursa.isPrivateKey(pub), false, msg);
assert.equal(ursa.isPrivateKey(priv), true, msg);
assert.equal(ursa.isPrivateKey(undefined), false, msg);
assert.equal(ursa.isPrivateKey("x"), false, msg);
}
function test_fail_createPublicKey() {

@@ -233,2 +257,3 @@ // This is mostly tested at the native level. This just tests the

testBasics();
testTypes();
test_fail_createPublicKey();

@@ -235,0 +260,0 @@ test_fail_createPrivateKey();

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