dash 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
1
  *.gem
2
- .bundle
3
- Gemfile.lock
4
2
  pkg/*
3
+ .bundle
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dash (0.3.1)
5
+ clamp
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ clamp (0.2.2)
11
+ diff-lcs (1.1.2)
12
+ rspec (2.6.0)
13
+ rspec-core (~> 2.6.0)
14
+ rspec-expectations (~> 2.6.0)
15
+ rspec-mocks (~> 2.6.0)
16
+ rspec-core (2.6.4)
17
+ rspec-expectations (2.6.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.6.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ dash!
26
+ rspec (~> 2.6)
data/bin/dash CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  begin
4
- require 'dash'
4
+ require 'dash/cli'
5
5
  rescue LoadError
6
6
  require 'rubygems'
7
- require 'dash'
7
+ require 'dash/cli'
8
8
  end
9
9
 
10
- Dash.hash(ARGV)
10
+ Dash::CLI.run
@@ -19,5 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency('slop', '= 2.0.0')
22
+ s.add_dependency('clamp')
23
+ s.add_development_dependency "rspec", "~> 2.6"
23
24
  end
@@ -0,0 +1,21 @@
1
+ require 'clamp'
2
+ require 'dash/password'
3
+
4
+ module Dash
5
+ class CLI < Clamp::Command
6
+ option ["-l", "--length"], "N", "make a password of N length", :default => 12 do |s|
7
+ Integer(s)
8
+ end
9
+ option ["-w", "--weak"], :flag, "generate a weak password"
10
+ parameter "DOMAIN", "the domain that needs a password", :attribute_name => :domain
11
+ parameter "[PASSWORD]", "your master password", :attribute_name => :password
12
+
13
+ def execute
14
+ puts Dash::Password.generate(domain, password, weak?, length)
15
+ end
16
+
17
+ def default_password
18
+ ENV['DASH_PASSWORD'] || ''
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'digest/sha2'
2
+
3
+ module Dash
4
+ class Password
5
+ STRONG = 'ABCDEFGHJKLMNPQRSTUVWabcdefghijkmnopqrstuvw0123456789+/-_*()[]{}'
6
+ WEAK = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
7
+ LENGTH = 12
8
+
9
+ def self.generate(domain, password, weak = false, length = LENGTH)
10
+ key = encrypt password
11
+ hash = encrypt "#{key}#{domain}"
12
+ charset = (weak == true) ? WEAK : STRONG
13
+
14
+ return encode(hash, charset)[0,length]
15
+ end
16
+
17
+ def self.encode(s,c)
18
+ (t=s.unpack('C*').inject([0,'',0]){|a,v|a[0]==0?[2,a[1]+c[v>>2,1],v*16&48]:a[0]==2?[4,a[1]+c[v>>4|a[2],1],v*4&60]:[0,a[1]+c[v>>6|a[2],1]+c[v&63,1],0]})[1]+(t[0]==0?'':t[0]==2?c[t[2],1]+'==':c[t[2],1]+'=')
19
+ end
20
+
21
+ def self.encrypt(key)
22
+ Digest::SHA2.new(256).hexdigest(key || '')
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Dash
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -0,0 +1,7 @@
1
+ require 'dash/password'
2
+
3
+ describe Dash::Password do
4
+ it "generates consistent password" do
5
+ Dash::Password.generate('twitter.com','password').should eql("NpPrP8E5QGJ5")
6
+ end
7
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dash
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael McClenaghan
@@ -10,20 +10,31 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-18 00:00:00 -06:00
13
+ date: 2011-07-21 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: slop
17
+ name: clamp
18
18
  prerelease: false
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - "="
22
+ - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.0.0
24
+ version: "0"
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "2.6"
36
+ type: :development
37
+ version_requirements: *id002
27
38
  description: Generates a strong password that is simple to recreate so there is no need to ever store your passwords.
28
39
  email:
29
40
  - mike@shift81.com
@@ -36,11 +47,14 @@ extra_rdoc_files: []
36
47
  files:
37
48
  - .gitignore
38
49
  - Gemfile
50
+ - Gemfile.lock
39
51
  - Rakefile
40
52
  - bin/dash
41
53
  - dash.gemspec
42
- - lib/dash.rb
54
+ - lib/dash/cli.rb
55
+ - lib/dash/password.rb
43
56
  - lib/dash/version.rb
57
+ - spec/dash_spec.rb
44
58
  has_rdoc: true
45
59
  homepage: https://github.com/shift81/dash
46
60
  licenses: []
@@ -69,5 +83,5 @@ rubygems_version: 1.5.0
69
83
  signing_key:
70
84
  specification_version: 3
71
85
  summary: Strong password generator
72
- test_files: []
73
-
86
+ test_files:
87
+ - spec/dash_spec.rb
@@ -1,52 +0,0 @@
1
- require 'digest/sha2'
2
- require 'slop'
3
-
4
- module Dash
5
- extend self
6
- STRONG = 'ABCDEFGHJKLMNPQRSTUVWabcdefghijkmnopqrstuvw0123456789+/-_*()[]{}'
7
- WEAK = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
8
- LENGTH = 12
9
-
10
- def hash(args)
11
- return unless parse_args(args)
12
-
13
- @key = encrypt @password
14
- @hash = encrypt "#{@key}#{@domain}"
15
-
16
- puts encode(@hash, @charset)[0,@length]
17
- end
18
-
19
- def parse_args(args)
20
- opts = Slop.parse!(args) do
21
- banner "Usage: dash <domain> [options]"
22
- on :p, :password, 'Your master password', :argument => true
23
- on :w, :weak, 'Generate weak password with alphanumeric character set'
24
- on :l, :length, 'Length of generated password', :argument => true
25
- end
26
-
27
- @charset = opts.weak? ? WEAK : STRONG
28
- @length = opts.length? ? opts[:length].to_i : LENGTH
29
-
30
- unless password = opts[:password] || ENV['DASH_PASSWORD']
31
- puts opts.help
32
- return
33
- end
34
-
35
- unless domain = args.shift
36
- puts opts.help
37
- return
38
- end
39
-
40
- @password = password.strip
41
- @domain = domain.strip
42
- true
43
- end
44
-
45
- def encode(s,c)
46
- (t=s.unpack('C*').inject([0,'',0]){|a,v|a[0]==0?[2,a[1]+c[v>>2,1],v*16&48]:a[0]==2?[4,a[1]+c[v>>4|a[2],1],v*4&60]:[0,a[1]+c[v>>6|a[2],1]+c[v&63,1],0]})[1]+(t[0]==0?'':t[0]==2?c[t[2],1]+'==':c[t[2],1]+'=')
47
- end
48
-
49
- def encrypt(key)
50
- Digest::SHA2.new(256).hexdigest key
51
- end
52
- end