Module: Oplop
- Defined in:
- lib/oplop.rb,
lib/oplop/cli.rb,
lib/oplop/version.rb
Defined Under Namespace
Modules: Cli
Constant Summary collapse
- LENGTH =
8
- VERSION =
"0.0.8"
Class Method Summary collapse
-
.password(args = {}) ⇒ Object
Oplop.password(:master => ‘p@ssw0rd’, :label => ‘github’).
-
.urlsafe_b64encode(string) ⇒ Object
See www.ietf.org/rfc/rfc4648.txt Ruby 1.8.x does not have this as part of the Base64 lib.
Class Method Details
.password(args = {}) ⇒ Object
Oplop.password(:master => ‘p@ssw0rd’, :label => ‘github’)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/oplop.rb', line 11 def self.password(args={}) unless (args.keys.include?(:master) && args.keys.include?(:label)) raise ArgumentError.new 'Master and label are required arguments.' end master_label = '%s%s' % [ args.delete(:master), args.delete(:label) ] raise ArgumentError.new "Unknown keys #{args.keys.join(',')}." if args.keys.any? password = urlsafe_b64encode(Digest::MD5.digest(master_label)) if password.respond_to?(:encode) password = password.encode('UTF-8') end if m = password.match(/\d+/) password = '%s%s' % [ m[0], password ] if (m.begin(0) >= LENGTH) else password = '1%s' % password end password[0,LENGTH] end |
.urlsafe_b64encode(string) ⇒ Object
See www.ietf.org/rfc/rfc4648.txt Ruby 1.8.x does not have this as part of the Base64 lib
38 39 40 |
# File 'lib/oplop.rb', line 38 def self.urlsafe_b64encode(string) Base64.encode64(string).tr('+/', '-_') end |