mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
[ruby/securerandom] [DOC] Add documents of methods and constants
https://github.com/ruby/securerandom/commit/9a99978135
This commit is contained in:
parent
cb93d10ae5
commit
dbd704ae6f
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user