funny_yubikey_generator 0.1.0 → 0.3.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: 350531896679505d5c75b0aa08f9cfa5bd1d1adde5a7f17f85fa1b2009b50765
4
- data.tar.gz: 324ee9f08142ba54a720e9a26768f79d8b5fdfa9f9841e498477ee322ff28a32
3
+ metadata.gz: ee03f537080c0eee30e79ca418b86395103442b5b7212cb862de5065fa5af037
4
+ data.tar.gz: b7351abcdaef208798a496a93d9b6529010ea965f1a4f7a3ba507e72ee9421e2
5
5
  SHA512:
6
- metadata.gz: 0e93ba39d11fcf9b1c1a480b7cc18c863fdce73407b0a349bba6ecb60c9b5c00d13c5e9bb06cfe1aa1d15532fc6f8f1faca10a34761e7eef16de63b1a1cfa84b
7
- data.tar.gz: d7fa16ed1a142d953a33207e455176b92484dc26ca4f85fd3e8fb344307a3626bec3cebc744e46292f9afad7c298f41c35f8f34533bd602a516a8c8668cd8418
6
+ metadata.gz: cea34ab297af170a44379b8123d55def53f2bb4db9de3bd12567fecf1b6ed51c47f99eda0792d7eb6c01738ee48aa1a7d1c38b9fcb31f8e9f9d82e21099838e8
7
+ data.tar.gz: f781e1fef15707693c9fb1874e125c9d322916fce9f5658be85d0e91fe62aacc774a56011306da3ff91f212be10be7ca570a1dc024de6b7ec5c80d7979326e6e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funny_yubikey_generator (0.1.0)
4
+ funny_yubikey_generator (0.3.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
+ [![0.3.0](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,26 +18,30 @@ 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.split("\n"))
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
@@ -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]
@@ -3,24 +3,27 @@
3
3
  require "singleton"
4
4
  require "colorize"
5
5
  require "set"
6
+ require "yaml"
6
7
 
7
8
  class FunnyYubikeyGenerator
8
- VERSION = "0.1.0"
9
+ include Singleton
10
+ VERSION = "0.3.0"
9
11
  COLORS = %i[red green yellow blue magenta cyan]
12
+ LETTERS = "cbdefghijklnrtuv".chars.to_set
13
+
10
14
  private_constant :COLORS
15
+ private_constant :LETTERS
16
+
11
17
  class << self
12
- def initialize_singleton
13
- @singleton__instance__ = nil
14
- @singleton__mutex__ = Thread::Mutex.new
18
+ def from_dictionary(dictionary)
19
+ indexed_words = filter_and_index_words(dictionary)
20
+ new(indexed_words: indexed_words)
15
21
  end
16
22
 
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__
23
+ def filter_and_index_words(dictionary)
24
+ dictionary.map(&:strip).select { |line|
25
+ line.size > 3 && line.chars.all? { |c| LETTERS.include?(c) }
26
+ }.group_by(&:length)
24
27
  end
25
28
 
26
29
  def generate(colorize: false)
@@ -28,20 +31,13 @@ class FunnyYubikeyGenerator
28
31
  end
29
32
  end
30
33
 
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)
34
+ def initialize(indexed_words: load_default_indexed_words)
35
+ @indexed_words = indexed_words
39
36
  end
40
37
 
41
38
  def generate(colorize: false)
42
- words_lengths = @dictionary.keys
43
- words = random_partition(40, words_lengths).map do |s|
44
- @dictionary[s].sample
39
+ words = random_partition(40, @indexed_words.keys).map do |s|
40
+ @indexed_words[s].sample
45
41
  end
46
42
  if colorize
47
43
  words.map!.with_index { |w, i| w.colorize(COLORS[i % COLORS.length]) }
@@ -51,14 +47,8 @@ class FunnyYubikeyGenerator
51
47
 
52
48
  private
53
49
 
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
50
+ def load_default_indexed_words
51
+ YAML.load_file(File.join(__dir__, "indexed_words.yaml"))
62
52
  end
63
53
 
64
54
  def random_partition(target, word_lengths)