-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathx11hash.cc
More file actions
36 lines (26 loc) · 799 Bytes
/
x11hash.cc
File metadata and controls
36 lines (26 loc) · 799 Bytes
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
#include <nan.h>
extern "C" {
#include "x11.h"
}
NAN_METHOD(digest) {
if (info.Length() != 1){
Nan::ThrowError("You must provide exactly one argument.");
return;
}
v8::Local<v8::Object> target = info[0]->ToObject();
if(!node::Buffer::HasInstance(target)) {
Nan::ThrowError("Argument should be a buffer object.");
return;
}
char * input = node::Buffer::Data(target);
uint32_t input_len = node::Buffer::Length(target);
char * output = new char[32];
x11_hash(input, output, input_len);
Nan::MaybeLocal<v8::Object> buffer = Nan::CopyBuffer(output, 32);
delete []output;
info.GetReturnValue().Set(buffer.ToLocalChecked());
}
NAN_MODULE_INIT(init) {
NAN_EXPORT(target, digest);
}
NODE_MODULE(x11hash, init)