Browse Source

Update verushash.cc

master
hellcatz 5 years ago
committed by GitHub
parent
commit
60a1e36a74
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 163
      verushash.cc

163
verushash.cc

@ -11,6 +11,8 @@ using namespace v8;
CVerusHash* vh;
CVerusHashV2* vh2;
CVerusHashV2* vh2b1;
bool initialized = false;
void initialize()
@ -20,8 +22,11 @@ void initialize()
CVerusHash::init();
CVerusHashV2::init();
}
vh = new CVerusHash();
vh2 = new CVerusHashV2();
vh2 = new CVerusHashV2(SOLUTION_VERUSHHASH_V2);
vh2b1 = new CVerusHashV2(SOLUTION_VERUSHHASH_V2_1);
initialized = true;
}
@ -30,69 +35,23 @@ void verusInit(const v8::FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(args.This());
}
void verusUpdate(const v8::FunctionCallbackInfo<Value>& args) {
void verusHash(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (initialized == false){
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "call init() first!"))
);
}
if (args.Length() < 1) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))
);
return;
}
Local<Object> buffer = args[0]->ToObject();
if(!node::Buffer::HasInstance(buffer)) {
MaybeLocal<Object> maybeBuffer = Nan::To<v8::Object>(args[0]);
Local<Object> buffer;
if (maybeBuffer.ToLocal(&buffer) != true) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Invalid buffer objects."))
);
return;
}
const char *buff = node::Buffer::Data(buffer);
vh->Write((const unsigned char *)buff, node::Buffer::Length(buffer));
args.GetReturnValue().Set(args.This());
}
void verusDigest(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (initialized == false){
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "call init() first!"))
);
}
char *result = new char[32];
vh->Finalize((unsigned char *)result);
args.GetReturnValue().Set(Nan::NewBuffer(result, 32).ToLocalChecked());
}
void verusReset(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (initialized == false){
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "call init() first!"))
);
}
vh->Reset();
args.GetReturnValue().Set(args.This());
}
void verusHash(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.Length() < 1) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))
);
return;
}
Local<Object> buffer = args[0]->ToObject();
if(!node::Buffer::HasInstance(buffer)) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Invalid buffer objects."))
@ -108,25 +67,26 @@ void verusHash(const v8::FunctionCallbackInfo<Value>& args) {
initialize();
}
verus_hash(result, buff, node::Buffer::Length(buffer));
args.GetReturnValue().Set(Nan::NewBuffer(result, 32).ToLocalChecked());
}
void verusUpdateV2(const v8::FunctionCallbackInfo<Value>& args) {
void verusHashV2(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (initialized == false){
if (args.Length() < 1) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "call init() first!"))
Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))
);
return;
}
if (args.Length() < 1) {
MaybeLocal<Object> maybeBuffer = Nan::To<v8::Object>(args[0]);
Local<Object> buffer;
if (maybeBuffer.ToLocal(&buffer) != true) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))
Exception::TypeError(String::NewFromUtf8(isolate, "Invalid buffer objects."))
);
return;
}
Local<Object> buffer = args[0]->ToObject();
if(!node::Buffer::HasInstance(buffer)) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Invalid buffer objects."))
@ -135,50 +95,20 @@ void verusUpdateV2(const v8::FunctionCallbackInfo<Value>& args) {
}
const char *buff = node::Buffer::Data(buffer);
vh2->Write((const unsigned char *)buff, node::Buffer::Length(buffer));
args.GetReturnValue().Set(args.This());
}
void verusDigestV2(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (initialized == false){
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "call init() first!"))
);
}
char *result = new char[32];
vh2->Finalize((unsigned char *)result);
args.GetReturnValue().Set(Nan::NewBuffer(result, 32).ToLocalChecked());
}
void verusDigestV2b(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (initialized == false){
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "call init() first!"))
);
if (initialized == false) {
initialize();
}
char *result = new char[32];
vh2->Finalize2b((unsigned char *)result);
args.GetReturnValue().Set(Nan::NewBuffer(result, 32).ToLocalChecked());
}
void verusResetV2(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (initialized == false){
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "call init() first!"))
);
}
vh2->Reset();
args.GetReturnValue().Set(args.This());
vh2->Write((const unsigned char *)buff, node::Buffer::Length(buffer));
vh2->Finalize((unsigned char *)result);
args.GetReturnValue().Set(Nan::NewBuffer(result, 32).ToLocalChecked());
}
void verusHashV2(const v8::FunctionCallbackInfo<Value>& args) {
void verusHashV2b(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.Length() < 1) {
@ -187,7 +117,14 @@ void verusHashV2(const v8::FunctionCallbackInfo<Value>& args) {
);
return;
}
Local<Object> buffer = args[0]->ToObject();
MaybeLocal<Object> maybeBuffer = Nan::To<v8::Object>(args[0]);
Local<Object> buffer;
if (maybeBuffer.ToLocal(&buffer) != true) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Invalid buffer objects."))
);
return;
}
if(!node::Buffer::HasInstance(buffer)) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Invalid buffer objects."))
@ -205,11 +142,11 @@ void verusHashV2(const v8::FunctionCallbackInfo<Value>& args) {
vh2->Reset();
vh2->Write((const unsigned char *)buff, node::Buffer::Length(buffer));
vh2->Finalize((unsigned char *)result);
vh2->Finalize2b((unsigned char *)result);
args.GetReturnValue().Set(Nan::NewBuffer(result, 32).ToLocalChecked());
}
void verusHashV2b(const v8::FunctionCallbackInfo<Value>& args) {
void verusHashV2b1(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.Length() < 1) {
@ -218,7 +155,14 @@ void verusHashV2b(const v8::FunctionCallbackInfo<Value>& args) {
);
return;
}
Local<Object> buffer = args[0]->ToObject();
MaybeLocal<Object> maybeBuffer = Nan::To<v8::Object>(args[0]);
Local<Object> buffer;
if (maybeBuffer.ToLocal(&buffer) != true) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Invalid buffer objects."))
);
return;
}
if(!node::Buffer::HasInstance(buffer)) {
isolate->ThrowException(
Exception::TypeError(String::NewFromUtf8(isolate, "Invalid buffer objects."))
@ -234,24 +178,19 @@ void verusHashV2b(const v8::FunctionCallbackInfo<Value>& args) {
initialize();
}
vh2->Reset();
vh2->Write((const unsigned char *)buff, node::Buffer::Length(buffer));
vh2->Finalize2b((unsigned char *)result);
vh2b1->Reset();
vh2b1->Write((const unsigned char *)buff, node::Buffer::Length(buffer));
vh2b1->Finalize2b((unsigned char *)result);
args.GetReturnValue().Set(Nan::NewBuffer(result, 32).ToLocalChecked());
}
void Init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "init", verusInit);
NODE_SET_METHOD(exports, "update", verusUpdate);
NODE_SET_METHOD(exports, "digest", verusDigest);
NODE_SET_METHOD(exports, "reset", verusReset);
NODE_SET_METHOD(exports, "hash", verusHash);
NODE_SET_METHOD(exports, "update2", verusUpdateV2);
NODE_SET_METHOD(exports, "digest2", verusDigestV2);
NODE_SET_METHOD(exports, "digest2b", verusDigestV2b);
NODE_SET_METHOD(exports, "reset2", verusResetV2);
NODE_SET_METHOD(exports, "hash2", verusHashV2);
NODE_SET_METHOD(exports, "hash2b", verusHashV2b);
NODE_SET_METHOD(exports, "hash", verusHash); //VerusHash V1
NODE_SET_METHOD(exports, "hash2", verusHashV2); //VerusHash V2
NODE_SET_METHOD(exports, "hash2b", verusHashV2b); //VerusHash V2B
NODE_SET_METHOD(exports, "hash2b1", verusHashV2b1); //VerusHash V2B1
}
NODE_MODULE(verushash, Init)

Loading…
Cancel
Save