Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
crypto: fix -Wtautological-compare warning
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Oct 7, 2012
1 parent 8c5f269 commit 08af1c6
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/node_crypto.cc
Expand Up @@ -4370,26 +4370,26 @@ void RandomBytesFree(char* data, void* hint) {
}


template <RandomBytesGenerator generator>
template <bool pseudoRandom>
void RandomBytesWork(uv_work_t* work_req) {
RandomBytesRequest* req =
container_of(work_req, RandomBytesRequest, work_req_);

int r = generator(reinterpret_cast<unsigned char*>(req->data_), req->size_);

switch (r) {
case 0:
// RAND_bytes() returns 0 on error, RAND_pseudo_bytes() returns 0
// when the result is not cryptographically strong - the latter
// sucks but is not an error
if (generator == RAND_bytes)
req->error_ = ERR_get_error();
break;
RandomBytesRequest* req = container_of(work_req,
RandomBytesRequest,
work_req_);
int r;

if (pseudoRandom == true) {
r = RAND_pseudo_bytes(reinterpret_cast<unsigned char*>(req->data_),
req->size_);
} else {
r = RAND_bytes(reinterpret_cast<unsigned char*>(req->data_), req->size_);
}

case -1:
// not supported - can this actually happen?
req->error_ = (unsigned long) -1;
break;
// RAND_bytes() returns 0 on error. RAND_pseudo_bytes() returns 0 when the
// result is not cryptographically strong - but that's not an error.
if (r == 0 && pseudoRandom == false) {
req->error_ = ERR_get_error();
} else if (r == -1) {
req->error_ = static_cast<unsigned long>(-1);
}
}

Expand All @@ -4414,10 +4414,10 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) {
}


template <RandomBytesGenerator generator>
void RandomBytesAfter(uv_work_t* work_req) {
RandomBytesRequest* req =
container_of(work_req, RandomBytesRequest, work_req_);
RandomBytesRequest* req = container_of(work_req,
RandomBytesRequest,
work_req_);

HandleScope scope;
Local<Value> argv[2];
Expand All @@ -4428,7 +4428,7 @@ void RandomBytesAfter(uv_work_t* work_req) {
}


template <RandomBytesGenerator generator>
template <bool pseudoRandom>
Handle<Value> RandomBytes(const Arguments& args) {
HandleScope scope;

Expand All @@ -4452,14 +4452,14 @@ Handle<Value> RandomBytes(const Arguments& args) {

uv_queue_work(uv_default_loop(),
&req->work_req_,
RandomBytesWork<generator>,
RandomBytesAfter<generator>);
RandomBytesWork<pseudoRandom>,
RandomBytesAfter);

return req->obj_;
}
else {
Local<Value> argv[2];
RandomBytesWork<generator>(&req->work_req_);
RandomBytesWork<pseudoRandom>(&req->work_req_);
RandomBytesCheck(req, argv);
delete req;

Expand Down Expand Up @@ -4508,8 +4508,8 @@ void InitCrypto(Handle<Object> target) {
Verify::Initialize(target);

NODE_SET_METHOD(target, "PBKDF2", PBKDF2);
NODE_SET_METHOD(target, "randomBytes", RandomBytes<RAND_bytes>);
NODE_SET_METHOD(target, "pseudoRandomBytes", RandomBytes<RAND_pseudo_bytes>);
NODE_SET_METHOD(target, "randomBytes", RandomBytes<false>);
NODE_SET_METHOD(target, "pseudoRandomBytes", RandomBytes<true>);

subject_symbol = NODE_PSYMBOL("subject");
issuer_symbol = NODE_PSYMBOL("issuer");
Expand Down

0 comments on commit 08af1c6

Please sign in to comment.