sixword 0.3.3 → 0.3.4

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
  SHA1:
3
- metadata.gz: 510c9016d6296108aea1122a763e3389c608715e
4
- data.tar.gz: 8e93476177ebc6c328c7ea7972b65b9c6f660e83
3
+ metadata.gz: a5f8241501d3ec9a161b47b2b3d013de7eee6c7f
4
+ data.tar.gz: 0df5938f25ccf57e734f53d0fce16dc87504121f
5
5
  SHA512:
6
- metadata.gz: 5c295ddfd1e6b4c616cc1257bd71a0aab7707c42bab0fafa8b88b5e9ee3c29658d8715ffb236353f27d2018b6cb46285769a0f8ee50a0030b474423cc08f0d0b
7
- data.tar.gz: 32824743c047bba15734a0819bb896ba1c9ff299b9cfb6214da582fe5c4999560e595fe249b82b2aa7942193811003d5402547aee62a187ba2835c050599c294
6
+ metadata.gz: 50dd98d6d7c3ae1c0936c05be2cb0b21eb63141701fe329baa58b3eaf3224621817dd2406d7b4532e24e1e3a305aa849e181d47800ecf2370f8e932dfbf1191d
7
+ data.tar.gz: e42402107439bdf45dbb38b79b039b08d8af4f7454f10486147684bb83a8873eacdc7cd83e91d257bf95f19448bd7af9ca01eed7a9b2d5c173738d35c4f3d5e0
data/.travis.yml CHANGED
@@ -5,6 +5,7 @@ rvm:
5
5
  - "2.1" # latest 2.1.x
6
6
  - "2.2" # latest 2.2.x
7
7
  - "jruby-19mode"
8
+ - "jruby-head"
8
9
  script:
9
10
  bundle exec rake test
10
11
  sudo: false
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.3.4] -- 2015-12-06
8
+
9
+ - Add multi-sentence output option for encoding mode (-w, --line-width). This
10
+ allows users to output multiples of 6 words on a line when encoding.
11
+
7
12
  ## [0.3.3] -- 2015-12-01
8
13
 
9
14
  - Fix handling of words that straddle the 2048-byte buffer boundary. Previously
data/README.md CHANGED
@@ -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
@@ -1,4 +1,4 @@
1
1
  module Sixword
2
2
  # version string
3
- VERSION = '0.3.3'
3
+ VERSION = '0.3.4'
4
4
  end
