Module: KineticSdk::Utils::Random

Defined in:
lib/kinetic_sdk/utils/random.rb

Overview

The Random module provides methods to generate random secrets of varying complexity.

Constant Summary collapse

DEFAULT_SYMBOLS =

Symbols that are allowed by default

%w( ! @ % * ( ) { } [ ] )
SEVEN_BIT_ASCII_SYMBOLS =

Symbols that are represented as 7-bit ASCII

%w(! " # $ % & ' ( ) * + - . / : ; < = > ? @ [ \ ] & _ ` { | } ~)
SEVEN_BIT_ASCII_ALPHANUM =

Alpha-numeric characters that are respresented as 7-bit ASCII

('A'..'Z').to_a.concat(
          ('a'..'z').to_a).concat(
('0'..'9').to_a)

Class Method Summary collapse

Class Method Details

.simple(size = 20, allowed_symbols = DEFAULT_SYMBOLS) ⇒ Object

Generates a simple secret based on ASCII alpha-numeric characters, and a few standard symbol characters.

Parameters:

  • size (Fixnum) (defaults to: 20)

    The length of the generated secret

  • allowed_symbols (Array) (defaults to: DEFAULT_SYMBOLS)

    symbols to allow



23
24
25
26
# File 'lib/kinetic_sdk/utils/random.rb', line 23

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