Bug #6799 » secure_random.patch
lib/securerandom.rb | ||
---|---|---|
# If secure random number generator is not available,
|
||
# NotImplementedError is raised.
|
||
def self.hex(n=nil)
|
||
random_bytes(n).unpack("H*")[0]
|
||
random_bytes(n).unpack("H*")[0].force_encoding(Encoding::US_ASCII)
|
||
end
|
||
# SecureRandom.base64 generates a random base64 string.
|
test/test_securerandom.rb | ||
---|---|---|
end
|
||
end
|
||
def test_hex_encoding
|
||
assert_equal(Encoding::US_ASCII, @it.hex.encoding)
|
||
end
|
||
def test_s_base64
|
||
assert_equal(16, @it.base64.unpack('m*')[0].size)
|
||
17.times do |idx|
|