Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dan Bornstein
committed
Feb 8, 2012
1 parent
4a7c92d
commit 473f4a5
Showing
3 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,72 @@ | ||
// FIXME | ||
// This placeholder is just the "Hello" example from the Node docs. | ||
// Copyright 2012 The Obvious Corporation. | ||
|
||
#include <node.h> | ||
#include <v8.h> | ||
#include "rsabNative.h" | ||
|
||
#include <openssl/ssl.h> | ||
#include <openssl/err.h> | ||
#include <openssl/evp.h> | ||
#include <openssl/pem.h> | ||
#include <openssl/x509.h> | ||
#include <openssl/hmac.h> | ||
#include <openssl/engine.h> | ||
#include <openssl/rand.h> | ||
|
||
using namespace v8; | ||
|
||
Handle<Value> Method(const Arguments& args) { | ||
HandleScope scope; | ||
return scope.Close(String::New("world")); | ||
} | ||
|
||
/** | ||
* Top-level initialization function. | ||
*/ | ||
void init(Handle<Object> target) { | ||
target->Set(String::NewSymbol("hello"), | ||
FunctionTemplate::New(Method)->GetFunction()); | ||
RsaWrap::InitClass(target); | ||
} | ||
|
||
NODE_MODULE(rsabNative, init) | ||
|
||
/** | ||
* Initialize the bindings for this class. | ||
*/ | ||
void RsaWrap::InitClass(Handle<Object> target) { | ||
Local<String> className = String::NewSymbol("RsaWrap"); | ||
|
||
// Basic instance setup | ||
Local<FunctionTemplate> tpl = FunctionTemplate::New(New); | ||
tpl->SetClassName(className); | ||
tpl->InstanceTemplate()->SetInternalFieldCount(1); // required by ObjectWrap | ||
|
||
// Prototype method bindings | ||
Local<ObjectTemplate> proto = tpl->PrototypeTemplate(); | ||
proto->Set(String::NewSymbol("hello"), | ||
FunctionTemplate::New(Hello)->GetFunction()); | ||
|
||
// Store the constructor in the target bindings. | ||
target->Set(className, Persistent<Function>::New(tpl->GetFunction())); | ||
} | ||
|
||
RsaWrap::RsaWrap() { | ||
rsa = NULL; | ||
} | ||
|
||
RsaWrap::~RsaWrap() { | ||
if (rsa != NULL) { | ||
RSA_free(rsa); | ||
} | ||
printf("~~~ DESTRUCTOR CALLED\n"); | ||
} | ||
|
||
Handle<Value> RsaWrap::New(const Arguments& args) { | ||
HandleScope scope; | ||
|
||
printf("~~~ ALLOC\n"); | ||
|
||
RsaWrap *obj = new RsaWrap(); | ||
obj->Wrap(args.This()); | ||
|
||
return args.This(); | ||
} | ||
|
||
// FIXME: Temporary! | ||
Handle<Value> RsaWrap::Hello(const Arguments& args) { | ||
HandleScope scope; | ||
return scope.Close(String::New("world")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2012 The Obvious Corporation. | ||
|
||
#ifndef RSAB_NATIVE_H | ||
#define RSAB_NATIVE_H | ||
|
||
#define BUILDING_NODE_EXTENSION | ||
#include <node.h> | ||
#include <node_object_wrap.h> | ||
#include <v8.h> | ||
|
||
#include <openssl/rsa.h> | ||
|
||
class RsaWrap : node::ObjectWrap { | ||
public: | ||
static void InitClass(v8::Handle<v8::Object> target); | ||
|
||
protected: | ||
RsaWrap(); | ||
~RsaWrap(); | ||
|
||
static v8::Handle<v8::Value> New(const v8::Arguments& args); | ||
static v8::Handle<v8::Value> Hello(const v8::Arguments& args); | ||
|
||
private: | ||
RSA *rsa; | ||
}; | ||
|
||
#endif // def RSAB_NATIV_H |