Class: LeapCli::Util::Secret

Inherits:
Object
  • Object
show all
Defined in:
lib/leap_cli/util/secret.rb

Constant Summary collapse

CHARS =
(('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a) - "i1loO06G".split(//u)
HEX =
(0..9).to_a + ('a'..'f').to_a

Class Method Summary collapse

Class Method Details

.generate(length = 16) ⇒ Object

generate a secret with with no ambiguous characters.

length is in chars

Only alphanumerics are allowed, in order to make these passwords work for REST url calls and to allow you to easily copy and paste them.



22
23
24
25
26
27
# File 'lib/leap_cli/util/secret.rb', line 22

def self.generate(length = 16)
  seed
  OpenSSL::Random.random_bytes(length).bytes.to_a.collect { |byte|
    CHARS[ byte % CHARS.length ]
  }.join
end

.generate_hex(length = 128) ⇒ Object

generates a hex secret, instead of an alphanumeric on.

length is in bits



34
35
36
37
38
39
# File 'lib/leap_cli/util/secret.rb', line 34

def self.generate_hex(length = 128)
  seed
  OpenSSL::Random.random_bytes(length/4).bytes.to_a.collect { |byte|
    HEX[ byte % HEX.length ]
  }.join
end