summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-07 11:25:45 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-07 11:25:45 +0000
commit2099780eb653e46bd46d68939e04c7a2ebe2f13a (patch)
tree88f29f302b8c1fa1f5ce8eb8f4187eea29578f25 /lib
parentf4be1257a4706bcb3e595a65bc898239c2b547a8 (diff)
merge revision(s) 35545,35564,35565:
* lib/securerandom.rb: show actual read length in an error message. * lib/securerandom.rb (random_bytes): call to_int method for the argument at first. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/securerandom.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index 04e8bc205e..d4ab947f54 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -54,7 +54,7 @@ module SecureRandom
# If secure random number generator is not available,
# NotImplementedError is raised.
def self.random_bytes(n=nil)
- n ||= 16
+ n = n ? n.to_int : 16
if defined? OpenSSL::Random
@pid = 0 if !defined?(@pid)
@@ -80,7 +80,7 @@ module SecureRandom
@has_urandom = true
ret = f.readpartial(n)
if ret.length != n
- raise NotImplementedError, "Unexpected partial read from random device"
+ raise NotImplementedError, "Unexpected partial read from random device: only #{ret.length} for #{n} bytes"
end
return ret
}