Sha256: cf98217c786b2497b3b660a16bf3ed1e4473b050fb682b1c99ae49ee7e820d0c
Contents?: true
Size: 1.05 KB
Versions: 36
Compression:
Stored size: 1.05 KB
Contents
module KineticSdk module Utils # The Random module provides methods to generate random secrets of varying # complexity. module Random # Symbols that are allowed by default DEFAULT_SYMBOLS = %w( ! @ % * ( ) { } [ ] ) # Symbols that are represented as 7-bit ASCII SEVEN_BIT_ASCII_SYMBOLS = %w(! " # $ % & ' ( ) * + - . / : ; < = > ? @ [ \ ] & _ ` { | } ~) # Alpha-numeric characters that are respresented as 7-bit ASCII SEVEN_BIT_ASCII_ALPHANUM = ('A'..'Z').to_a.concat( ('a'..'z').to_a).concat( ('0'..'9').to_a) # Generates a simple secret based on ASCII alpha-numeric characters, # and a few standard symbol characters. # # @param size [Fixnum] The length of the generated secret # @param allowed_symbols [Array] symbols to allow def self.simple(size = 20, allowed_symbols = DEFAULT_SYMBOLS) chars = (allowed_symbols || Array.new).concat(SEVEN_BIT_ASCII_ALPHANUM) (0...size).map { chars[rand(chars.size)] }.join end end end end
Version data entries
36 entries across 36 versions & 1 rubygems