[ruby/securerandom] [DOC] Add documents of methods and constants

https://github.com/ruby/securerandom/commit/9a99978135
This commit is contained in:
Nobuyoshi Nakada 2023-12-12 14:11:51 +09:00 коммит произвёл git
Родитель cb93d10ae5
Коммит dbd704ae6f
2 изменённых файлов: 10 добавлений и 0 удалений

Просмотреть файл

@ -292,6 +292,7 @@ module Random::Formatter
end
end
# Internal interface to Random; Generate random data _n_ bytes.
private def gen_random(n)
self.bytes(n)
end
@ -339,7 +340,9 @@ module Random::Formatter
result
end
# The default character list for #alphanumeric.
ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9']
# Generate a random alphanumeric string.
#
# The argument _n_ specifies the length, in characters, of the alphanumeric

Просмотреть файл

@ -40,19 +40,25 @@ require 'random/formatter'
module SecureRandom
# The version
VERSION = "0.3.0"
class << self
# Returns a random binary string containing +size+ bytes.
#
# See Random.bytes
def bytes(n)
return gen_random(n)
end
private
# Implementation using OpenSSL
def gen_random_openssl(n)
return OpenSSL::Random.random_bytes(n)
end
# Implementation using system random device
def gen_random_urandom(n)
ret = Random.urandom(n)
unless ret
@ -78,6 +84,7 @@ module SecureRandom
end
end
# Generate random data bytes for Random::Formatter
public :gen_random
end
end