Merge pull request #4 from jgarzik/compressed-keys
eckey: add support for compressed or uncompressed keys
This commit is contained in:
commit
3dcf318b19
29
src/eckey.cc
29
src/eckey.cc
|
@ -108,6 +108,8 @@ void Key::Init(Handle<Object> target)
|
||||||
GetPrivate, SetPrivate);
|
GetPrivate, SetPrivate);
|
||||||
s_ct->InstanceTemplate()->SetAccessor(String::New("public"),
|
s_ct->InstanceTemplate()->SetAccessor(String::New("public"),
|
||||||
GetPublic, SetPublic);
|
GetPublic, SetPublic);
|
||||||
|
s_ct->InstanceTemplate()->SetAccessor(String::New("compressed"),
|
||||||
|
GetCompressed, SetCompressed);
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
NODE_SET_PROTOTYPE_METHOD(s_ct, "verifySignature", VerifySignature);
|
NODE_SET_PROTOTYPE_METHOD(s_ct, "verifySignature", VerifySignature);
|
||||||
|
@ -126,6 +128,7 @@ void Key::Init(Handle<Object> target)
|
||||||
|
|
||||||
Key::Key() :
|
Key::Key() :
|
||||||
lastError(NULL),
|
lastError(NULL),
|
||||||
|
isCompressed(true),
|
||||||
hasPrivate(false),
|
hasPrivate(false),
|
||||||
hasPublic(false)
|
hasPublic(false)
|
||||||
{
|
{
|
||||||
|
@ -240,6 +243,28 @@ Key::SetPrivate(Local<String> property, Local<Value> value, const AccessorInfo&
|
||||||
key->hasPrivate = true;
|
key->hasPrivate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Key::SetCompressed(Local<String> property, Local<Value> value, const AccessorInfo& info)
|
||||||
|
{
|
||||||
|
if (!value->IsBoolean()) {
|
||||||
|
ThrowException(Exception::Error(String::New("compressed must be boolean")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Key* key = node::ObjectWrap::Unwrap<Key>(info.Holder());
|
||||||
|
|
||||||
|
key->isCompressed = value->BooleanValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle<Value>
|
||||||
|
Key::GetCompressed(Local<String> property, const AccessorInfo& info)
|
||||||
|
{
|
||||||
|
HandleScope scope;
|
||||||
|
Key* key = node::ObjectWrap::Unwrap<Key>(info.Holder());
|
||||||
|
|
||||||
|
return scope.Close(Boolean::New(key->isCompressed));
|
||||||
|
}
|
||||||
|
|
||||||
Handle<Value>
|
Handle<Value>
|
||||||
Key::GetPublic(Local<String> property, const AccessorInfo& info)
|
Key::GetPublic(Local<String> property, const AccessorInfo& info)
|
||||||
{
|
{
|
||||||
|
@ -250,6 +275,10 @@ Key::GetPublic(Local<String> property, const AccessorInfo& info)
|
||||||
return scope.Close(Null());
|
return scope.Close(Null());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set compressed/uncompressed (we prefer compressed)
|
||||||
|
EC_KEY_set_conv_form(key->ec, key->isCompressed ?
|
||||||
|
POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
|
||||||
|
|
||||||
// Export public
|
// Export public
|
||||||
int pub_size = i2o_ECPublicKey(key->ec, NULL);
|
int pub_size = i2o_ECPublicKey(key->ec, NULL);
|
||||||
if (!pub_size) {
|
if (!pub_size) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ private:
|
||||||
const char *lastError;
|
const char *lastError;
|
||||||
EC_KEY *ec;
|
EC_KEY *ec;
|
||||||
|
|
||||||
|
bool isCompressed;
|
||||||
bool hasPrivate;
|
bool hasPrivate;
|
||||||
bool hasPublic;
|
bool hasPublic;
|
||||||
|
|
||||||
|
@ -70,6 +71,12 @@ public:
|
||||||
static void
|
static void
|
||||||
SetPublic(Local<String> property, Local<Value> value, const AccessorInfo& info);
|
SetPublic(Local<String> property, Local<Value> value, const AccessorInfo& info);
|
||||||
|
|
||||||
|
static Handle<Value>
|
||||||
|
GetCompressed(Local<String> property, const AccessorInfo& info);
|
||||||
|
|
||||||
|
static void
|
||||||
|
SetCompressed(Local<String> property, Local<Value> value, const AccessorInfo& info);
|
||||||
|
|
||||||
static Handle<Value>
|
static Handle<Value>
|
||||||
RegenerateSync(const Arguments& args);
|
RegenerateSync(const Arguments& args);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue