ssbx 0.1.5 → 0.1.6

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: e8cac41924cd31245f471e60522d958da2b6a1d3b88161930aff945440f0b451
4
- data.tar.gz: 420bc230bfc9f2df406617d32317cf6b8febc385bbfed6929c0862a59f794312
3
+ metadata.gz: f2132a8b2ea3e99b5af1a7fb19751560aeac5b2158bdecf1017e19f6bedadacd
4
+ data.tar.gz: ceb0e18fc93e884ccf133c6732ba4f564c60bac7fee5dc9a4f6032e69cac7957
5
5
  SHA512:
6
- metadata.gz: 34009a357a04ffcb61df3c112e228fb18d6152d01e25f54b2e561f1b661e4fe9e4e74478d5828cb3eb108bd2f0f9be02a4ee8a9bce822f0363707993c671b2db
7
- data.tar.gz: 976b293b5faa6dcf9ef2ec49e49b971cf77bd3c59b0ee09277d1f0f323b4257e20160103f6d9b8f0d16d5a030f0331e534a7fe1edbcebf5c7b29fae0cd95b81b
6
+ metadata.gz: fc0de25d170ab074b06e123eaa9ba962ba3734a5241421721ba2b145871ea2e01255713ce67f84e637f566e3071db5138bbbc57d6c73b477dd8baca67840f8f0
7
+ data.tar.gz: b953c1ac36b85f6997c8fc3b9d75474df865eb8d249d0c4531ff9bd0dd6be574b0b0ac5cc9b310debd84950a078336fd07cb18efa9030e7f0997d8afff451bf0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ssbx (0.1.4)
4
+ ssbx (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exe/ssbx CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "ssbx"
4
+ require 'ssbx/cli'
4
5
  require 'optparse'
5
6
  require 'yaml'
6
7
  require 'pp'
@@ -12,11 +13,7 @@ CONFIG = {
12
13
  'pass' => 'password',
13
14
  }
14
15
 
15
- default_config = File.join(ENV['HOME'], '.ssbx.yaml')
16
- if File.file? default_config
17
- c = YAML::load(File.read(default_config))
18
- CONFIG.merge!(c)
19
- end
16
+ Ssbx::Cli::load_default(CONFIG)
20
17
 
21
18
  CONFIG['delete_users'] = []
22
19
  CONFIG['add_users'] = []
@@ -73,34 +70,7 @@ OptionParser.new do |opts|
73
70
  end.parse! ARGV
74
71
 
75
72
  if CONFIG['config']
76
- print "User name? [#{ENV['USER']}]: "
77
- CONFIG['user'] = STDIN.readline.chomp
78
- CONFIG['user'] = ENV['USER'] if CONFIG['user'] == ''
79
-
80
- require 'io/console'
81
- STDIN.echo = false
82
- print "Password: "
83
- p = begin
84
- STDIN.readline.chomp
85
- ensure
86
- STDIN.echo = true
87
- puts ''
88
- end
89
- CONFIG['pass'] = p unless p == ''
90
-
91
- print "Editor? [#{ENV['EDITOR']}]: "
92
- e = STDIN.readline.chomp
93
- CONFIG['editor'] = e unless e == ''
94
-
95
- require 'yaml'
96
- File.open(default_config, 'wb') do |io|
97
- io.write(YAML::dump(
98
- CONFIG.select do |k,v|
99
- k !~ /^delete_users|add_users|config|verbose$/
100
- end
101
- ))
102
-
103
- end
73
+ Ssbx::Cli::config(CONFIG)
104
74
  end
105
75
 
106
76
  if CONFIG['verbose']
@@ -108,132 +78,31 @@ if CONFIG['verbose']
108
78
  pp CONFIG
109
79
  end
110
80
 
111
- if CONFIG['pass'] == 'prompt'
112
- require 'io/console'
113
- print "Enter your password: "
114
- STDIN.echo = false
115
- begin
116
- CONFIG['pass'] = STDIN.readline.chomp
117
- puts ''
118
- ensure
119
- STDIN.echo = true
120
- end
121
-
122
- end
123
-
124
81
  if CONFIG['change_password']
125
- require 'io/console'
126
- STDIN.echo = false
127
- begin
128
- print("Old password: ")
129
- old_pw = STDIN.readline.chomp
130
- print("\nNew password: ")
131
- new_pw1 = STDIN.readline.chomp
132
- print("\nRetype new password: ")
133
- new_pw2 = STDIN.readline.chomp
134
- puts ''
135
-
136
- if new_pw1 != new_pw2
137
- puts "Old and new passwords do not match. Taking no action."
138
- else
139
- f = Ssbx::File.new
140
- bx = Ssbx::Box.new(f)
141
-
142
- # Decrypt with the old key.
143
- data = Ssbx::Util.read(CONFIG['file']) { |io| bx.read(io, CONFIG['user'], old_pw) }
144
-
145
- Ssbx::Util.write(CONFIG['file']) { |io| bx.write(io, CONFIG['user'], new_pw1, data) }
146
-
147
- end
148
- ensure
149
- STDIN.echo = true
150
- end
82
+ Ssbx::Cli::change_password(CONFIG)
151
83
  end
152
84
 
153
85
  CONFIG['delete_users'].each do |u|
154
- f = Ssbx::Util.read(CONFIG['file']) { |io| Ssbx::File.new(io) }
155
- bx = Ssbx::Box.new(f)
156
- bx.remove_user(u)
157
- Ssbx::Util.write(CONFIG['file']) { |io| f.write(io) }
86
+ Ssbx::Cli::delete_users(CONFIG)
158
87
  end
159
88
 
160
89
  if CONFIG['add_users'].length > 0
161
- f = Ssbx::File.new
162
- bx = Ssbx::Box.new(f)
163
- data = Ssbx::Util.read(CONFIG['file']) do |io|
164
- bx.read(io, CONFIG['user'], CONFIG['pass'])
165
- end
90
+ Ssbx::Cli::add_users(CONFIG)
91
+ end
166
92
 
167
- CONFIG['add_users'].each do |u|
168
- u, p = u[0], u[1] || u[0]
169
-
170
- Ssbx::Util.write(CONFIG['file']) do |io|
171
- bx.write(io, u, p, data)
172
- end
173
- end
93
+ if CONFIG['list']
94
+ Ssbx::Cli::list_users(CONFIG)
174
95
  end
175
96
 
176
97
  if CONFIG['set']
177
- f = Ssbx::File.new
178
- bx = Ssbx::Box.new(f)
179
- data = Ssbx::Util.read(CONFIG['set']) do |io|
180
- io.read
181
- end
182
- Ssbx::Util.write(CONFIG['file']) do |io|
183
- bx.write(io, CONFIG['user'], CONFIG['pass'], data)
184
- end
98
+ Ssbx::Cli::set(CONFIG)
185
99
  end
186
100
 
187
101
  if CONFIG['out']
188
- f = Ssbx::File.new
189
- bx = Ssbx::Box.new(f)
190
- data = Ssbx::Util.read(CONFIG['file']) do |io|
191
- bx.read(io, CONFIG['user'], CONFIG['pass'])
192
- end
193
-
194
- Ssbx::Util.write(CONFIG['out']) { |io| io.write(data) }
102
+ Ssbx::Cli::get(CONFIG)
195
103
  end
196
104
 
197
105
  if CONFIG['edit']
198
- f = Ssbx::File.new
199
- bx = Ssbx::Box.new(f)
200
-
201
- data = if File.file? CONFIG['file']
202
- Ssbx::Util.read(CONFIG['file']) do |io|
203
- bx.read(io, CONFIG['user'], CONFIG['pass'])
204
- end
205
- else
206
- ''
207
- end
208
-
209
- tmpfile = Tempfile.new("ssbx")
210
- tmpfile.write(data)
211
- tmpfile.flush
212
-
213
- begin
214
- editor = CONFIG['editor'] || ENV['EDITOR']
215
-
216
- system("#{editor} #{tmpfile.path}")
217
-
218
- tmpfile.rewind
219
- data = File.read(tmpfile)
220
- File.open(CONFIG['file'], 'wb') do |io|
221
- bx.write(io, CONFIG['user'], CONFIG['pass'], data)
222
- end
223
- ensure
224
- tmpfile.unlink
225
- end
106
+ Ssbx::Cli::edit(CONFIG)
226
107
  end
227
108
 
228
- if CONFIG['list']
229
- f = Ssbx::File.new
230
- bx = Ssbx::Box.new(f)
231
-
232
- Ssbx::Util.read(CONFIG['file']) do |io|
233
- f.read(io)
234
- end
235
-
236
- bx.list.each do |u|
237
- puts u
238
- end
239
- end
@@ -0,0 +1,6 @@
1
+
2
+ require 'ssbx/cli/config_task'
3
+ require 'ssbx/cli/get_password_task'
4
+ require 'ssbx/cli/change_password_task'
5
+ require 'ssbx/cli/user_task'
6
+ require 'ssbx/cli/edit_task'
@@ -0,0 +1,37 @@
1
+ require 'io/console'
2
+
3
+ require 'ssbx/file'
4
+ require 'ssbx/box'
5
+ require 'ssbx/util'
6
+
7
+ module Ssbx
8
+ module Cli
9
+ def self.change_password(config)
10
+ STDIN.echo = false
11
+ begin
12
+ print("Old password: ")
13
+ old_pw = STDIN.readline.chomp
14
+ print("\nNew password: ")
15
+ new_pw1 = STDIN.readline.chomp
16
+ print("\nRetype new password: ")
17
+ new_pw2 = STDIN.readline.chomp
18
+ puts ''
19
+
20
+ if new_pw1 != new_pw2
21
+ puts "Old and new passwords do not match. Taking no action."
22
+ else
23
+ f = Ssbx::File.new
24
+ bx = Ssbx::Box.new(f)
25
+
26
+ # Decrypt with the old key.
27
+ data = Ssbx::Util.read(config['file']) { |io| bx.read(io, config['user'], old_pw) }
28
+
29
+ Ssbx::Util.write(config['file']) { |io| bx.write(io, config['user'], new_pw1, data) }
30
+
31
+ end
32
+ ensure
33
+ STDIN.echo = true
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ require 'io/console'
2
+ require 'yaml'
3
+
4
+ module Ssbx
5
+ module Cli
6
+
7
+ @@default_config_file = ::File.join(ENV['HOME'], '.ssbx.yaml')
8
+
9
+ def self.load_default(config)
10
+ if ::File.file? @@default_config_file
11
+ c = YAML::load(::File.read(@@default_config_file))
12
+ config.merge!(c)
13
+ end
14
+ end
15
+
16
+ def self.config(config)
17
+ print "User name? [#{ENV['USER']}]: "
18
+ config['user'] = STDIN.readline.chomp
19
+ config['user'] = ENV['USER'] if config['user'] == ''
20
+
21
+ require 'io/console'
22
+ STDIN.echo = false
23
+ print "Password: "
24
+ p = begin
25
+ STDIN.readline.chomp
26
+ ensure
27
+ STDIN.echo = true
28
+ puts ''
29
+ end
30
+ config['pass'] = p unless p == ''
31
+
32
+ print "Editor? [#{ENV['EDITOR']}]: "
33
+ e = STDIN.readline.chomp
34
+ config['editor'] = e unless e == ''
35
+
36
+ require 'yaml'
37
+ ::File.open(@@default_config_file, 'wb') do |io|
38
+ io.write(YAML::dump(
39
+ config.select do |k,v|
40
+ k !~ /^delete_users|add_users|config|verbose$/
41
+ end
42
+ ))
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,61 @@
1
+ require 'ssbx/file'
2
+ require 'ssbx/box'
3
+ require 'ssbx/cli/get_password_task'
4
+ require 'tempfile'
5
+ module Ssbx
6
+ module Cli
7
+
8
+ def self.set(config)
9
+ f = Ssbx::File.new
10
+ bx = Ssbx::Box.new(f)
11
+ data = Ssbx::Util.read(config['set']) do |io|
12
+ io.read
13
+ end
14
+ Ssbx::Util.write(config['file']) do |io|
15
+ bx.write(io, config['user'], get_password(config), data)
16
+ end
17
+ end
18
+
19
+ def self.get(config)
20
+ f = Ssbx::File.new
21
+ bx = Ssbx::Box.new(f)
22
+ data = Ssbx::Util.read(config['file']) do |io|
23
+ bx.read(io, config['user'], get_password(config))
24
+ end
25
+
26
+ Ssbx::Util.write(config['out']) { |io| io.write(data) }
27
+ end
28
+
29
+ def self.edit(config)
30
+ f = Ssbx::File.new
31
+ bx = Ssbx::Box.new(f)
32
+ p = get_password(config)
33
+
34
+ data = if ::File.file? config['file']
35
+ Ssbx::Util.read(config['file']) do |io|
36
+ bx.read(io, config['user'], p)
37
+ end
38
+ else
39
+ ''
40
+ end
41
+
42
+ tmpfile = Tempfile.new("ssbx")
43
+ tmpfile.write(data)
44
+ tmpfile.flush
45
+
46
+ begin
47
+ editor = config['editor'] || ENV['EDITOR']
48
+
49
+ system("#{editor} #{tmpfile.path}")
50
+
51
+ tmpfile.rewind
52
+ data = ::File.read(tmpfile)
53
+ ::File.open(config['file'], 'wb') do |io|
54
+ bx.write(io, config['user'], p, data)
55
+ end
56
+ ensure
57
+ tmpfile.unlink
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,20 @@
1
+ require 'io/console'
2
+
3
+ module Ssbx
4
+ module Cli
5
+ def self.get_password(config)
6
+ if config['pass'] == 'prompt'
7
+ print "Enter your password: "
8
+ STDIN.echo = false
9
+ begin
10
+ config['pass'] = STDIN.readline.chomp
11
+ puts ''
12
+ ensure
13
+ STDIN.echo = true
14
+ end
15
+ end
16
+
17
+ config['pass']
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ require 'ssbx/file'
2
+ require 'ssbx/box'
3
+ require 'ssbx/cli/get_password_task'
4
+
5
+ module Ssbx
6
+ module Cli
7
+ def self.list_users(config)
8
+ f = Ssbx::File.new
9
+ bx = Ssbx::Box.new(f)
10
+
11
+ Ssbx::Util.read(config['file']) do |io|
12
+ f.read(io)
13
+ end
14
+
15
+ bx.list.each do |u|
16
+ puts u
17
+ end
18
+ end
19
+
20
+ def self.delete_users(config)
21
+ config['delete_users'].each do |u|
22
+ f = Ssbx::Util.read(config['file']) { |io| Ssbx::File.new(io) }
23
+ bx = Ssbx::Box.new(f)
24
+ bx.remove_user(u)
25
+ Ssbx::Util.write(config['file']) { |io| f.write(io) }
26
+ end
27
+ end
28
+
29
+ def self.add_users(config)
30
+ f = Ssbx::File.new
31
+ bx = Ssbx::Box.new(f)
32
+ p = get_password(config)
33
+
34
+ data = Ssbx::Util.read(config['file']) do |io|
35
+ bx.read(io, config['user'], p)
36
+ end
37
+
38
+ config['add_users'].each do |u|
39
+ u, p = u[0], u[1] || u[0]
40
+
41
+ Ssbx::Util.write(config['file']) do |io|
42
+ bx.write(io, u, p, data)
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Ssbx
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssbx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam
@@ -58,6 +58,12 @@ files:
58
58
  - exe/ssbx
59
59
  - lib/ssbx.rb
60
60
  - lib/ssbx/box.rb
61
+ - lib/ssbx/cli.rb
62
+ - lib/ssbx/cli/change_password_task.rb
63
+ - lib/ssbx/cli/config_task.rb
64
+ - lib/ssbx/cli/edit_task.rb
65
+ - lib/ssbx/cli/get_password_task.rb
66
+ - lib/ssbx/cli/user_task.rb
61
67
  - lib/ssbx/file.rb
62
68
  - lib/ssbx/util.rb
63
69
  - lib/ssbx/version.rb
@@ -84,7 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
90
  - !ruby/object:Gem::Version
85
91
  version: '0'
86
92
  requirements: []
87
- rubygems_version: 3.0.1
93
+ rubyforge_project:
94
+ rubygems_version: 2.7.6
88
95
  signing_key:
89
96
  specification_version: 4
90
97
  summary: Shared encrypted file.