Browse files

handle -1 response

  • Loading branch information...
1 parent 5c9a1a2 commit ada643be71ed28b2591db77c02f5d65cb814f1da akdubya committed Dec 12, 2010
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/binding.cc
View
14 src/binding.cc
@@ -32,11 +32,17 @@ Handle<Value> RandBytes(const Arguments &args) {
Local<Object> buf = args[0]->ToObject();
char *data = Buffer::Data(buf);
size_t length = Buffer::Length(buf);
- if (!RAND_bytes((unsigned char*)data, length)) {
- unsigned long code = ERR_get_error();
- return ThrowException(Exception::Error(String::New(
- ERR_error_string(code, NULL))));
+
+ switch (RAND_bytes((unsigned char*) data, length)) {
+ case -1:
+ return ThrowException(Exception::Error(String::New(
+ "Current RAND method does not support this operation")));
+ case 0:
+ unsigned long code = ERR_get_error();
+ return ThrowException(Exception::Error(String::New(
+ ERR_error_string(code, NULL))));
}
+
return scope.Close(Integer::NewFromUnsigned(length));
}

0 comments on commit ada643b

Please sign in to comment.