funny_yubikey_generator 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ce4a0835f9bf5d97819283adf58333005e5ef819fa25aeab2c361435906c7f4
4
- data.tar.gz: a92c688a139531971bebcc3862e2b12d471deffd7f9d9a42619b9b9947d93596
3
+ metadata.gz: aa628988e7878d56e67bdb26d912dc7d21f419f9f0e75fb6ccc845a8937c1a56
4
+ data.tar.gz: 7dbeea9dc0759e3f894fa2893530cf79a041dbc29de99087b9ccbd7ddceb27bc
5
5
  SHA512:
6
- metadata.gz: 8ba31a110fd97278d7ba0e6bf53f69ce30ec883e879db9ba991f085cdb0ece991fa1196731b4eccdb7abffb762e7f7575405a4db2b3ba3a8ccef4cd3427c69f3
7
- data.tar.gz: c9ae9bdd76e6af8979c466d98c43f3d9b60de330793241a517c309ee28e4500ac5ebbfa9f42f32680077249d6f39d8a500e80ba517677522d29ab39dd922583e
6
+ metadata.gz: f91e58a6fc9d03de37625515a93918f33e7e3fc41334f4e1dd0ac982ae2a740cbcd67bff7cb2e422fd4eb21c29c9c3217e5af19084967abda92775f6d12a040e
7
+ data.tar.gz: 1d225d62b4b474bbdaad7edff6ee078194b7ea6a72146f9bc07844666048336c0d0eef4a9d07b9ead94799da7f822babd13ce44a2cd7ab274bd8d57a4f0a7a21
data/Gemfile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in yubikey_generator.gemspec
5
+ # Specify your gem's dependencies in funny_yubikey_generator.gemspec
6
6
  gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funny_yubikey_generator (0.2.0)
