ruby-diceware 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby-dice/cli.rb +3 -1
- data/lib/ruby-dice/passphrase.rb +4 -0
- data/lib/ruby-dice/version.rb +1 -1
- data/spec/ruby-dice_spec.rb +8 -0
- metadata +3 -3
data/lib/ruby-dice/cli.rb
CHANGED
@@ -7,12 +7,14 @@ module RubyDice
|
|
7
7
|
option :length, type: :numeric, default: 5, aliases: :l, desc: 'Amount of words to use'
|
8
8
|
option :print, type: :boolean, default: false, aliases: :p, desc: 'Output passphrase to terminal'
|
9
9
|
option :wordlist, type: :string, default: nil, aliases: :w, desc: 'Use a custom wordlist file', banner: 'filename'
|
10
|
-
option :camelcase, type: :boolean, default: false, aliases: :c, desc: 'Generate a camelCase
|
10
|
+
option :camelcase, type: :boolean, default: false, aliases: :c, desc: 'Generate a camelCase passphrase with no spaces'
|
11
|
+
option :numbers, type: :boolean, default: false, aliases: :n, desc: 'Generate a passphrase with at least one number'
|
11
12
|
def throw
|
12
13
|
passphrase_options = {}.tap do |o|
|
13
14
|
o[:words] = options['length']
|
14
15
|
o[:wordlist] = options['wordlist']
|
15
16
|
o[:camelcase] = options['camelcase']
|
17
|
+
o[:numbers] = options['numbers']
|
16
18
|
end
|
17
19
|
|
18
20
|
passphrase = RubyDice::Passphrase.generate passphrase_options
|
data/lib/ruby-dice/passphrase.rb
CHANGED
@@ -10,6 +10,10 @@ module RubyDice
|
|
10
10
|
wordlist = Wordlist.new(wordlist_options)
|
11
11
|
words = wordlist.random(options[:words])
|
12
12
|
|
13
|
+
if !words.detect { |w| w.match(/\d/) } && options[:numbers]
|
14
|
+
words[-1] += SecureRandom.random_number(100).to_s
|
15
|
+
end
|
16
|
+
|
13
17
|
if options[:camelcase]
|
14
18
|
words.map!(&:capitalize)
|
15
19
|
words[0] = words[0].downcase
|
data/lib/ruby-dice/version.rb
CHANGED
data/spec/ruby-dice_spec.rb
CHANGED
@@ -19,6 +19,14 @@ describe RubyDice::Passphrase do
|
|
19
19
|
passphrase = RubyDice::Passphrase.generate(camelcase: true)
|
20
20
|
passphrase.should eql(camel)
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'returns a passphrase with a number' do
|
24
|
+
words = %w[mary had a little lamb]
|
25
|
+
with_number = /mary had a little lamb\d+/
|
26
|
+
RubyDice::Wordlist.any_instance.stub(:random).and_return(words)
|
27
|
+
passphrase = RubyDice::Passphrase.generate(numbers: true)
|
28
|
+
passphrase.should =~ with_number
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
describe RubyDice::Wordlist do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-diceware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
segments:
|
115
115
|
- 0
|
116
|
-
hash: -
|
116
|
+
hash: -3135137275591674634
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
segments:
|
124
124
|
- 0
|
125
|
-
hash: -
|
125
|
+
hash: -3135137275591674634
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
128
|
rubygems_version: 1.8.23
|