Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to gyp, add tests and more methods #5

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add onetimeauth
warner committed Dec 13, 2012
commit 3188d91306eebcc6feb65d0aca8fc9e5a0ab9dc8
32 changes: 32 additions & 0 deletions node_nacl.cc
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#include <crypto_box.h>
#include <crypto_sign.h>
#include <crypto_secretbox.h>
#include <crypto_onetimeauth.h>

using namespace std;
using namespace node;
@@ -23,6 +24,9 @@ static Handle<Value> node_crypto_sign_keypair (const Arguments&);
static Handle<Value> node_crypto_secretbox (const Arguments&);
static Handle<Value> node_crypto_secretbox_open (const Arguments&);

static Handle<Value> node_crypto_onetimeauth (const Arguments&);
static Handle<Value> node_crypto_onetimeauth_verify (const Arguments&);


static string buf_to_str (Handle<Object> b) {
return string(Buffer::Data(b), Buffer::Length(b));
@@ -138,6 +142,31 @@ static Handle<Value> node_crypto_secretbox_open (const Arguments& args) {
}
}

static Handle<Value> node_crypto_onetimeauth (const Arguments& args) {
HandleScope scope;
string m = buf_to_str(args[0]->ToObject());
string k = buf_to_str(args[1]->ToObject());
try {
string c = crypto_onetimeauth(m,k);
return scope.Close(str_to_buf(c)->handle_);
} catch(...) {
return THROW_ERROR("onetimeauth error");
}
}

static Handle<Value> node_crypto_onetimeauth_verify (const Arguments& args) {
HandleScope scope;
string a = buf_to_str(args[0]->ToObject());
string m = buf_to_str(args[1]->ToObject());
string k = buf_to_str(args[2]->ToObject());
try {
crypto_onetimeauth_verify(a,m,k);
return scope.Close(Null());
} catch(...) {
return THROW_ERROR("onetimeauth_verify error");
}
}


extern "C" {
void init (Handle<Object> target) {
@@ -153,6 +182,9 @@ extern "C" {

NODE_SET_METHOD(target, "secretbox", node_crypto_secretbox);
NODE_SET_METHOD(target, "secretbox_open", node_crypto_secretbox_open);

NODE_SET_METHOD(target, "onetimeauth", node_crypto_onetimeauth);
NODE_SET_METHOD(target, "onetimeauth_verify", node_crypto_onetimeauth_verify);

target->Set(String::NewSymbol("box_NONCEBYTES"), Integer::New(crypto_box_NONCEBYTES));
target->Set(String::NewSymbol("box_PUBLICKEYBYTES"), Integer::New(crypto_box_PUBLICKEYBYTES));
22 changes: 22 additions & 0 deletions test/onetimeauth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

var test = require("tap").test;

var n = require("../index").nacl;

var rs = Buffer("eea6a7251c1e72916d11c2cb214d3c25"+
"2539121d8e234e652d651fa4c8cff880", "hex");
var c = Buffer("8e993b9f48681273c29650ba32fc76ce"+
"48332ea7164d96a4476fb8c531a1186a"+
"c0dfc17c98dce87b4da7f011ec48c972"+
"71d2c20f9b928fe2270d6fb863d51738"+
"b48eeee314a7cc8ab932164548e526ae"+
"90224368517acfeabd6bb3732bc0e9da"+
"99832b61ca01b6de56244a9e88d5f9b3"+
"7973f622a43d14a6599b1f654cb45a74"+
"e355a5", "hex"); // 131 bytes long

test("onetimeauth", function(t) {
t.equivalent(n.onetimeauth(c, rs),
Buffer("f3ffc7703f9400e52a7dfb4b3d3305d9", "hex"));
t.end();
});