Sha256: 6b94759114cd9d7ceccce079b010498fdc18c5df421f3e8bd6afd07024783975

Contents?: true

Size: 821 Bytes

Versions: 7

Compression:

Stored size: 821 Bytes

Contents

require "securerandom"

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

  unless SecureRandom.methods.include?(:base58)
    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
  end

  unless SecureRandom.methods.include?(:base36)
    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
activestorage_legacy-0.2.1 lib/active_storage/patches/secure_random.rb
activestorage_legacy-0.2.0 lib/active_storage/patches/secure_random.rb
activestorage_legacy-0.1.3 lib/active_storage/patches/secure_random.rb
activestorage_legacy-0.1.2 lib/active_storage/patches/secure_random.rb
activestorage_legacy-0.1.1 lib/active_storage/patches/secure_random.rb
activestorage_legacy-0.1.1.alpha lib/active_storage/patches/secure_random.rb
activestorage_legacy-0.1 lib/active_storage/patches/secure_random.rb