Method: Ppp::Generator#initialize

Defined in:
lib/ppp/generator.rb

#initialize(sha256_key, opts = {}) ⇒ Generator

Returns a new instance of Generator.

Parameters:

  • sha256_key (String)

    a 64 hex-digit string representation of a SHA-256 hash. This hash will seed all the generated passcodes.

  • opts (Hash) (defaults to: {})

    the options to create the generator with.

Options Hash (opts):

  • :length (Fixnum) — default: 4

    the number of characters in each generated passcode

  • :alphabet (String) — default: :conservative

    a string containing the characters passcodes will be comprised of. Cannot contain null characters and duplicate characters will be removed.

Raises:



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ppp/generator.rb', line 15

def initialize sha256_key, opts={}
  raise NotHexKey.new( sha256_key ) if @@HEX_PATTERN.match( sha256_key ).nil?

  @seed     = sha256_key

  options   = { :length => 4, :alphabet => :conservative }.merge opts
  @length   = options[ :length ]
  @alphabet = process_alphabet( options[ :alphabet ] ).split( '' ).uniq.join

  raise ArgumentError.new( "alphabet cannot contain null character" ) if alphabet.include? ?\0
end