Module: SecureRandom

Defined in:
lib/active_storage/patches/secure_random.rb

Constant Summary collapse

BASE58_ALPHABET =
("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a - ["0", "O", "I", "l"]
BASE36_ALPHABET =
("0".."9").to_a + ("a".."z").to_a

Class Method Summary collapse

Class Method Details

.base36(n = 16) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/active_storage/patches/secure_random.rb', line 18

def self.base36(n = 16)
  SecureRandom.random_bytes(n).unpack("C*").map do |byte|
    idx = byte % 64
    idx = SecureRandom.random_number(36) if idx >= 36
    BASE36_ALPHABET[idx]
  end.join
end

.base58(n = 16) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/active_storage/patches/secure_random.rb', line 8

def self.base58(n = 16)
  SecureRandom.random_bytes(n).unpack("C*").map do |byte|
    idx = byte % 64
    idx = SecureRandom.random_number(58) if idx >= 58
    BASE58_ALPHABET[idx]
  end.join
end