sixword 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 412a951ad1786d3f978ebc77305e6b7094004b36
4
- data.tar.gz: 1a70321549259a131a8a10a536117d29a529110a
2
+ SHA256:
3
+ metadata.gz: b74ea6c562414ef7a07f742098179f75bccb9807cd5e75161d5f8cb2a04ee780
4
+ data.tar.gz: 9e5842fc333709e4469d518d5fcffd90987a60fff2c070892923e69dcff19c93
5
5
  SHA512:
6
- metadata.gz: 9a2ca1765246ff2b0df8e4ae6b6f8554abec1fbbf7c07478b5e9b36ea38e7b34cb22e352b8c49c4786e9ebaf85927a3d270c48f005fa7e8fba4a00ab24ea09b0
7
- data.tar.gz: 0b44ad6d9bd5c7d2b7d0c5ddf9272357be00bf4e1917a46321c595afd72d754a33eae2eda1af3c503539f388427345b59d8ffc81e0505e544b139e910845d760
6
+ metadata.gz: 8b238947058e4b05daadb950f3c67f72c7ace5982d97b7e7ec68ad5047ec93ccf3b82af3b0cd9956296e04b1f625a6c0d755db6f3443612ba947a5cf68a16a9d
7
+ data.tar.gz: 05d8e291207ad2fcc499584a7647de32ef7f9c4a41a2d9d6b35c0a8629de7eb552e880e938a3990fa4ea2a52f8b22b618372b1bc05c2981104027da028d0eb27
@@ -0,0 +1,18 @@
1
+ name: tests
2
+ on: [push, pull_request]
3
+ jobs:
4
+ run-tests:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu-latest] #, macos-latest
9
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
10
+ ruby: [2.6, 2.7, '3.0', head, jruby, jruby-head]
11
+ runs-on: ${{ matrix.os }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ bundler-cache: true
18
+ - run: bundle exec rake test
@@ -120,13 +120,10 @@ Style/SpaceInsideBlockBraces:
120
120
  Style/SpaceInsideHashLiteralBraces:
121
121
  Enabled: false
122
122
 
123
- # TODO this is affected by rubocop bug
124
- # https://github.com/bbatsov/rubocop/issues/2448
125
- #
126
123
  # Offense count: 27
127
124
  # Cop supports --auto-correct.
128
125
  # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
129
- Style/TrailingComma:
126
+ Style/TrailingCommaInLiteral:
130
127
  # SupportedStyles:
131
128
  # - comma
132
129
  # - no_comma
@@ -136,6 +133,10 @@ Style/TrailingComma:
136
133
  Style/WordArray:
137
134
  Enabled: false
138
135
 
136
+ # Definitely do NOT assign variables within a conditional. Christ.
137
+ Style/ConditionalAssignment:
138
+ Enabled: false
139
+
139
140
  # ********************************
140
141
 
141
142
  # Configuration parameters: AllowedVariables.
data/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@ This project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.3.5] -- 2018-03-28
8
+
9
+ - Fix up rubocop config etc.
10
+
11
+ ## [0.3.4] -- 2015-12-06
12
+
13
+ - Add multi-sentence output option for encoding mode (-w, --line-width). This
14
+ allows users to output multiples of 6 words on a line when encoding.
15
+
16
+ ## [0.3.3] -- 2015-12-01
17
+
18
+ - Fix handling of words that straddle the 2048-byte buffer boundary. Previously
19
+ any word that was split over the boundary would be mangled into two words,
20
+ resulting in an error or incorrect output. This only affected the sixword
21
+ CLI. [#3](https://github.com/ab/sixword/issues/3)
22
+
7
23
  ## [0.3.2] -- 2015-11-25
8
24
 
9
25
  - Add lots of documentation and a change log!
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Sixword
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/sixword.svg)](https://rubygems.org/gems/sixword)
4
- [![Build status](https://travis-ci.org/ab/sixword.svg)](https://travis-ci.org/ab/sixword)
4
+ [![Build status](https://github.com/ab/sixword/actions/workflows/tests.yml/badge.svg)](https://github.com/ab/sixword/actions/workflows/tests.yml)
5
5
  [![Code Climate](https://codeclimate.com/github/ab/sixword.svg)](https://codeclimate.com/github/ab/sixword)
6
6
  [![Inline Docs](http://inch-ci.org/github/ab/sixword.svg?branch=master)](http://www.rubydoc.info/github/ab/sixword/master)
7
7
 
@@ -79,7 +79,7 @@ The same data, but hex encoded
79
79
  $ sixword -dH <<< 'BEAK NET SITE ROTH SWIM FORM'
80
80
  54657374696e670a
81
81
 
82
- $ sixword -dF <<< 'BEAK NET SITE ROTH SWIM FORM'
82
+ $ sixword -df <<< 'BEAK NET SITE ROTH SWIM FORM'
83
83
  5465 7374 696E 670A
84
84
 
85
85
  $ sixword -d -S colons <<< 'BEAK NET SITE ROTH SWIM FORM'
data/bin/sixword CHANGED
@@ -86,9 +86,16 @@ Options:
86
86
  options[:hex_style] = 'lowercase'
87
87
  end
88
88
 
89
- opts.on('-f', '--fingerprint', 'Short for --hex-style fingerprint') do
89
+ opts.on('-f', '--fingerprint', 'Short for --hex-style fingerprint', ' ') do
90
90
  options[:hex_style] = 'fingerprint'
91
91
  end
92
+
93
+ #
94
+
95
+ opts.on('-w', '--line-width NUM',
96
+ 'Print NUM sentences per line when encoding') do |arg|
97
+ options[:line_width] = Integer(arg)
98
+ end
92
99
  end
93
100
 
94
101
  begin
data/lib/sixword/cli.rb CHANGED
@@ -27,6 +27,8 @@ module Sixword
27
27
  # @option options [:encode, :decode] :mode (:encode)
28
28
  # @option options [Boolean] :pad (false)
29
29
  # @option options [String] :hex_style
30
+ # @option options [Integer] :line_width (1) In encode mode, the number of
31
+ # sentences to output per line.
30
32
  #
31
33
  def initialize(filename, options)
32
34
  @filename = filename
@@ -125,11 +127,29 @@ module Sixword
125
127
  end
126
128
 
127
129
  def do_encode!
130
+ sentences_per_line = options.fetch(:line_width, 1)
131
+ if sentences_per_line <= 0
132
+ sentences_per_line = 1 << 32
133
+ end
134
+
135
+ sentences = []
136
+
128
137
  process_encode_input do |chunk|
129
138
  Sixword.encode_iter(chunk, words_per_slice:6, pad:pad?) do |encoded|
130
- yield encoded
139
+ sentences << encoded
140
+
141
+ # yield sentences once we reach sentences_per_line of them
142
+ if sentences.length >= sentences_per_line
143
+ yield sentences.join(' ')
144
+ sentences.clear
145
+ end
131
146
  end
132
147
  end
148
+
149
+ # yield any leftover sentences
150
+ unless sentences.empty?
151
+ yield sentences.join(' ')
152
+ end
133
153
  end
134
154
 
135
155
  def process_encode_input
@@ -165,16 +185,15 @@ module Sixword
165
185
 
166
186
  # Yield data 6 words at a time until EOF
167
187
  def read_input_by_6_words
168
- block_size = 2048
169
188
  word_arr = []
170
189
 
171
190
  while true
172
- buf = stream.read(block_size)
173
- if buf.nil?
191
+ line = stream.gets
192
+ if line.nil?
174
193
  break # EOF
175
194
  end
176
195
 
177
- buf.scan(/\S+/) do |word|
196
+ line.scan(/\S+/) do |word|
178
197
  word_arr << word
179
198
 
180
199
  # return the array if we have accumulated 6 words
data/lib/sixword/lib.rb CHANGED
@@ -96,7 +96,8 @@ module Sixword
96
96
 
97
97
  # check parity
98
98
  unless parity_int(int) == parity
99
- raise InvalidParity.new("Parity bits do not match")
99
+ raise InvalidParity.new("Parity bits do not match: " +
100
+ word_array.join(' ').inspect)
100
101
  end
101
102
 
102
103
  # omit padding bits, if any
@@ -1,4 +1,4 @@
1
1
  module Sixword
2
2
  # version string
3
- VERSION = '0.3.2'
3
+ VERSION = '0.4.0'.freeze
4
4
  end
data/lib/sixword/words.rb CHANGED
@@ -258,11 +258,7 @@ module Sixword
258
258
  "WITH", "WOLF", "WONT", "WOOD", "WOOL", "WORD", "WORE", "WORK",
259
259
  "WORM", "WORN", "WOVE", "WRIT", "WYNN", "YALE", "YANG", "YANK",
260
260
  "YARD", "YARN", "YAWL", "YAWN", "YEAH", "YEAR", "YELL", "YOGA",
261
- "YOKE" ]
262
-
263
- # mutability sucks
264
- WORDS.freeze
265
- WORDS.each(&:freeze)
261
+ "YOKE" ].map(&:freeze).freeze
266
262
 
267
263
  # A mapping from Word => Integer index in the word list
268
264
  WORDS_HASH = Hash[WORDS.each_with_index.to_a]
data/sixword.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = 'sixword'
8
8
  spec.version = Sixword::VERSION
9
9
  spec.authors = ['Andy Brody']
10
- spec.email = ['abrody@abrody.com']
10
+ spec.email = ['git@abrody.com']
11
11
  spec.summary = 'Implementation of RFC 2289 compatible 6-word encoding'
12
12
  spec.description = <<-EOM
13
13
  Sixword implements the 6-word binary encoding created for S/Key (tm) and
@@ -27,11 +27,11 @@ Gem::Specification.new do |spec|
27
27
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_development_dependency 'bundler', '~> 1.3'
30
+ spec.add_development_dependency 'bundler', '~> 2.2'
31
31
  spec.add_development_dependency 'pry'
32
32
  spec.add_development_dependency 'rake'
33
33
  spec.add_development_dependency 'rspec', '~> 3.0'
34
- spec.add_development_dependency 'rubocop', '~> 0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.49'
35
35
  spec.add_development_dependency 'yard'
36
36
 
37
37
  spec.required_ruby_version = '>= 1.9.3'
@@ -0,0 +1,158 @@
1
+ require 'set'
2
+
3
+ RSpec.describe Sixword::CLI do
4
+
5
+ TestWarnings = Set.new
6
+ def warn_once(label, message)
7
+ unless TestWarnings.include?(label)
8
+ warn message
9
+ TestWarnings << label
10
+ end
11
+ end
12
+
13
+ if RUBY_ENGINE == 'jruby' && JRUBY_VERSION.start_with?('1.7')
14
+ RunningJruby17 = true
15
+ else
16
+ RunningJruby17 = false
17
+ end
18
+
19
+ # hack around jruby9 warnings on travis
20
+ if RUBY_ENGINE == 'jruby' && ENV['TRAVIS'] && JRUBY_VERSION.start_with?('9.0')
21
+ RunningTravisJruby9 = true
22
+ SixwordOutputPrefix = "jruby: warning: unknown property jruby.cext.enabled\n" * 2
23
+ else
24
+ RunningTravisJruby9 = false
25
+ end
26
+
27
+ # Run a command with input and validate the expected output and exit status.
28
+ def run(cmd, input_string, expected_output, expected_exitstatus=0)
29
+ output = nil
30
+
31
+ if RunningJruby17
32
+ warn_once('jruby17', 'test warning: skipping unsupported popen option :err')
33
+ opts = {}
34
+ else
35
+ opts = {err: [:child, :out]}
36
+ end
37
+
38
+ IO.popen(cmd, 'r+', opts) do |p|
39
+ p.write(input_string)
40
+ p.close_write
41
+ output = p.read
42
+ end
43
+
44
+ if expected_output.is_a?(Regexp)
45
+ expect(output).to match(expected_output)
46
+ else
47
+ expect(output).to eq(expected_output)
48
+ end
49
+
50
+ expect($?.exited?).to eq(true) unless RunningJruby17
51
+ expect($?.exitstatus).to eq(expected_exitstatus)
52
+ end
53
+
54
+ SixwordExecutable = File.dirname(__FILE__) + '/../../bin/sixword'
55
+
56
+ def run_sixword(opts, input_string, expected_output, expected_exitstatus=0)
57
+
58
+ # hack around IO.popen stderr behavior in ruby 1.9
59
+ if RUBY_VERSION.start_with?('1.9') && expected_exitstatus != 0 &&
60
+ (expected_output.is_a?(Regexp) || !expected_output.empty?)
61
+
62
+ warn_once('ruby19', "test warning: overriding output #{expected_output.inspect} with ''")
63
+ expected_output = ''
64
+ end
65
+
66
+ if RunningTravisJruby9 && expected_output.is_a?(String)
67
+ expected_output = SixwordOutputPrefix + expected_output
68
+ end
69
+
70
+ run([SixwordExecutable] + opts, input_string, expected_output, expected_exitstatus)
71
+ end
72
+
73
+ it 'handles basic encoding and decoding' do
74
+ run_sixword(['-e'], "Testing\n", "BEAK NET SITE ROTH SWIM FORM\n")
75
+ run_sixword([], "Testing\n", "BEAK NET SITE ROTH SWIM FORM\n")
76
+ run_sixword(['-d'], "BEAK NET SITE ROTH SWIM FORM\n", "Testing\n")
77
+ run_sixword(['-d'], "beak net site roth swim form\n", "Testing\n")
78
+
79
+ run_sixword(['-v'], '', 'sixword ' + Sixword::VERSION + "\n")
80
+ end
81
+
82
+ it 'returns expected error codes in various conditions' do
83
+ run_sixword(%w{-e --hex-style nonexistent}, '', /unknown hex style/, 2)
84
+ run_sixword(['-d'], "BEAK NET SITE ROTH SWIM FOR\n", /Parity bits do not match/, 3)
85
+ run_sixword(['-d'], "ZZZ A A A A A\n", /Unknown word: "ZZZ"/, 4)
86
+ run_sixword(['-d'], "AAAAAA A A A A A\n", /1-4 chars/, 5)
87
+
88
+ run_sixword(['-d'], "A\n", /multiple of 6 words/, 10)
89
+ end
90
+
91
+ it 'handles padding' do
92
+ run_sixword([], 'foo', "CHUB EMIL MUDD A A A5\n")
93
+ run_sixword(['-d'], "CHUB EMIL MUDD A A A5\n", 'foo')
94
+ end
95
+
96
+ it 'rejects padding when -p is given' do
97
+ run_sixword(['-ep'], '.', /multiple of 8 or use pad_encode/, 10)
98
+ run_sixword(['-dp'], "CHUB EMIL MUDD A A A5\n", /Unknown word: "A5"/, 4)
99
+ end
100
+
101
+ it 'handles basic hex styles' do
102
+ run_sixword(['-H'], "54:65:73:74:69:6e:67:0a\n", "BEAK NET SITE ROTH SWIM FORM\n")
103
+ run_sixword(['-H'], "54657374696e670a\n", "BEAK NET SITE ROTH SWIM FORM\n")
104
+ run_sixword(['-H'], "5465 7374 696E 670A\n", "BEAK NET SITE ROTH SWIM FORM\n")
105
+
106
+ run_sixword(['-dH'], "BEAK NET SITE ROTH SWIM FORM\n", "54657374696e670a\n")
107
+ run_sixword(['-df'], "BEAK NET SITE ROTH SWIM FORM\n", "5465 7374 696E 670A\n")
108
+ run_sixword(%w{-d -S colons}, "BEAK NET SITE ROTH SWIM FORM\n", "54:65:73:74:69:6e:67:0a\n")
109
+ end
110
+
111
+ it 'should encode/decode RFC hex vectors correctly' do
112
+ Sixword::TestVectors::HexTests.each do |_section, tests|
113
+ tests.each do |hex, sentence|
114
+ debug_puts "0x#{hex} <=> #{sentence}"
115
+
116
+ if sentence.split.length > 6
117
+ expected_encoded = sentence.split.each_slice(6).map {|line| line.join(' ')}.join("\n")
118
+ else
119
+ expected_encoded = sentence
120
+ end
121
+
122
+ run_sixword(['-df'], sentence, hex + "\n")
123
+ run_sixword(['-ef'], hex, expected_encoded + "\n")
124
+ end
125
+ end
126
+ end
127
+
128
+ it 'should handle all null bytes correctly' do
129
+ run_sixword(['-ep'], "\0" * 8, "A A A A A A\n")
130
+ run_sixword(['-dp'], "A A A A A A\n", "\0" * 8)
131
+ end
132
+
133
+ it 'should handle padded null bytes correctly' do
134
+ {
135
+ "\0\0\0foo" => ["A", "A", "HAY", "SLEW", "TROT", "A2"],
136
+ "\0\0\0foo\0\0" => ["A", "A", "HAY", "SLEW", "TROT", "A"],
137
+ "foo\0\0" => ["CHUB", "EMIL", "MUDD", "A", "A", "A3"],
138
+ }.each do |binary, encoded|
139
+ encoded_s = encoded.join(' ') + "\n"
140
+ run_sixword(['-e'], binary, encoded_s)
141
+ run_sixword(['-d'], encoded_s, binary)
142
+ end
143
+ end
144
+
145
+ it 'should encode N sentences per line' do
146
+ input = 'The quick brown fox jump'
147
+
148
+ {
149
+ 0 => "BEAK US ACHE SOUR BERN LOLA CORE ARC HULK SLID DREW DUE CHUB ENDS BOG RUSS BESS MAST\n",
150
+ 1 => "BEAK US ACHE SOUR BERN LOLA\nCORE ARC HULK SLID DREW DUE\nCHUB ENDS BOG RUSS BESS MAST\n",
151
+ 2 => "BEAK US ACHE SOUR BERN LOLA CORE ARC HULK SLID DREW DUE\nCHUB ENDS BOG RUSS BESS MAST\n",
152
+ 3 => "BEAK US ACHE SOUR BERN LOLA CORE ARC HULK SLID DREW DUE CHUB ENDS BOG RUSS BESS MAST\n",
153
+ 4 => "BEAK US ACHE SOUR BERN LOLA CORE ARC HULK SLID DREW DUE CHUB ENDS BOG RUSS BESS MAST\n",
154
+ }.each_pair do |width, expected_output|
155
+ run_sixword(['-e', '-w %d' % width], input, expected_output)
156
+ end
157
+ end
158
+ end
data/spec/test_vectors.rb CHANGED
@@ -4,7 +4,7 @@ module Sixword
4
4
  # from RFC 2289 and RFC 1751
5
5
  HexTests = {
6
6
  'rfc2289 parity' => {
7
- '85c43ee03857765b' => 'FOWL KID MASH DEAD DUAL OAF',
7
+ '85C4 3EE0 3857 765B' => 'FOWL KID MASH DEAD DUAL OAF',
8
8
  },
9
9
  'rfc2289 md4' => {
10
10
  'D185 4218 EBBB 0B51' => 'ROME MUG FRED SCAN LIVE LACE',
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sixword
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Brody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '0.49'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '0.49'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: yard
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -104,17 +104,17 @@ description: |2
104
104
 
105
105
  See also: Bubble Babble, PGP Word List, Diceware, Base64, Base32
106
106
  email:
107
- - abrody@abrody.com
107
+ - git@abrody.com
108
108
  executables:
109
109
  - sixword
110
110
  extensions: []
111
111
  extra_rdoc_files: []
112
112
  files:
113
+ - ".github/workflows/tests.yml"
113
114
  - ".gitignore"
114
115
  - ".rspec"
115
116
  - ".rubocop-disables.yml"
116
117
  - ".rubocop.yml"
117
- - ".travis.yml"
118
118
  - CHANGELOG.md
119
119
  - Gemfile
120
120
  - LICENSE.txt
@@ -128,11 +128,12 @@ files:
128
128
  - lib/sixword/version.rb
129
129
  - lib/sixword/words.rb
130
130
  - sixword.gemspec
131
- - spec/sixword/hex_spec.rb
132
- - spec/sixword/lib_spec.rb
133
- - spec/sixword_spec.rb
131
+ - spec/cli/cli_spec.rb
134
132
  - spec/spec_helper.rb
135
133
  - spec/test_vectors.rb
134
+ - spec/unit/sixword/hex_spec.rb
135
+ - spec/unit/sixword/lib_spec.rb
136
+ - spec/unit/sixword_spec.rb
136
137
  homepage: https://github.com/ab/sixword
137
138
  licenses:
138
139
  - GPL-3
@@ -152,15 +153,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
153
  - !ruby/object:Gem::Version
153
154
  version: '0'
154
155
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.2.5
156
+ rubygems_version: 3.0.3.1
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Implementation of RFC 2289 compatible 6-word encoding
160
160
  test_files:
161
- - spec/sixword/hex_spec.rb
162
- - spec/sixword/lib_spec.rb
163
- - spec/sixword_spec.rb
161
+ - spec/cli/cli_spec.rb
164
162
  - spec/spec_helper.rb
165
163
  - spec/test_vectors.rb
166
- has_rdoc:
164
+ - spec/unit/sixword/hex_spec.rb
165
+ - spec/unit/sixword/lib_spec.rb
166
+ - spec/unit/sixword_spec.rb
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - "1.9.3"
4
- - "2.0.0"
5
- - "2.1" # latest 2.1.x
6
- - "2.2" # latest 2.2.x
7
- - "jruby-19mode"
8
- script:
9
- bundle exec rake test