Skip to content

Commit

Permalink
[ruby/securerandom] [DOC] Add documents of methods and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Dec 12, 2023
1 parent cb93d10 commit dbd704a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/random/formatter.rb
Expand Up @@ -292,6 +292,7 @@ def uuid_v7(extra_timestamp_bits: 0)
end
end

# Internal interface to Random; Generate random data _n_ bytes.
private def gen_random(n)
self.bytes(n)
end
Expand Down Expand Up @@ -339,7 +340,9 @@ def uuid_v7(extra_timestamp_bits: 0)
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
Expand Down
7 changes: 7 additions & 0 deletions lib/securerandom.rb
Expand Up @@ -40,19 +40,25 @@

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
Expand All @@ -78,6 +84,7 @@ def gen_random_urandom(n)
end
end

# Generate random data bytes for Random::Formatter
public :gen_random
end
end
Expand Down

0 comments on commit dbd704a

Please sign in to comment.