forked from underdarkskies/node-x16r
-
Notifications
You must be signed in to change notification settings - Fork 3
/
multihashing.cc
43 lines (28 loc) · 1.04 KB
/
multihashing.cc
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
#include <node.h>
#include <node_buffer.h>
#include <v8.h>
#include <stdint.h>
#include "nan.h"
extern "C" {
#include "x21s.h"
}
#define THROW_ERROR_EXCEPTION(x) Nan::ThrowError(x)
#define THROW_ERROR_EXCEPTION_WITH_STATUS_CODE(x, y) NanThrowError(x, y)
using namespace node;
using namespace v8;
NAN_METHOD(x21s) {
if (info.Length() < 1)
return THROW_ERROR_EXCEPTION("You must provide one argument.");
Local<Object> target = Nan::To<Object>(info[0]).ToLocalChecked();
if(!Buffer::HasInstance(target))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
char * input = Buffer::Data(target);
char *output = (char*) malloc(sizeof(char) * 32);
uint32_t input_len = Buffer::Length(target);
x21s_hash(input, output, input_len);
info.GetReturnValue().Set(Nan::NewBuffer(output, 32).ToLocalChecked());
}
NAN_MODULE_INIT(init) {
Nan::Set(target, Nan::New("x21s").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(x21s)).ToLocalChecked());
}
NODE_MODULE(nodex21s, init)