diff options
author | elijah <elijah@riseup.net> | 2016-07-01 14:49:27 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2016-07-01 14:49:27 -0700 |
commit | 174dbf380fe1b0962a9e173caa6dd0a0f76a14e1 (patch) | |
tree | d2f1414652d2c0fbd1003347c2abf2be1ffff473 /lib/leap_cli/util/secret.rb | |
parent | 2d277c7d2aa3ddfbe3c2c65f68d7290930934b70 (diff) | |
parent | f9284ff22da6eec685782dbc9aa4a4ded0efec29 (diff) |
Merge branch 'feature/newcli' into develop
Diffstat (limited to 'lib/leap_cli/util/secret.rb')
-rw-r--r-- | lib/leap_cli/util/secret.rb | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/lib/leap_cli/util/secret.rb b/lib/leap_cli/util/secret.rb deleted file mode 100644 index 749b959..0000000 --- a/lib/leap_cli/util/secret.rb +++ /dev/null @@ -1,55 +0,0 @@ -# encoding: utf-8 -# -# A simple secret generator -# -# Uses OpenSSL random number generator instead of Ruby's rand function -# -autoload :OpenSSL, 'openssl' - -module LeapCli; module Util - class Secret - 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 - - # - # 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. - # - def self.generate(length = 16) - seed - OpenSSL::Random.random_bytes(length).bytes.to_a.collect { |byte| - CHARS[ byte % CHARS.length ] - }.join - end - - # - # generates a hex secret, instead of an alphanumeric on. - # - # length is in bits - # - def self.generate_hex(length = 128) - seed - OpenSSL::Random.random_bytes(length/4).bytes.to_a.collect { |byte| - HEX[ byte % HEX.length ] - }.join - end - - private - - def self.seed - @pid ||= 0 - pid = $$ - if @pid != pid - now = Time.now - ary = [now.to_i, now.nsec, @pid, pid] - OpenSSL::Random.seed(ary.to_s) - @pid = pid - end - end - - end -end; end |