Skip to content

Commit

Permalink
crypto: use domains for any callback-taking method
Browse files Browse the repository at this point in the history
This adds domains coverage for pdbkdf2, pseudoRandomBytes, and randomBytes.
All others should be covered by event emitters.

Fixes nodejs#5801.
  • Loading branch information
chrisdickinson committed Sep 16, 2014
1 parent 0664ddc commit 1e2a687
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL

namespace node {

// defined in node.cc
extern v8::Persistent<v8::String> process_symbol;
extern v8::Persistent<v8::String> domain_symbol;

const char* root_certs[] = {
#include "node_root_certs.h" // NOLINT(build/include_order)
NULL
Expand Down Expand Up @@ -3982,8 +3986,19 @@ Handle<Value> PBKDF2(const Arguments& args) {
req->keylen = keylen;

if (args[4]->IsFunction()) {
Local<Value> domain = Context::GetCurrent()
->Global()
->Get(process_symbol)
->ToObject()
->Get(domain_symbol);

req->obj = Persistent<Object>::New(Object::New());
req->obj->Set(String::New("ondone"), args[4]);

if (!domain->IsUndefined()) {
req->obj->Set(domain_symbol, domain);
}

uv_queue_work(uv_default_loop(),
&req->work_req,
EIO_PBKDF2,
Expand Down Expand Up @@ -4111,6 +4126,16 @@ Handle<Value> RandomBytes(const Arguments& args) {
if (args[1]->IsFunction()) {
req->obj_ = Persistent<Object>::New(Object::New());
req->obj_->Set(String::New("ondone"), args[1]);
Local<Value> domain = Context::GetCurrent()
->Global()
->Get(process_symbol)
->ToObject()
->Get(domain_symbol);


if (!domain->IsUndefined()) {
req->obj_->Set(domain_symbol, domain);
}

uv_queue_work(uv_default_loop(),
&req->work_req_,
Expand Down

0 comments on commit 1e2a687

Please sign in to comment.