Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changes

  • Loading branch information...
commit 83ce0777b1f1d1736eed70327ead8706c7091bc5 1 parent e27f88c
@justinfreitag authored
View
28 binding.gyp
@@ -0,0 +1,28 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'botan',
+ 'sources': [
+ 'src/node-botan.cpp'
+ ],
+ 'cflags!': [ '-fno-exceptions', '-fno-rtti' ],
+ 'cflags_cc!': [ '-fno-exceptions', '-fno-rtti' ],
+ 'cflags': [
+ '-g',
+ '-D_FILE_OFFSET_BITS=64',
+ '-D_LARGEFILE_SOURCE',
+ '-Wall',
+ '-std=c++0x'
+ ],
+ 'link_settings': {
+ 'ldflags': [
+ '<!@(pkg-config --libs-only-l --libs-only-other botan-1.10)'
+ ],
+ 'libraries': [
+ '<!@(pkg-config --libs-only-l botan-1.10)',
+ ],
+ },
+ },
+ ]
+}
+
View
16 makefile
@@ -1,16 +1,6 @@
-make: all
-
-all: waf test
-
-waf:
- node-waf configure build
-
-debug:
- node-waf configure --debug=true build
-
-test:
- @mocha /test/node-botan-test.js
+build:
+ node-gyp build
clean:
- @rm -rf ./build
+ node-gyp clean
View
6 package.json
@@ -2,7 +2,7 @@
"name": "botan",
"author": "Justin Freitag",
"description": "Fully asynchronous Botan wrapper with RSA/public-key, cipher, hash, mac, codec, PBKDF, rnd support",
- "version": "0.0.1",
+ "version": "0.0.2",
"main": "build/Release/botan",
"devDependencies": {
"mocha": "~0.11",
@@ -12,6 +12,6 @@
"test": "mocha -t 30000 -R list -r should test/node-botan-test"
},
"engines": {
- "node": "~0.6"
+ "node": "~0.8"
}
-}
+}
View
472 node-botan.cpp → src/node-botan.cpp
@@ -15,6 +15,8 @@
#define THROW_BAD_ARGS \
THROW_TYPE_ERROR("Bad argument/s")
+namespace node_botan {
+
using namespace v8;
using namespace node;
using namespace Botan;
@@ -28,7 +30,7 @@ using namespace pbkdf;
using namespace rnd;
SecureVector<byte> *toSecureVector(Local<Value> object) {
- SecureVector<byte> *secureVector;
+ SecureVector<byte> *secureVector = NULL;
if (object->IsString()) {
String::Utf8Value string(object->ToString());
secureVector = new SecureVector<byte>((byte *) *string, string.length());
@@ -92,13 +94,14 @@ Handle<Value> pk::Generate(const Arguments &args) {
else
baton->keySize = args[0]->NumberValue();
- eio_custom(EIO_Generate, EIO_PRI_DEFAULT, EIO_AfterGenerate, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingGenerate, AfterGenerate);
return scope.Close(Undefined());
}
-void pk::EIO_Generate(eio_req *request) {
+void pk::DoingGenerate(uv_work_t *request) {
GenerateBaton *baton = static_cast<GenerateBaton *>(request->data);
try {
@@ -111,11 +114,9 @@ void pk::EIO_Generate(eio_req *request) {
}
}
-int pk::EIO_AfterGenerate(eio_req *request) {
+void pk::AfterGenerate(uv_work_t *request) {
GenerateBaton *baton = static_cast<GenerateBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> publicKey = Null();
Handle<Value> privateKey = Null();
@@ -140,8 +141,7 @@ int pk::EIO_AfterGenerate(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> pk::LoadPublicKey(const Arguments &args) {
@@ -153,13 +153,14 @@ Handle<Value> pk::LoadPublicKey(const Arguments &args) {
LoadPublicKeyBaton *baton = new LoadPublicKeyBaton(args[1]);
baton->publicKeyString = toString(args[0]);
- eio_custom(EIO_LoadPublicKey, EIO_PRI_DEFAULT, EIO_AfterLoadPublicKey, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingLoadPublicKey, AfterLoadPublicKey);
return scope.Close(Undefined());
}
-void pk::EIO_LoadPublicKey(eio_req *request) {
+void pk::DoingLoadPublicKey(uv_work_t *request) {
LoadPublicKeyBaton *baton = static_cast<LoadPublicKeyBaton *>(request->data);
try {
@@ -177,11 +178,9 @@ void pk::EIO_LoadPublicKey(eio_req *request) {
}
}
-int pk::EIO_AfterLoadPublicKey(eio_req *request) {
+void pk::AfterLoadPublicKey(uv_work_t *request) {
LoadPublicKeyBaton *baton = static_cast<LoadPublicKeyBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> publicKey = Null();
@@ -199,8 +198,7 @@ int pk::EIO_AfterLoadPublicKey(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> pk::LoadPrivateKey(const Arguments &args) {
@@ -216,13 +214,14 @@ Handle<Value> pk::LoadPrivateKey(const Arguments &args) {
baton->iv = toString(args[2]);
baton->passphrase = toString(args[3]);
- eio_custom(EIO_LoadPrivateKey, EIO_PRI_DEFAULT, EIO_AfterLoadPrivateKey, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingLoadPrivateKey, AfterLoadPrivateKey);
return scope.Close(Undefined());
}
-void pk::EIO_LoadPrivateKey(eio_req *request) {
+void pk::DoingLoadPrivateKey(uv_work_t *request) {
LoadPrivateKeyBaton *baton = static_cast<LoadPrivateKeyBaton *>(request->data);
try {
@@ -256,11 +255,9 @@ void pk::EIO_LoadPrivateKey(eio_req *request) {
}
}
-int pk::EIO_AfterLoadPrivateKey(eio_req *request) {
+void pk::AfterLoadPrivateKey(uv_work_t *request) {
LoadPrivateKeyBaton *baton = static_cast<LoadPrivateKeyBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> privateKey = Null();
@@ -278,8 +275,7 @@ int pk::EIO_AfterLoadPrivateKey(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> PublicKey::ToString(const Arguments &args) {
@@ -290,13 +286,15 @@ Handle<Value> PublicKey::ToString(const Arguments &args) {
PublicKeyToStringBaton *baton = new PublicKeyToStringBaton(args[0]);
baton->publicKey = (ObjectWrap::Unwrap<PublicKey>(args.This()))->publicKey;
- eio_custom(EIO_ToString, EIO_PRI_DEFAULT, EIO_AfterToString, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+
+ uv_queue_work(uv_default_loop(), request, DoingToString, AfterToString);
return scope.Close(Undefined());
}
-void PublicKey::EIO_ToString(eio_req *request) {
+void PublicKey::DoingToString(uv_work_t *request) {
PublicKeyToStringBaton *baton =
static_cast<PublicKeyToStringBaton *>(request->data);
@@ -308,12 +306,10 @@ void PublicKey::EIO_ToString(eio_req *request) {
}
}
-int PublicKey::EIO_AfterToString(eio_req *request) {
+void PublicKey::AfterToString(uv_work_t *request) {
PublicKeyToStringBaton *baton =
static_cast<PublicKeyToStringBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> publicKeyString = Null();
@@ -328,8 +324,7 @@ int PublicKey::EIO_AfterToString(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> PrivateKey::ToString(const Arguments &args) {
@@ -342,13 +337,14 @@ Handle<Value> PrivateKey::ToString(const Arguments &args) {
baton->privateKey = (ObjectWrap::Unwrap<PrivateKey>(args.This()))->privateKey;
baton->passphrase = toString(args[0]);
- eio_custom(EIO_ToString, EIO_PRI_DEFAULT, EIO_AfterToString, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingToString, AfterToString);
return scope.Close(Undefined());
}
-void PrivateKey::EIO_ToString(eio_req *request) {
+void PrivateKey::DoingToString(uv_work_t *request) {
PrivateKeyToStringBaton *baton =
static_cast<PrivateKeyToStringBaton *>(request->data);
@@ -372,12 +368,10 @@ void PrivateKey::EIO_ToString(eio_req *request) {
}
}
-int PrivateKey::EIO_AfterToString(eio_req *request) {
+void PrivateKey::AfterToString(uv_work_t *request) {
PrivateKeyToStringBaton *baton =
static_cast<PrivateKeyToStringBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> privateKeyString = Null();
Handle<Value> salt = Null();
@@ -397,8 +391,7 @@ int PrivateKey::EIO_AfterToString(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> PublicKey::Encrypt(const Arguments &args) {
@@ -411,13 +404,14 @@ Handle<Value> PublicKey::Encrypt(const Arguments &args) {
baton->in = toSecureVector(args[0]);
baton->publicKey = (ObjectWrap::Unwrap<PublicKey>(args.This()))->publicKey;
- eio_custom(EIO_Encrypt, EIO_PRI_DEFAULT, EIO_AfterEncrypt, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingEncrypt, AfterEncrypt);
return scope.Close(Undefined());
}
-void PublicKey::EIO_Encrypt(eio_req *request) {
+void PublicKey::DoingEncrypt(uv_work_t *request) {
PublicKeyEncryptBaton *baton =
static_cast<PublicKeyEncryptBaton *>(request->data);
@@ -432,12 +426,10 @@ void PublicKey::EIO_Encrypt(eio_req *request) {
}
}
-int PublicKey::EIO_AfterEncrypt(eio_req *request) {
+void PublicKey::AfterEncrypt(uv_work_t *request) {
PublicKeyEncryptBaton *baton =
static_cast<PublicKeyEncryptBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -452,8 +444,7 @@ int PublicKey::EIO_AfterEncrypt(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> PrivateKey::Decrypt(const Arguments &args) {
@@ -466,13 +457,14 @@ Handle<Value> PrivateKey::Decrypt(const Arguments &args) {
baton->in = toSecureVector(args[0]);
baton->privateKey = (ObjectWrap::Unwrap<PrivateKey>(args.This()))->privateKey;
- eio_custom(EIO_Decrypt, EIO_PRI_DEFAULT, EIO_AfterDecrypt, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingDecrypt, AfterDecrypt);
return scope.Close(Undefined());
}
-void PrivateKey::EIO_Decrypt(eio_req *request) {
+void PrivateKey::DoingDecrypt(uv_work_t *request) {
PrivateKeyDecryptBaton *baton =
static_cast<PrivateKeyDecryptBaton *>(request->data);
@@ -486,12 +478,10 @@ void PrivateKey::EIO_Decrypt(eio_req *request) {
}
}
-int PrivateKey::EIO_AfterDecrypt(eio_req *request) {
+void PrivateKey::AfterDecrypt(uv_work_t *request) {
PrivateKeyDecryptBaton *baton =
static_cast<PrivateKeyDecryptBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -506,8 +496,7 @@ int PrivateKey::EIO_AfterDecrypt(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
PublicKey::PublicKey(Handle<Object> target, RSA_PublicKey* publicKey) {
@@ -564,8 +553,9 @@ Handle<Value> cipher::Encrypt(const Arguments &args) {
memset(baton->mac, 0, baton->inLength * sizeof(std::string*));
}
- eio_custom(EIO_Encrypt, EIO_PRI_DEFAULT, EIO_AfterEncrypt, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingEncrypt, AfterEncrypt);
return scope.Close(Undefined());
}
@@ -597,7 +587,7 @@ std::string *encryptSecureVector(SecureVector<byte> *secureVector,
return encryptedSecureVector;
}
-void cipher::EIO_Encrypt(eio_req *request) {
+void cipher::DoingEncrypt(uv_work_t *request) {
EncryptBaton *baton = static_cast<EncryptBaton *>(request->data);
try {
@@ -605,10 +595,12 @@ void cipher::EIO_Encrypt(eio_req *request) {
baton->key = new OctetString(base64_decode(*baton->keyString));
size_t i = 0;
for (; i < baton->inLength; i++) {
- std::string *mac = NULL;
- baton->out[i] = encryptSecureVector(baton->in[i], baton->cipherType, baton->key,
- baton->macType, &mac);
- if (mac) baton->mac[i] = mac;
+ if (baton->in[i]) {
+ std::string *mac = NULL;
+ baton->out[i] = encryptSecureVector(baton->in[i], baton->cipherType,
+ baton->key, baton->macType, &mac);
+ if (mac) baton->mac[i] = mac;
+ }
}
}
catch (std::exception &e) {
@@ -616,9 +608,8 @@ void cipher::EIO_Encrypt(eio_req *request) {
}
}
-int cipher::EIO_AfterEncrypt(eio_req *request) {
+void cipher::AfterEncrypt(uv_work_t *request) {
EncryptBaton *baton = static_cast<EncryptBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -628,9 +619,12 @@ int cipher::EIO_AfterEncrypt(eio_req *request) {
error = TYPE_ERROR(baton->error->c_str());
else {
if (baton->inLength == 1) {
- out = String::New(baton->out[0]->c_str());
- if (baton->mac)
- mac = String::New(baton->mac[0]->c_str());
+ if (baton->out[0]) {
+ out = String::New(baton->out[0]->c_str());
+ if (baton->mac)
+ mac = String::New(baton->mac[0]->c_str());
+ }
+ else out = Null();
}
else {
Local<Array> outArray = Array::New(baton->inLength);
@@ -638,9 +632,12 @@ int cipher::EIO_AfterEncrypt(eio_req *request) {
if (baton->macType) macArray = Array::New(baton->inLength);
size_t i = 0;
for (; i < baton->inLength; i++) {
- outArray->Set(i, String::New(baton->out[i]->c_str()));
- if (baton->macType)
- macArray->Set(i, String::New(baton->mac[i]->c_str()));
+ if (baton->out[i]) {
+ outArray->Set(i, String::New(baton->out[i]->c_str()));
+ if (baton->macType)
+ macArray->Set(i, String::New(baton->mac[i]->c_str()));
+ }
+ else outArray->Set(i, Null());
}
out = outArray;
if (baton->macType) mac = macArray;
@@ -653,8 +650,7 @@ int cipher::EIO_AfterEncrypt(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> cipher::Decrypt(const Arguments &args) {
@@ -684,8 +680,9 @@ Handle<Value> cipher::Decrypt(const Arguments &args) {
memset(baton->mac, 0, baton->inLength * sizeof(std::string*));
}
- eio_custom(EIO_Decrypt, EIO_PRI_DEFAULT, EIO_AfterDecrypt, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingDecrypt, AfterDecrypt);
return scope.Close(Undefined());
}
@@ -712,7 +709,7 @@ SecureVector<byte> *decryptSecureVector(SecureVector<byte>& secureVector,
return decryptedSecureVector;
}
-void cipher::EIO_Decrypt(eio_req *request) {
+void cipher::DoingDecrypt(uv_work_t *request) {
DecryptBaton *baton = static_cast<DecryptBaton *>(request->data);
try {
@@ -720,16 +717,18 @@ void cipher::EIO_Decrypt(eio_req *request) {
baton->key = new OctetString(base64_decode(*baton->keyString));
size_t i = 0;
for (; i < baton->inLength; i++) {
- std::string *mac = NULL;
- SecureVector<byte> ivString = base64_decode((char *) baton->in[i]->begin(),
- IV_SIZE_BASE64);
- ivString.resize(ivString.size() - (IV_SIZE % 3));
- InitializationVector iv(ivString);
- SecureVector<byte> in(*baton->in[i] + IV_SIZE_BASE64, baton->in[i]->size()
- - IV_SIZE_BASE64);
- baton->out[i] = decryptSecureVector(in, baton->cipherType, baton->key, iv,
- baton->macType, &mac);
- if (mac) baton->mac[i] = mac;
+ if (baton->in[i]) {
+ std::string *mac = NULL;
+ SecureVector<byte> ivString = base64_decode((char *) baton->in[i]->begin(),
+ IV_SIZE_BASE64);
+ ivString.resize(ivString.size() - (IV_SIZE % 3));
+ InitializationVector iv(ivString);
+ SecureVector<byte> in(*baton->in[i] + IV_SIZE_BASE64, baton->in[i]->size()
+ - IV_SIZE_BASE64);
+ baton->out[i] = decryptSecureVector(in, baton->cipherType, baton->key, iv,
+ baton->macType, &mac);
+ if (mac) baton->mac[i] = mac;
+ }
}
}
catch (std::exception &e) {
@@ -737,9 +736,8 @@ void cipher::EIO_Decrypt(eio_req *request) {
}
}
-int cipher::EIO_AfterDecrypt(eio_req *request) {
+void cipher::AfterDecrypt(uv_work_t *request) {
DecryptBaton *baton = static_cast<DecryptBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -749,9 +747,12 @@ int cipher::EIO_AfterDecrypt(eio_req *request) {
error = TYPE_ERROR(baton->error->c_str());
else {
if (baton->inLength == 1) {
- out = Buffer::New((char *) baton->out[0]->begin(),
- baton->out[0]->size())->handle_;
- if (baton->mac) mac = String::New(baton->mac[0]->c_str());
+ if (baton->out[0]) {
+ out = Buffer::New((char *) baton->out[0]->begin(),
+ baton->out[0]->size())->handle_;
+ if (baton->mac) mac = String::New(baton->mac[0]->c_str());
+ }
+ else out = Null();
}
else {
Local<Array> outArray = Array::New(baton->inLength);
@@ -759,10 +760,13 @@ int cipher::EIO_AfterDecrypt(eio_req *request) {
if (baton->macType) macArray = Array::New(baton->inLength);
size_t i = 0;
for (; i < baton->inLength; i++) {
- outArray->Set(i, Buffer::New((char *) baton->out[i]->begin(),
- baton->out[i]->size())->handle_);
- if (baton->macType)
- macArray->Set(i, String::New(baton->mac[i]->c_str()));
+ if (baton->out[i]) {
+ outArray->Set(i, Buffer::New((char *) baton->out[i]->begin(),
+ baton->out[i]->size())->handle_);
+ if (baton->macType)
+ macArray->Set(i, String::New(baton->mac[i]->c_str()));
+ }
+ else outArray->Set(i, Null());
}
out = outArray;
if (baton->macType) mac = macArray;
@@ -775,8 +779,7 @@ int cipher::EIO_AfterDecrypt(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> cipher::InitialiseEncryptor(const Arguments &args) {
@@ -798,14 +801,15 @@ Handle<Value> cipher::InitialiseEncryptor(const Arguments &args) {
else
baton->key = toSecureVector(args[2]);
- eio_custom(EIO_InitialiseEncryptor, EIO_PRI_DEFAULT,
- EIO_AfterInitialiseEncryptor, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingInitialiseEncryptor,
+ AfterInitialiseEncryptor);
return scope.Close(Undefined());
}
-void cipher::EIO_InitialiseEncryptor(eio_req *request) {
+void cipher::DoingInitialiseEncryptor(uv_work_t *request) {
InitialiseEncryptorBaton *baton =
static_cast<InitialiseEncryptorBaton *>(request->data);
@@ -829,12 +833,10 @@ void cipher::EIO_InitialiseEncryptor(eio_req *request) {
}
}
-int cipher::EIO_AfterInitialiseEncryptor(eio_req *request) {
+void cipher::AfterInitialiseEncryptor(uv_work_t *request) {
InitialiseEncryptorBaton *baton =
static_cast<InitialiseEncryptorBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> encryptor = Null();
Handle<Value> iv = Null();
@@ -855,8 +857,7 @@ int cipher::EIO_AfterInitialiseEncryptor(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> Encryptor::Update(const Arguments &args) {
@@ -882,13 +883,14 @@ Handle<Value> Encryptor::Update(const Arguments &args) {
inLength);
baton->pipe = (ObjectWrap::Unwrap<Encryptor>(args.This()))->pipe;
- eio_custom(EIO_Update, EIO_PRI_DEFAULT, EIO_AfterUpdate, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingUpdate, AfterUpdate);
return scope.Close(Undefined());
}
-void Encryptor::EIO_Update(eio_req *request) {
+void Encryptor::DoingUpdate(uv_work_t *request) {
EncryptorUpdateBaton *baton = static_cast<EncryptorUpdateBaton *>(request->data);
try {
@@ -900,10 +902,9 @@ void Encryptor::EIO_Update(eio_req *request) {
}
}
-int Encryptor::EIO_AfterUpdate(eio_req *request) {
+void Encryptor::AfterUpdate(uv_work_t *request) {
EncryptorUpdateBaton *baton = static_cast<EncryptorUpdateBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -919,8 +920,7 @@ int Encryptor::EIO_AfterUpdate(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> Encryptor::Final(const Arguments &args) {
@@ -931,13 +931,14 @@ Handle<Value> Encryptor::Final(const Arguments &args) {
EncryptorFinalBaton *baton = new EncryptorFinalBaton(args[0]);
baton->pipe = (ObjectWrap::Unwrap<Encryptor>(args.This()))->pipe;
- eio_custom(EIO_Final, EIO_PRI_DEFAULT, EIO_AfterFinal, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingFinal, AfterFinal);
return scope.Close(Undefined());
}
-void Encryptor::EIO_Final(eio_req *request) {
+void Encryptor::DoingFinal(uv_work_t *request) {
EncryptorFinalBaton *baton = static_cast<EncryptorFinalBaton *>(request->data);
try {
@@ -951,9 +952,8 @@ void Encryptor::EIO_Final(eio_req *request) {
}
}
-int Encryptor::EIO_AfterFinal(eio_req *request) {
+void Encryptor::AfterFinal(uv_work_t *request) {
EncryptorFinalBaton *baton = static_cast<EncryptorFinalBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -976,8 +976,7 @@ int Encryptor::EIO_AfterFinal(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Encryptor::Encryptor(Handle<Object> target, Pipe* pipe) {
@@ -1014,14 +1013,15 @@ Handle<Value> cipher::InitialiseDecryptor(const Arguments &args) {
baton->key = toSecureVector(args[2]);
baton->iv = toSecureVector(args[3]);
- eio_custom(EIO_InitialiseDecryptor, EIO_PRI_DEFAULT,
- EIO_AfterInitialiseDecryptor, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingInitialiseDecryptor,
+ AfterInitialiseDecryptor);
return scope.Close(Undefined());
}
-void cipher::EIO_InitialiseDecryptor(eio_req *request) {
+void cipher::DoingInitialiseDecryptor(uv_work_t *request) {
InitialiseDecryptorBaton *baton =
static_cast<InitialiseDecryptorBaton *>(request->data);
@@ -1044,12 +1044,10 @@ void cipher::EIO_InitialiseDecryptor(eio_req *request) {
}
}
-int cipher::EIO_AfterInitialiseDecryptor(eio_req *request) {
+void cipher::AfterInitialiseDecryptor(uv_work_t *request) {
InitialiseDecryptorBaton *baton =
static_cast<InitialiseDecryptorBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> decryptor = Null();
@@ -1068,8 +1066,7 @@ int cipher::EIO_AfterInitialiseDecryptor(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> Decryptor::Update(const Arguments &args) {
@@ -1095,13 +1092,14 @@ Handle<Value> Decryptor::Update(const Arguments &args) {
inLength);
baton->pipe = (ObjectWrap::Unwrap<Decryptor>(args.This()))->pipe;
- eio_custom(EIO_Update, EIO_PRI_DEFAULT, EIO_AfterUpdate, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingUpdate, AfterUpdate);
return scope.Close(Undefined());
}
-void Decryptor::EIO_Update(eio_req *request) {
+void Decryptor::DoingUpdate(uv_work_t *request) {
DecryptorUpdateBaton *baton = static_cast<DecryptorUpdateBaton *>(request->data);
try {
@@ -1113,7 +1111,7 @@ void Decryptor::EIO_Update(eio_req *request) {
}
}
-int Decryptor::EIO_AfterUpdate(eio_req *request) {
+void Decryptor::AfterUpdate(uv_work_t *request) {
DecryptorUpdateBaton *baton = static_cast<DecryptorUpdateBaton *>(request->data);
Handle<Value> error = Null();
@@ -1130,8 +1128,7 @@ int Decryptor::EIO_AfterUpdate(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> Decryptor::Final(const Arguments &args) {
@@ -1142,13 +1139,14 @@ Handle<Value> Decryptor::Final(const Arguments &args) {
DecryptorFinalBaton *baton = new DecryptorFinalBaton(args[0]);
baton->pipe = (ObjectWrap::Unwrap<Decryptor>(args.This()))->pipe;
- eio_custom(EIO_Final, EIO_PRI_DEFAULT, EIO_AfterFinal, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingFinal, AfterFinal);
return scope.Close(Undefined());
}
-void Decryptor::EIO_Final(eio_req *request) {
+void Decryptor::DoingFinal(uv_work_t *request) {
DecryptorFinalBaton *baton = static_cast<DecryptorFinalBaton *>(request->data);
try {
@@ -1163,9 +1161,8 @@ void Decryptor::EIO_Final(eio_req *request) {
}
}
-int Decryptor::EIO_AfterFinal(eio_req *request) {
+void Decryptor::AfterFinal(uv_work_t *request) {
DecryptorFinalBaton *baton = static_cast<DecryptorFinalBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -1186,8 +1183,7 @@ int Decryptor::EIO_AfterFinal(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Decryptor::Decryptor(Handle<Object> target, Pipe* pipe) {
@@ -1256,13 +1252,14 @@ Handle<Value> codec::Encode(const Arguments &args) {
return THROW_BAD_ARGS;
baton->in = toSecureVector(args[1]);
- eio_custom(EIO_Encode, EIO_PRI_DEFAULT, EIO_AfterEncode, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingEncode, AfterEncode);
return scope.Close(Undefined());
}
-void codec::EIO_Encode(eio_req *request) {
+void codec::DoingEncode(uv_work_t *request) {
EncodeBaton *baton = static_cast<EncodeBaton *>(request->data);
try {
@@ -1276,9 +1273,8 @@ void codec::EIO_Encode(eio_req *request) {
}
}
-int codec::EIO_AfterEncode(eio_req *request) {
+void codec::AfterEncode(uv_work_t *request) {
EncodeBaton *baton = static_cast<EncodeBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -1294,8 +1290,7 @@ int codec::EIO_AfterEncode(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> codec::DecodeSync(const Arguments &args) {
@@ -1342,13 +1337,14 @@ Handle<Value> codec::Decode(const Arguments &args) {
return THROW_BAD_ARGS;
baton->in = toString(args[1]);
- eio_custom(EIO_Decode, EIO_PRI_DEFAULT, EIO_AfterDecode, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingDecode, AfterDecode);
return scope.Close(Undefined());
}
-void codec::EIO_Decode(eio_req *request) {
+void codec::DoingDecode(uv_work_t *request) {
DecodeBaton *baton = static_cast<DecodeBaton *>(request->data);
try {
@@ -1363,11 +1359,9 @@ void codec::EIO_Decode(eio_req *request) {
}
}
-int codec::EIO_AfterDecode(eio_req *request) {
+void codec::AfterDecode(uv_work_t *request) {
DecodeBaton *baton = static_cast<DecodeBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> out = Null();
@@ -1382,8 +1376,7 @@ int codec::EIO_AfterDecode(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> mac::Generate(const Arguments &args) {
@@ -1422,13 +1415,14 @@ Handle<Value> mac::Generate(const Arguments &args) {
}
baton->key = toOctetString(args[3]);
- eio_custom(EIO_Generate, EIO_PRI_DEFAULT, EIO_AfterGenerate, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingGenerate, AfterGenerate);
return scope.Close(Undefined());
}
-void mac::EIO_Generate(eio_req *request) {
+void mac::DoingGenerate(uv_work_t *request) {
GenerateBaton *baton = static_cast<GenerateBaton *>(request->data);
try {
@@ -1443,11 +1437,9 @@ void mac::EIO_Generate(eio_req *request) {
}
}
-int mac::EIO_AfterGenerate(eio_req *request) {
+void mac::AfterGenerate(uv_work_t *request) {
GenerateBaton *baton = static_cast<GenerateBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> mac = Null();
@@ -1462,8 +1454,7 @@ int mac::EIO_AfterGenerate(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> mac::Initialise(const Arguments &args) {
@@ -1476,13 +1467,14 @@ Handle<Value> mac::Initialise(const Arguments &args) {
baton->type = toString(args[0]);
baton->key = toOctetString(args[1]);
- eio_custom(EIO_Initialise, EIO_PRI_DEFAULT, EIO_AfterInitialise, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingInitialise, AfterInitialise);
return scope.Close(Undefined());
}
-void mac::EIO_Initialise(eio_req *request) {
+void mac::DoingInitialise(uv_work_t *request) {
InitialiseBaton *baton = static_cast<InitialiseBaton *>(request->data);
try {
@@ -1495,11 +1487,9 @@ void mac::EIO_Initialise(eio_req *request) {
}
}
-int mac::EIO_AfterInitialise(eio_req *request) {
+void mac::AfterInitialise(uv_work_t *request) {
InitialiseBaton *baton = static_cast<InitialiseBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> mac = Null();
@@ -1517,8 +1507,7 @@ int mac::EIO_AfterInitialise(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> Mac::Update(const Arguments &args) {
@@ -1555,13 +1544,14 @@ Handle<Value> Mac::Update(const Arguments &args) {
}
baton->pipe = (ObjectWrap::Unwrap<Mac>(args.This()))->pipe;
- eio_custom(EIO_Update, EIO_PRI_DEFAULT, EIO_AfterUpdate, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingUpdate, AfterUpdate);
return scope.Close(Undefined());
}
-void Mac::EIO_Update(eio_req *request) {
+void Mac::DoingUpdate(uv_work_t *request) {
MacUpdateBaton *baton = static_cast<MacUpdateBaton *>(request->data);
try {
@@ -1572,11 +1562,9 @@ void Mac::EIO_Update(eio_req *request) {
}
}
-int Mac::EIO_AfterUpdate(eio_req *request) {
+void Mac::AfterUpdate(uv_work_t *request) {
MacUpdateBaton *baton = static_cast<MacUpdateBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
if (baton->error)
error = TYPE_ERROR(baton->error->c_str());
@@ -1587,8 +1575,7 @@ int Mac::EIO_AfterUpdate(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> Mac::Final(const Arguments &args) {
@@ -1599,13 +1586,14 @@ Handle<Value> Mac::Final(const Arguments &args) {
MacFinalBaton *baton = new MacFinalBaton(args[0]);
baton->pipe = (ObjectWrap::Unwrap<Mac>(args.This()))->pipe;
- eio_custom(EIO_Final, EIO_PRI_DEFAULT, EIO_AfterFinal, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingFinal, AfterFinal);
return scope.Close(Undefined());
}
-void Mac::EIO_Final(eio_req *request) {
+void Mac::DoingFinal(uv_work_t *request) {
MacFinalBaton *baton = static_cast<MacFinalBaton *>(request->data);
try {
@@ -1617,11 +1605,9 @@ void Mac::EIO_Final(eio_req *request) {
}
}
-int Mac::EIO_AfterFinal(eio_req *request) {
+void Mac::AfterFinal(uv_work_t *request) {
MacFinalBaton *baton = static_cast<MacFinalBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> mac = Null();
@@ -1636,8 +1622,7 @@ int Mac::EIO_AfterFinal(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Mac::Mac(Local<Object> target, Pipe* pipe) {
@@ -1687,13 +1672,14 @@ Handle<Value> hash::Generate(const Arguments &args) {
baton->in = new SecureVector<byte>((byte *) Buffer::Data(in), inLength);
}
- eio_custom(EIO_Generate, EIO_PRI_DEFAULT, EIO_AfterGenerate, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingGenerate, AfterGenerate);
return scope.Close(Undefined());
}
-void hash::EIO_Generate(eio_req *request) {
+void hash::DoingGenerate(uv_work_t *request) {
GenerateBaton *baton = static_cast<GenerateBaton *>(request->data);
try {
@@ -1707,11 +1693,9 @@ void hash::EIO_Generate(eio_req *request) {
}
}
-int hash::EIO_AfterGenerate(eio_req *request) {
+void hash::AfterGenerate(uv_work_t *request) {
GenerateBaton *baton = static_cast<GenerateBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> hash = Null();
@@ -1726,8 +1710,7 @@ int hash::EIO_AfterGenerate(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> hash::Initialise(const Arguments &args) {
@@ -1739,13 +1722,14 @@ Handle<Value> hash::Initialise(const Arguments &args) {
InitialiseBaton *baton = new InitialiseBaton(args[1]);
baton->type = toString(args[0]);
- eio_custom(EIO_Initialise, EIO_PRI_DEFAULT, EIO_AfterInitialise, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingInitialise, AfterInitialise);
return scope.Close(Undefined());
}
-void hash::EIO_Initialise(eio_req *request) {
+void hash::DoingInitialise(uv_work_t *request) {
InitialiseBaton *baton = static_cast<InitialiseBaton *>(request->data);
try {
@@ -1757,11 +1741,9 @@ void hash::EIO_Initialise(eio_req *request) {
}
}
-int hash::EIO_AfterInitialise(eio_req *request) {
+void hash::AfterInitialise(uv_work_t *request) {
InitialiseBaton *baton = static_cast<InitialiseBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> hash = Null();
@@ -1779,8 +1761,7 @@ int hash::EIO_AfterInitialise(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> Hash::Update(const Arguments &args) {
@@ -1817,13 +1798,14 @@ Handle<Value> Hash::Update(const Arguments &args) {
}
baton->pipe = (ObjectWrap::Unwrap<Hash>(args.This()))->pipe;
- eio_custom(EIO_Update, EIO_PRI_DEFAULT, EIO_AfterUpdate, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingUpdate, AfterUpdate);
return scope.Close(Undefined());
}
-void Hash::EIO_Update(eio_req *request) {
+void Hash::DoingUpdate(uv_work_t *request) {
HashUpdateBaton *baton = static_cast<HashUpdateBaton *>(request->data);
try {
@@ -1834,11 +1816,9 @@ void Hash::EIO_Update(eio_req *request) {
}
}
-int Hash::EIO_AfterUpdate(eio_req *request) {
+void Hash::AfterUpdate(uv_work_t *request) {
HashUpdateBaton *baton = static_cast<HashUpdateBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
if (baton->error)
error = TYPE_ERROR(baton->error->c_str());
@@ -1849,8 +1829,7 @@ int Hash::EIO_AfterUpdate(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> Hash::Final(const Arguments &args) {
@@ -1861,13 +1840,14 @@ Handle<Value> Hash::Final(const Arguments &args) {
HashFinalBaton *baton = new HashFinalBaton(args[0]);
baton->pipe = (ObjectWrap::Unwrap<Hash>(args.This()))->pipe;
- eio_custom(EIO_Final, EIO_PRI_DEFAULT, EIO_AfterFinal, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingFinal, AfterFinal);
return scope.Close(Undefined());
}
-void Hash::EIO_Final(eio_req *request) {
+void Hash::DoingFinal(uv_work_t *request) {
HashFinalBaton *baton = static_cast<HashFinalBaton *>(request->data);
try {
@@ -1879,11 +1859,9 @@ void Hash::EIO_Final(eio_req *request) {
}
}
-int Hash::EIO_AfterFinal(eio_req *request) {
+void Hash::AfterFinal(uv_work_t *request) {
HashFinalBaton *baton = static_cast<HashFinalBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> hash = Null();
@@ -1898,8 +1876,7 @@ int Hash::EIO_AfterFinal(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Hash::Hash(Local<Object> target, Pipe* pipe) {
@@ -1932,13 +1909,14 @@ Handle<Value> pbkdf::Generate(const Arguments &args) {
else
baton->iterations = args[3]->NumberValue();
- eio_custom(EIO_Generate, EIO_PRI_DEFAULT, EIO_AfterGenerate, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingGenerate, AfterGenerate);
return scope.Close(Undefined());
}
-void pbkdf::EIO_Generate(eio_req *request) {
+void pbkdf::DoingGenerate(uv_work_t *request) {
GenerateBaton *baton = static_cast<GenerateBaton *>(request->data);
try {
@@ -1961,11 +1939,9 @@ void pbkdf::EIO_Generate(eio_req *request) {
}
}
-int pbkdf::EIO_AfterGenerate(eio_req *request) {
+void pbkdf::AfterGenerate(uv_work_t *request) {
GenerateBaton *baton = static_cast<GenerateBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> derivedKey = Null();
Handle<Value> salt = Null();
@@ -1983,8 +1959,7 @@ int pbkdf::EIO_AfterGenerate(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> rnd::GenerateDigits(const Arguments &args) {
@@ -1997,13 +1972,15 @@ Handle<Value> rnd::GenerateDigits(const Arguments &args) {
baton->digitsLength = args[0]->NumberValue();
if (baton->digitsLength <= 0) return THROW_BAD_ARGS;
- eio_custom(EIO_GenerateDigits, EIO_PRI_DEFAULT, EIO_AfterGenerateDigits, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingGenerateDigits,
+ AfterGenerateDigits);
return scope.Close(Undefined());
}
-void rnd::EIO_GenerateDigits(eio_req *request) {
+void rnd::DoingGenerateDigits(uv_work_t *request) {
GenerateDigitsBaton *baton = static_cast<GenerateDigitsBaton *>(request->data);
std::string digits;
@@ -2024,11 +2001,9 @@ void rnd::EIO_GenerateDigits(eio_req *request) {
}
}
-int rnd::EIO_AfterGenerateDigits(eio_req *request) {
+void rnd::AfterGenerateDigits(uv_work_t *request) {
GenerateDigitsBaton *baton = static_cast<GenerateDigitsBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> digits = Null();
@@ -2044,8 +2019,7 @@ int rnd::EIO_AfterGenerateDigits(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
Handle<Value> rnd::GenerateBytes(const Arguments &args) {
@@ -2067,13 +2041,14 @@ Handle<Value> rnd::GenerateBytes(const Arguments &args) {
baton->bytesLength = args[1]->NumberValue();
if (baton->bytesLength <= 0) return THROW_BAD_ARGS;
- eio_custom(EIO_GenerateBytes, EIO_PRI_DEFAULT, EIO_AfterGenerateBytes, baton);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *request = new uv_work_t;
+ request->data = baton;
+ uv_queue_work(uv_default_loop(), request, DoingGenerateBytes, AfterGenerateBytes);
return scope.Close(Undefined());
}
-void rnd::EIO_GenerateBytes(eio_req *request) {
+void rnd::DoingGenerateBytes(uv_work_t *request) {
GenerateBytesBaton *baton = static_cast<GenerateBytesBaton *>(request->data);
try {
@@ -2095,11 +2070,9 @@ void rnd::EIO_GenerateBytes(eio_req *request) {
}
}
-int rnd::EIO_AfterGenerateBytes(eio_req *request) {
+void rnd::AfterGenerateBytes(uv_work_t *request) {
GenerateBytesBaton *baton = static_cast<GenerateBytesBaton *>(request->data);
- ev_unref(EV_DEFAULT_UC);
-
Handle<Value> error = Null();
Handle<Value> bytes = Null();
@@ -2118,12 +2091,11 @@ int rnd::EIO_AfterGenerateBytes(eio_req *request) {
if (try_catch.HasCaught()) FatalException(try_catch);
delete baton;
-
- return 0;
+ delete request;
}
-extern "C" void init(Handle<Object> target) {
- LibraryInitializer init();
+void init(Handle<Object> target) {
+ Botan::LibraryInitializer init("thread_safe=true");
NODE_SET_METHOD(target, "generateKeys", pk::Generate);
NODE_SET_METHOD(target, "loadPublicKey", pk::LoadPublicKey);
@@ -2145,3 +2117,7 @@ extern "C" void init(Handle<Object> target) {
NODE_SET_METHOD(target, "generateRandomBytes", rnd::GenerateBytes);
}
+} // namespace node_botan
+
+NODE_MODULE(cr, node_botan::init);
+
View
123 node-botan.h → src/node-botan.h
@@ -9,13 +9,16 @@
#include <botan/rsa.h>
#include <botan/pubkey.h>
+namespace node_botan {
+
class Baton {
public:
v8::Persistent<v8::Function> callback;
std::string *error;
Baton(v8::Local<v8::Value> callback) {
- this->callback = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(callback));
+ this->callback =
+ v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(callback));
error = NULL;
}
@@ -30,8 +33,8 @@ namespace pk {
static const size_t DEFAULT_KEY_SIZE = 2048;
static v8::Handle<v8::Value> Generate(const v8::Arguments &args);
- static void EIO_Generate(eio_req *request);
- static int EIO_AfterGenerate(eio_req *request);
+ static void DoingGenerate(uv_work_t *request);
+ static void AfterGenerate(uv_work_t *request);
class GenerateBaton : public Baton {
public:
@@ -43,8 +46,8 @@ namespace pk {
};
static v8::Handle<v8::Value> LoadPublicKey(const v8::Arguments &args);
- static void EIO_LoadPublicKey(eio_req *request);
- static int EIO_AfterLoadPublicKey(eio_req *request);
+ static void DoingLoadPublicKey(uv_work_t *request);
+ static void AfterLoadPublicKey(uv_work_t *request);
class LoadPublicKeyBaton : public Baton {
public:
@@ -66,12 +69,12 @@ namespace pk {
protected:
static v8::Handle<v8::Value> Encrypt(const v8::Arguments &args);
- static void EIO_Encrypt(eio_req *request);
- static int EIO_AfterEncrypt(eio_req *request);
+ static void DoingEncrypt(uv_work_t *request);
+ static void AfterEncrypt(uv_work_t *request);
static v8::Handle<v8::Value> ToString(const v8::Arguments &args);
- static void EIO_ToString(eio_req *request);
- static int EIO_AfterToString(eio_req *request);
+ static void DoingToString(uv_work_t *request);
+ static void AfterToString(uv_work_t *request);
private:
~PublicKey();
@@ -112,12 +115,12 @@ namespace pk {
static const std::string PBKDF_TYPE = "PBKDF2(SHA-256)";
static const size_t IV_SIZE = 16;
static const size_t PBKDF_SIZE = 32;
- static const uint32_t PBKDF_ITERATIONS = 30000;
+ static const uint32_t PBKDF_ITERATIONS = 50000;
static const std::string CIPHER_TYPE = "AES-256/EAX";
static v8::Handle<v8::Value> LoadPrivateKey(const v8::Arguments &args);
- static void EIO_LoadPrivateKey(eio_req *request);
- static int EIO_AfterLoadPrivateKey(eio_req *request);
+ static void DoingLoadPrivateKey(uv_work_t *request);
+ static void AfterLoadPrivateKey(uv_work_t *request);
class LoadPrivateKeyBaton : public Baton {
public:
@@ -150,12 +153,12 @@ namespace pk {
protected:
static v8::Handle<v8::Value> Decrypt(const v8::Arguments &args);
- static void EIO_Decrypt(eio_req *request);
- static int EIO_AfterDecrypt(eio_req *request);
+ static void DoingDecrypt(uv_work_t *request);
+ static void AfterDecrypt(uv_work_t *request);
static v8::Handle<v8::Value> ToString(const v8::Arguments &args);
- static void EIO_ToString(eio_req *request);
- static int EIO_AfterToString(eio_req *request);
+ static void DoingToString(uv_work_t *request);
+ static void AfterToString(uv_work_t *request);
private:
~PrivateKey();
@@ -214,8 +217,8 @@ namespace cipher {
static const std::string IV_MAC_TYPE = "HMAC(SHA-256)";
static v8::Handle<v8::Value> Encrypt(const v8::Arguments &args);
- static void EIO_Encrypt(eio_req *request);
- static int EIO_AfterEncrypt(eio_req *request);
+ static void DoingEncrypt(uv_work_t *request);
+ static void AfterEncrypt(uv_work_t *request);
class EncryptBaton : public Baton {
public:
@@ -262,8 +265,8 @@ namespace cipher {
};
static v8::Handle<v8::Value> Decrypt(const v8::Arguments &args);
- static void EIO_Decrypt(eio_req *request);
- static int EIO_AfterDecrypt(eio_req *request);
+ static void DoingDecrypt(uv_work_t *request);
+ static void AfterDecrypt(uv_work_t *request);
class DecryptBaton : public Baton {
public:
@@ -310,8 +313,8 @@ namespace cipher {
};
static v8::Handle<v8::Value> InitialiseEncryptor(const v8::Arguments &args);
- static void EIO_InitialiseEncryptor(eio_req *request);
- static int EIO_AfterInitialiseEncryptor(eio_req *request);
+ static void DoingInitialiseEncryptor(uv_work_t *request);
+ static void AfterInitialiseEncryptor(uv_work_t *request);
static const std::string DEFAULT_CIPHER_TYPE = "AES-256/EAX";
@@ -347,12 +350,12 @@ namespace cipher {
protected:
static v8::Handle<v8::Value> Update(const v8::Arguments &args);
- static void EIO_Update(eio_req *request);
- static int EIO_AfterUpdate(eio_req *request);
+ static void DoingUpdate(uv_work_t *request);
+ static void AfterUpdate(uv_work_t *request);
static v8::Handle<v8::Value> Final(const v8::Arguments &args);
- static void EIO_Final(eio_req *request);
- static int EIO_AfterFinal(eio_req *request);
+ static void DoingFinal(uv_work_t *request);
+ static void AfterFinal(uv_work_t *request);
private:
~Encryptor();
@@ -394,8 +397,8 @@ namespace cipher {
};
static v8::Handle<v8::Value> InitialiseDecryptor(const v8::Arguments &args);
- static void EIO_InitialiseDecryptor(eio_req *request);
- static int EIO_AfterInitialiseDecryptor(eio_req *request);
+ static void DoingInitialiseDecryptor(uv_work_t *request);
+ static void AfterInitialiseDecryptor(uv_work_t *request);
class InitialiseDecryptorBaton : public Baton {
public:
@@ -429,12 +432,12 @@ namespace cipher {
protected:
static v8::Handle<v8::Value> Update(const v8::Arguments &args);
- static void EIO_Update(eio_req *request);
- static int EIO_AfterUpdate(eio_req *request);
+ static void DoingUpdate(uv_work_t *request);
+ static void AfterUpdate(uv_work_t *request);
static v8::Handle<v8::Value> Final(const v8::Arguments &args);
- static void EIO_Final(eio_req *request);
- static int EIO_AfterFinal(eio_req *request);
+ static void DoingFinal(uv_work_t *request);
+ static void AfterFinal(uv_work_t *request);
private:
~Decryptor();
@@ -484,8 +487,8 @@ namespace codec {
static v8::Handle<v8::Value> EncodeSync(const v8::Arguments &args);
static v8::Handle<v8::Value> Encode(const v8::Arguments &args);
- static void EIO_Encode(eio_req *request);
- static int EIO_AfterEncode(eio_req *request);
+ static void DoingEncode(uv_work_t *request);
+ static void AfterEncode(uv_work_t *request);
class EncodeBaton : public Baton {
public:
@@ -507,8 +510,8 @@ namespace codec {
static v8::Handle<v8::Value> DecodeSync(const v8::Arguments &args);
static v8::Handle<v8::Value> Decode(const v8::Arguments &args);
- static void EIO_Decode(eio_req *request);
- static int EIO_AfterDecode(eio_req *request);
+ static void DoingDecode(uv_work_t *request);
+ static void AfterDecode(uv_work_t *request);
class DecodeBaton : public Baton {
public:
@@ -532,8 +535,8 @@ namespace codec {
namespace mac {
static v8::Handle<v8::Value> Generate(const v8::Arguments &args);
- static void EIO_Generate(eio_req *request);
- static int EIO_AfterGenerate(eio_req *request);
+ static void DoingGenerate(uv_work_t *request);
+ static void AfterGenerate(uv_work_t *request);
class GenerateBaton : public Baton {
public:
@@ -558,8 +561,8 @@ namespace mac {
};
static v8::Handle<v8::Value> Initialise(const v8::Arguments &args);
- static void EIO_Initialise(eio_req *request);
- static int EIO_AfterInitialise(eio_req *request);
+ static void DoingInitialise(uv_work_t *request);
+ static void AfterInitialise(uv_work_t *request);
class InitialiseBaton : public Baton {
public:
@@ -584,12 +587,12 @@ namespace mac {
protected:
static v8::Handle<v8::Value> Update(const v8::Arguments &args);
- static void EIO_Update(eio_req *request);
- static int EIO_AfterUpdate(eio_req *request);
+ static void DoingUpdate(uv_work_t *request);
+ static void AfterUpdate(uv_work_t *request);
static v8::Handle<v8::Value> Final(const v8::Arguments &args);
- static void EIO_Final(eio_req *request);
- static int EIO_AfterFinal(eio_req *request);
+ static void DoingFinal(uv_work_t *request);
+ static void AfterFinal(uv_work_t *request);
private:
~Mac();
@@ -629,8 +632,8 @@ namespace mac {
namespace hash {
static v8::Handle<v8::Value> Generate(const v8::Arguments &args);
- static void EIO_Generate(eio_req *request);
- static int EIO_AfterGenerate(eio_req *request);
+ static void DoingGenerate(uv_work_t *request);
+ static void AfterGenerate(uv_work_t *request);
class GenerateBaton : public Baton {
public:
@@ -652,8 +655,8 @@ namespace hash {
};
static v8::Handle<v8::Value> Initialise(const v8::Arguments &args);
- static void EIO_Initialise(eio_req *request);
- static int EIO_AfterInitialise(eio_req *request);
+ static void DoingInitialise(uv_work_t *request);
+ static void AfterInitialise(uv_work_t *request);
class InitialiseBaton : public Baton {
public:
@@ -675,12 +678,12 @@ namespace hash {
protected:
static v8::Handle<v8::Value> Update(const v8::Arguments &args);
- static void EIO_Update(eio_req *request);
- static int EIO_AfterUpdate(eio_req *request);
+ static void DoingUpdate(uv_work_t *request);
+ static void AfterUpdate(uv_work_t *request);
static v8::Handle<v8::Value> Final(const v8::Arguments &args);
- static void EIO_Final(eio_req *request);
- static int EIO_AfterFinal(eio_req *request);
+ static void DoingFinal(uv_work_t *request);
+ static void AfterFinal(uv_work_t *request);
private:
~Hash();
@@ -724,8 +727,8 @@ namespace pbkdf {
static const uint32_t DEFAULT_ITERATIONS = 30000;
static v8::Handle<v8::Value> Generate(const v8::Arguments &args);
- static void EIO_Generate(eio_req *request);
- static int EIO_AfterGenerate(eio_req *request);
+ static void DoingGenerate(uv_work_t *request);
+ static void AfterGenerate(uv_work_t *request);
class GenerateBaton : public Baton {
public:
@@ -755,8 +758,8 @@ namespace pbkdf {
namespace rnd {
static v8::Handle<v8::Value> GenerateDigits(const v8::Arguments &args);
- static void EIO_GenerateDigits(eio_req *request);
- static int EIO_AfterGenerateDigits(eio_req *request);
+ static void DoingGenerateDigits(uv_work_t *request);
+ static void AfterGenerateDigits(uv_work_t *request);
class GenerateDigitsBaton : public Baton {
public:
@@ -773,8 +776,8 @@ namespace rnd {
};
static v8::Handle<v8::Value> GenerateBytes(const v8::Arguments &args);
- static void EIO_GenerateBytes(eio_req *request);
- static int EIO_AfterGenerateBytes(eio_req *request);
+ static void DoingGenerateBytes(uv_work_t *request);
+ static void AfterGenerateBytes(uv_work_t *request);
enum ByteType { binary, base64, hex };
@@ -798,4 +801,8 @@ namespace rnd {
}
+void init(v8::Handle<v8::Object> target);
+
+} // namespace node_botan
+
#endif
View
8 test/node-botan-test.js
@@ -206,7 +206,9 @@ describe('RSA key functions', function() {
should.not.exist(error);
should.not.exist(mac);
var decryptedBuffer = concatenate(decryptedData, finalDecryptedData);
- data.toString().should.equal(decryptedBuffer.toString());
+ var decryptedDataString = decryptedBuffer.toString();
+ console.log(decryptedDataString);
+ data.toString().should.equal(decryptedDataString);
done();
});
});
@@ -247,7 +249,7 @@ describe('RSA key functions', function() {
});
});
});
-
+/*
it('should fail to update encryptor with buffer that is too small', function(done) {
botan.initialiseEncryptor(null, null, cipherKey, function(error, encryptor, iv) {
should.not.exist(error);
@@ -833,5 +835,5 @@ describe('Random functions', function() {
(function() { botan.generateRandomBytes('myrhh', 20, function(error, bytes) {}); }).should.throw();
done();
});
-
+*/
});
View
40 wscript
@@ -1,40 +0,0 @@
-import Options
-
-import os
-import os.path as path
-
-srcdir = "."
-blddir = "build"
-VERSION = "0.0.1"
-
-def set_options(opt):
- opt.tool_options("compiler_cxx")
- opt.add_option('--debug', action='store', default=False, help='Enable debugging output')
-
-def configure(conf):
- conf.check_tool("compiler_cxx")
- conf.check_tool("node_addon")
- conf.check(lib='botan-1.10', uselib_store='LIBBOTAN-1.10')
-
-def build(bld):
- obj = bld.new_task_gen("cxx", "shlib", "node_addon")
- obj.cxxflags = ['-g',
- '-D_FILE_OFFSET_BITS=64',
- '-D_LARGEFILE_SOURCE',
- '-Wall']
- obj.target = "botan"
- obj.source = "node-botan.cpp"
- obj.uselib = ['LIBBOTAN-1.10']
- if (Options.options.debug != False) and (Options.options.debug == 'true'):
- obj.defines = "ENABLE_DEBUG=1"
-
-def shutdown():
- if Options.commands['clean']:
- if path.exists('node-botan.node'):
- os.unlink('node-botan.node')
- if path.exists('build/default/node-botan.node'):
- os.unlink('build/default/node-botan.node')
-
- if path.exists('build/default/node-botan.node') and not path.exists('node-botan.node'):
- os.symlink('build/default/node-botan.node', 'node-botan.node')
-
Please sign in to comment.
Something went wrong with that request. Please try again.