summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/ossl_rand.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c
index daf866d772d..7a01278ac88 100644
--- a/ext/openssl/ossl_rand.c
+++ b/ext/openssl/ossl_rand.c
@@ -114,10 +114,8 @@ ossl_rand_bytes(VALUE self, VALUE len)
str = rb_str_new(0, n);
ret = RAND_bytes((unsigned char *)RSTRING_PTR(str), n);
- if (ret == 0){
- char buf[256];
- ERR_error_string_n(ERR_get_error(), buf, 256);
- ossl_raise(eRandomError, "RAND_bytes error: %s", buf);
+ if (ret == 0) {
+ ossl_raise(eRandomError, "RAND_bytes");
} else if (ret == -1) {
ossl_raise(eRandomError, "RAND_bytes is not supported");
}
@@ -146,7 +144,7 @@ ossl_rand_pseudo_bytes(VALUE self, VALUE len)
int n = NUM2INT(len);
str = rb_str_new(0, n);
- if (!RAND_pseudo_bytes((unsigned char *)RSTRING_PTR(str), n)) {
+ if (RAND_pseudo_bytes((unsigned char *)RSTRING_PTR(str), n) < 1) {
ossl_raise(eRandomError, NULL);
}
@@ -165,7 +163,7 @@ ossl_rand_egd(VALUE self, VALUE filename)
{
SafeStringValue(filename);
- if(!RAND_egd(RSTRING_PTR(filename))) {
+ if (RAND_egd(RSTRING_PTR(filename)) == -1) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@@ -187,7 +185,7 @@ ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
SafeStringValue(filename);
- if (!RAND_egd_bytes(RSTRING_PTR(filename), n)) {
+ if (RAND_egd_bytes(RSTRING_PTR(filename), n) == -1) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;