-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhashing.cpp
51 lines (36 loc) · 1.26 KB
/
hashing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <node.h>
#include <node_buffer.h>
#include <v8.h>
#include <stdint.h>
extern "C" {
#include "x16r.h"
}
using namespace node;
using namespace v8;
// NODE_MAJOR_VERSION >=13
void x16r(const FunctionCallbackInfo<Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
if (args.Length() < 1) {
do {
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "You must provide one argument.").ToLocalChecked()));
return;
} while (0);
}
Local<Context> context = isolate->GetCurrentContext();
Local<Object> target = args[0]->ToObject(context).ToLocalChecked();
if(!Buffer::HasInstance(target)) {
do {
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Argument should be a buffer object.").ToLocalChecked()));
return;
} while (0);
}
char * input = Buffer::Data(target);
char output[32];
uint32_t input_len = Buffer::Length(target);
x16r_hash(input, output, input_len);
args.GetReturnValue().Set(Buffer::Copy(isolate, output, 32).ToLocalChecked());
}
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hash", x16r);
}
NODE_MODULE(hashing, init)