4
+ funny_yubikey_generator (0.4.0)
5
5
  colorize (~> 0.8.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # FunnyYubikeyGenerator
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/funny_yubikey_generator.svg)](https://badge.fury.io/rb/funny_yubikey_generator)
4
+
3
5
  Generate funny looking [yubikey OTP](https://developers.yubico.com/OTP/OTPs_Explained.html) containing words based on a dictionary.
4
6
 
5
7
  ## Installation
@@ -16,33 +18,37 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
18
 
17
19
  As CLI:
18
20
  ```bash
19
- gem install funny_yubikey_generator
20
- generate_funny_yubikey -c
21
+ gem install funny_yubikey_generator
22
+ generate_funny_yubikey -c
21
23
  ```
22
24
 
25
+ ![preview.png](preview.png)
26
+
23
27
  In Ruby:
24
28
  ```ruby
25
- require "funny_yubikey_generator"
26
- puts FunnyYubikeyGenerator.generate(colorize: true)
27
-
28
- dictionary = <<~DICO
29
- crude
30
- blubber
31
- futile
32
- lutrin
33
- interbelligerent
34
- reinterference
35
- DICO
36
- generator = FunnyYubikeyGenerator.new(dictionary: dictionary.split("\n"))
37
- puts generator.generate(colorize: true)
38
-
29
+ require "funny_yubikey_generator"
30
+ puts FunnyYubikeyGenerator.generate(colorize: true)
31
+
32
+ dictionary = <<~DICO
33
+ crude
34
+ blubber
35
+ futile
36
+ lutrin
37
+ interbelligerent
38
+ reinterference
39
+ DICO
40
+ generator = FunnyYubikeyGenerator.from_dictionary(dictionary)
41
+ puts generator.generate(colorize: true)
42
+
43
+ generator = FunnyYubikeyGenerator.from_dictionary(File.open("/usr/share/dict/words"))
44
+ puts generator.generate(colorize: false)
39
45
  ```
40
46
 
41
47
  ## Development
42
48
 
43
49
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
50
 
45
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the `spec.version` in [funny_yubikey_generator.gemspec](funny_yubikey_generator.gemspec), and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
52
 
47
53
  ## Contributing
48
54
 
@@ -54,4 +60,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
54
60
 
55
61
  ## Code of Conduct
56
62
 
57
- Everyone interacting in the YubikeyGenerator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/x4d3/funny_yubikey_generator/blob/master/CODE_OF_CONDUCT.md).
63
+ Everyone interacting in the FunnyYubikeyGenerator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/x4d3/funny_yubikey_generator/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rake/testtask"
5
+ require "yaml"
5
6
 
6
7
  Rake::TestTask.new(:test) do |t|
7
8
  t.libs << "test"
@@ -9,6 +10,10 @@ Rake::TestTask.new(:test) do |t|
9
10
  t.test_files = FileList["test/**/*_test.rb"]
10
11
  end
11
12
 
13
+ task :generate_index_words do
14
+ puts FunnyYubikeyGenerator.filter_and_index_words(File.open("/usr/share/dict/words")).to_yaml
15
+ end
16
+
12
17
  require "standard/rake"
13
18
 
14
19
  task default: %i[test standard]
@@ -27,7 +27,7 @@ end.parse!
27
27
 
28
28
  generator = if dictionary
29
29
  raise "Could not find file #{dictionary}" unless File.exist?(dictionary)
30
- FunnyYubikeyGenerator.new(dictionary: File.open(dictionary))
30
+ FunnyYubikeyGenerator.from_dictionary(File.open(dictionary))
31
31
  else
32
32
  FunnyYubikeyGenerator.instance
33
33
  end
@@ -1,15 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/funny_yubikey_generator"
4
-
5
3
  Gem::Specification.new do |spec|
6
4
  spec.name = "funny_yubikey_generator"
7
- spec.version = FunnyYubikeyGenerator::VERSION
5
+ spec.version = "0.4.0"
8
6
  spec.authors = ["Xavier Delamotte"]
9
7
  spec.email = ["git@xade.eu"]
10
8
 
11
- spec.summary = "Generates fun yubikeys"
12
- spec.description = "Generates fun yubikeys"
9
+ spec.summary = "Generate funny looking yubikey OTP containing words based on a dictionary."
10
+ spec.description = "Generate funny looking yubikey OTP containing words based on a dictionary."
13
11
  spec.homepage = "https://github.com/x4d3/funny_yubikey_generator"
14
12
  spec.license = "MIT"
15
13
  spec.required_ruby_version = ">= 2.6.0"
@@ -3,24 +3,24 @@
3
3
  require "singleton"
4
4
  require "colorize"
5
5
  require "set"
6
+ require "yaml"
6
7
 
7
8
  class FunnyYubikeyGenerator
8
- VERSION = "0.2.0"
9
+ include Singleton
9
10
  COLORS = %i[red green yellow blue magenta cyan]
11
+ LETTERS = "cbdefghijklnrtuv"
12
+ WORD_REGEX = /^[#{Regexp.quote(LETTERS)}]+{4,}$/
10
13
  private_constant :COLORS
14
+ private_constant :LETTERS
15
+
11
16
  class << self
12
- def initialize_singleton
13
- @singleton__instance__ = nil
14
- @singleton__mutex__ = Thread::Mutex.new
17
+ def from_dictionary(dictionary)
18
+ indexed_words = filter_and_index_words(dictionary)
19
+ new(indexed_words: indexed_words)
15
20
  end
16
21
 
17
- def instance # :nodoc:
18
- return @singleton__instance__ if @singleton__instance__
19
- @singleton__mutex__.synchronize {
20
- return @singleton__instance__ if @singleton__instance__
21
- @singleton__instance__ = new
22
- }
23
- @singleton__instance__
22
+ def filter_and_index_words(dictionary)
23
+ dictionary.scan(WORD_REGEX).group_by(&:length)
24
24
  end
25
25
 
26
26
  def generate(colorize: false)
@@ -28,20 +28,13 @@ class FunnyYubikeyGenerator
28
28
  end
29
29
  end
30
30
 
31
- initialize_singleton
32
-
33
- def initialize(dictionary: default_dictionary, letters: "cbdefghijklnrtuv".chars.to_set)
34
- @dictionary = dictionary.map(&:strip).select { |line|
35
- line.chars.all? do |c|
36
- letters.include?(c)
37
- end
38
- }.group_by(&:length)
31
+ def initialize(indexed_words: load_default_indexed_words)
32
+ @indexed_words = indexed_words
39
33
  end
40
34
 
41
35
  def generate(colorize: false)
42
- words_lengths = @dictionary.keys - [1, 2, 3]
43
- words = random_partition(40, words_lengths).map do |s|
44
- @dictionary[s].sample
36
+ words = random_partition(40, @indexed_words.keys).map do |s|
37
+ @indexed_words[s].sample
45
38
  end
46
39
  if colorize
47
40
  words.map!.with_index { |w, i| w.colorize(COLORS[i % COLORS.length]) }
@@ -51,14 +44,8 @@ class FunnyYubikeyGenerator
51
44
 
52
45
  private
53
46
 
54
- def default_dictionary
55
- [
56
- "/usr/share/dict/words",
57
- "/usr/dict/word",
58
- File.join(__dir__, "words.txt")
59
- ].each do |path|
60
- return File.open(path) if File.exist?(path)
61
- end
47
+ def load_default_indexed_words
48
+ YAML.load_file(File.join(__dir__, "indexed_words.yaml"))
62
49
  end
63
50
 
64
51
  def random_partition(target, word_lengths)