@@ -0,0 +1,156 @@
1
+ RSpec.describe Sixword::CLI do
2
+
3
+ @@test_warnings = Set.new
4
+ def warn_once(label, message)
5
+ unless @@test_warnings.include?(label)
6
+ warn message
7
+ @@test_warnings << label
8
+ end
9
+ end
10
+
11
+ if RUBY_ENGINE == 'jruby' && JRUBY_VERSION.start_with?('1.7')
12
+ RunningJruby17 = true
13
+ else
14
+ RunningJruby17 = false
15
+ end
16
+
17
+ # hack around jruby9 warnings on travis
18
+ if RUBY_ENGINE == 'jruby' && ENV['TRAVIS'] && JRUBY_VERSION.start_with?('9.0')
19
+ RunningTravisJruby9 = true
20
+ SixwordOutputPrefix = "jruby: warning: unknown property jruby.cext.enabled\n" * 2
21
+ else
22
+ RunningTravisJruby9 = false
23
+ end
24
+
25
+ # Run a command with input and validate the expected output and exit status.
26
+ def run(cmd, input_string, expected_output, expected_exitstatus=0)
27
+ output = nil
28
+
29
+ if RunningJruby17
30
+ warn_once('jruby17', 'test warning: skipping unsupported popen option :err')
31
+ opts = {}
32
+ else
33
+ opts = {err: [:child, :out]}
34
+ end
35
+
36
+ IO.popen(cmd, 'r+', opts) do |p|
37
+ p.write(input_string)
38
+ p.close_write
39
+ output = p.read
40
+ end
41
+
42
+ if expected_output.is_a?(Regexp)
43
+ expect(output).to match(expected_output)
44
+ else
45
+ expect(output).to eq(expected_output)
46
+ end
47
+
48
+ expect($?.exited?).to eq(true) unless RunningJruby17
49
+ expect($?.exitstatus).to eq(expected_exitstatus)
50
+ end
51
+
52
+ SixwordExecutable = File.dirname(__FILE__) + '/../../bin/sixword'
53
+
54
+ def run_sixword(opts, input_string, expected_output, expected_exitstatus=0)
55
+
56
+ # hack around IO.popen stderr behavior in ruby 1.9
57
+ if RUBY_VERSION.start_with?('1.9') && expected_exitstatus != 0 &&
58
+ (expected_output.is_a?(Regexp) || !expected_output.empty?)
59
+
60
+ warn_once('ruby19', "test warning: overriding output #{expected_output.inspect} with ''")
61
+ expected_output = ''
62
+ end
63
+
64
+ if RunningTravisJruby9 && expected_output.is_a?(String)
65
+ expected_output = SixwordOutputPrefix + expected_output
66
+ end
67
+
68
+ run([SixwordExecutable] + opts, input_string, expected_output, expected_exitstatus)
69
+ end
70
+
71
+ it 'handles basic encoding and decoding' do
72
+ run_sixword(['-e'], "Testing\n", "BEAK NET SITE ROTH SWIM FORM\n")
73
+ run_sixword([], "Testing\n", "BEAK NET SITE ROTH SWIM FORM\n")
74
+ run_sixword(['-d'], "BEAK NET SITE ROTH SWIM FORM\n", "Testing\n")
75
+ run_sixword(['-d'], "beak net site roth swim form\n", "Testing\n")
76
+
77
+ run_sixword(['-v'], '', 'sixword ' + Sixword::VERSION + "\n")
78
+ end
79
+
80
+ it 'returns expected error codes in various conditions' do
81
+ run_sixword(%w{-e --hex-style nonexistent}, '', /unknown hex style/, 2)
82
+ run_sixword(['-d'], "BEAK NET SITE ROTH SWIM FOR\n", /Parity bits do not match/, 3)
83
+ run_sixword(['-d'], "ZZZ A A A A A\n", /Unknown word: "ZZZ"/, 4)
84
+ run_sixword(['-d'], "AAAAAA A A A A A\n", /1-4 chars/, 5)
85
+
86
+ run_sixword(['-d'], "A\n", /multiple of 6 words/, 10)
87
+ end
88
+
89
+ it 'handles padding' do
90
+ run_sixword([], 'foo', "CHUB EMIL MUDD A A A5\n")
91
+ run_sixword(['-d'], "CHUB EMIL MUDD A A A5\n", 'foo')
92
+ end
93
+
94
+ it 'rejects padding when -p is given' do
95
+ run_sixword(['-ep'], '.', /multiple of 8 or use pad_encode/, 10)
96
+ run_sixword(['-dp'], "CHUB EMIL MUDD A A A5\n", /Unknown word: "A5"/, 4)
97
+ end
98
+
99
+ it 'handles basic hex styles' do
100
+ run_sixword(['-H'], "54:65:73:74:69:6e:67:0a\n", "BEAK NET SITE ROTH SWIM FORM\n")
101
+ run_sixword(['-H'], "54657374696e670a\n", "BEAK NET SITE ROTH SWIM FORM\n")
102
+ run_sixword(['-H'], "5465 7374 696E 670A\n", "BEAK NET SITE ROTH SWIM FORM\n")
103
+
104
+ run_sixword(['-dH'], "BEAK NET SITE ROTH SWIM FORM\n", "54657374696e670a\n")
105
+ run_sixword(['-df'], "BEAK NET SITE ROTH SWIM FORM\n", "5465 7374 696E 670A\n")
106
+ run_sixword(%w{-d -S colons}, "BEAK NET SITE ROTH SWIM FORM\n", "54:65:73:74:69:6e:67:0a\n")
107
+ end
108
+
109
+ it 'should encode/decode RFC hex vectors correctly' do
110
+ Sixword::TestVectors::HexTests.each do |_section, tests|
111
+ tests.each do |hex, sentence|
112
+ debug_puts "0x#{hex} <=> #{sentence}"
113
+
114
+ if sentence.split.length > 6
115
+ expected_encoded = sentence.split.each_slice(6).map {|line| line.join(' ')}.join("\n")
116
+ else
117
+ expected_encoded = sentence
118
+ end
119
+
120
+ run_sixword(['-df'], sentence, hex + "\n")
121
+ run_sixword(['-ef'], hex, expected_encoded + "\n")
122
+ end
123
+ end
124
+ end
125
+
126
+ it 'should handle all null bytes correctly' do
127
+ run_sixword(['-ep'], "\0" * 8, "A A A A A A\n")
128
+ run_sixword(['-dp'], "A A A A A A\n", "\0" * 8)
129
+ end
130
+
131
+ it 'should handle padded null bytes correctly' do
132
+ {
133
+ "\0\0\0foo" => ["A", "A", "HAY", "SLEW", "TROT", "A2"],
134
+ "\0\0\0foo\0\0" => ["A", "A", "HAY", "SLEW", "TROT", "A"],
135
+ "foo\0\0" => ["CHUB", "EMIL", "MUDD", "A", "A", "A3"],
136
+ }.each do |binary, encoded|
137
+ encoded_s = encoded.join(' ') + "\n"
138
+ run_sixword(['-e'], binary, encoded_s)
139
+ run_sixword(['-d'], encoded_s, binary)
140
+ end
141
+ end
142
+
143
+ it 'should encode N sentences per line' do
144
+ input = 'The quick brown fox jump'
145
+
146
+ {
147
+ 0 => "BEAK US ACHE SOUR BERN LOLA CORE ARC HULK SLID DREW DUE CHUB ENDS BOG RUSS BESS MAST\n",
148
+ 1 => "BEAK US ACHE SOUR BERN LOLA\nCORE ARC HULK SLID DREW DUE\nCHUB ENDS BOG RUSS BESS MAST\n",
149
+ 2 => "BEAK US ACHE SOUR BERN LOLA CORE ARC HULK SLID DREW DUE\nCHUB ENDS BOG RUSS BESS MAST\n",
150
+ 3 => "BEAK US ACHE SOUR BERN LOLA CORE ARC HULK SLID DREW DUE CHUB ENDS BOG RUSS BESS MAST\n",
151
+ 4 => "BEAK US ACHE SOUR BERN LOLA CORE ARC HULK SLID DREW DUE CHUB ENDS BOG RUSS BESS MAST\n",
152
+ }.each_pair do |width, expected_output|
153
+ run_sixword(['-e', '-w %d' % width], input, expected_output)
154
+ end
155
+ end
156
+ 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.3
4
+ version: 0.3.4
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-12-01 00:00:00.000000000 Z
11
+ date: 2015-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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
@@ -153,14 +154,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  version: '0'
154
155
  requirements: []
155
156
  rubyforge_project:
156
- rubygems_version: 2.2.5
157
+ rubygems_version: 2.4.5.1
157
158
  signing_key:
158
159
  specification_version: 4
159
160
  summary: Implementation of RFC 2289 compatible 6-word encoding
160
161
  test_files:
161
- - spec/sixword/hex_spec.rb
162
- - spec/sixword/lib_spec.rb
163
- - spec/sixword_spec.rb
162
+ - spec/cli/cli_spec.rb
164
163
  - spec/spec_helper.rb
165
164
  - spec/test_vectors.rb
165
+ - spec/unit/sixword/hex_spec.rb
166
+ - spec/unit/sixword/lib_spec.rb
167
+ - spec/unit/sixword_spec.rb
166
168
  has_rdoc: