ssbx 0.1.1 → 0.1.2

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: fb3f97e7f7bcd6aced71f70fca0c43ebec72d0e4251b003e447a87d49eacb039
4
- data.tar.gz: ecc265a10d0045c6f07944b7379432b7bf2452a77b2ca9893b1d6acb5f0d4424
3
+ metadata.gz: 8ac01c3e11dac6e4e8ef24b14e88dbb64164dd6fd81c34c7e0408c90b26838dd
4
+ data.tar.gz: 5c0bf89484444b8b72c1e5a07df573364f75b315f8abe099ef81236a0b277055
5
5
  SHA512:
6
- metadata.gz: df6183075ea93db79bd41942085cfd45b18a807cf17f198d0c7071d92a79f7098288d5e08c9a2c2fed48f73ae995e986b85acecf6850a49b22fe7426b37b4022
7
- data.tar.gz: 3e68060e935524cc38184c5e63c6e48ef19b909e86ba0fd2314d43e52e6c34b8dbaaebaf8c5cde76f1cd3c630f25394f4931d25079da365a33625c41a46426b5
6
+ metadata.gz: e28b74015ab982982ad09ab7c7e5f914acb249f8f61f3fa221d2e572ed2f52758d4622777c9000079f5e19a052ac45e1ae585f73feb4fe4e7559bf7d6d4cbdfb
7
+ data.tar.gz: ced2414f90e641209126b2205f49eb10d8d3f0822f75198e963739d5d0d2c57e5093c61c043e02dd83edbf4bd92de9b3fc835adf3f2f3e8438fc121ce954e4b5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ssbx (0.1.0)
4
+ ssbx (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -23,10 +23,30 @@ Edit `~/.ssbx.yaml` to contain...
23
23
  ```yaml
24
24
  user: You
25
25
  pass: A secret password
26
+ # This is optional if you want to override $EDITOR.
27
+ editor: vi
26
28
  ```
27
29
 
28
30
  Then use `ssbx` to view or edit a file.
29
31
 
32
+ ## Simple Recipes
33
+
34
+ # Add a user with a simple password.
35
+ sbx -f f1.enc -a user1:userpass
36
+
37
+ # ... or
38
+ cat f1.enc | ssbx -f - -a user1:userpass > f2.enc
39
+
40
+ # Remove the user.
41
+ ssbx -f f1.enc -d user1:userpass
42
+
43
+ # File data to standard out.
44
+ ssbx -f f1.enc -o -
45
+
46
+ # Edit file data and re-encrypt the file.
47
+ ssbx -f f1.enc -e
48
+
49
+
30
50
  ## Development
31
51
 
32
52
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/exe/ssbx CHANGED
@@ -4,6 +4,7 @@ require "ssbx"
4
4
  require 'optparse'
5
5
  require 'yaml'
6
6
  require 'pp'
7
+ require 'tempfile'
7
8
 
8
9
  CONFIG = {
9
10
  'file' => 'ssbx.enc',
@@ -29,6 +30,10 @@ OptionParser.new do |opts|
29
30
  CONFIG['list'] = true
30
31
  end
31
32
 
33
+ opts.on('-e', '--edit', "Edit the given file with EDITOR and exit.") do
34
+ CONFIG['edit'] = true
35
+ end
36
+
32
37
  opts.on('-d', '--delete=user', String, "Delete user. May be used multiple times.") do |u|
33
38
  CONFIG['delete_users'] << u
34
39
  end
@@ -60,24 +65,23 @@ if CONFIG['verbose']
60
65
  end
61
66
 
62
67
  CONFIG['delete_users'].each do |u|
63
- f = Ssbx::File.new
64
- File.open(CONFIG['file'], 'r') { |io| f.read(io) }
68
+ f = Ssbx::Util.read(CONFIG['file']) { |io| Ssbx::File.new(io) }
65
69
  bx = Ssbx::Box.new(f)
66
70
  bx.remove_user(u)
67
- File.open(CONFIG['file'], 'wb') { |io| f.write(io) }
71
+ Ssbx::Util.write(CONFIG['file']) { |io| f.write(io) }
68
72
  end
69
73
 
70
- if CONFIG['add_users']
74
+ if CONFIG['add_users'].length > 0
71
75
  f = Ssbx::File.new
72
76
  bx = Ssbx::Box.new(f)
73
- data = File.open(CONFIG['file'], 'rb') do |io|
77
+ data = Ssbx::Util.read(CONFIG['file']) do |io|
74
78
  bx.read(io, CONFIG['user'], CONFIG['pass'])
75
79
  end
76
80
 
77
81
  CONFIG['add_users'].each do |u|
78
82
  u, p = u[0], u[1] || u[0]
79
83
 
80
- File.open(CONFIG['file'], 'wb') do |io|
84
+ Ssbx::Util.write(CONFIG['file']) do |io|
81
85
  bx.write(io, u, p, data)
82
86
  end
83
87
  end
@@ -87,31 +91,57 @@ if CONFIG['set']
87
91
  f = Ssbx::File.new
88
92
  bx = Ssbx::Box.new(f)
89
93
  data = File.read(CONFIG['set'])
90
- File.open(CONFIG['file'], 'wb') do |io|
91
- bx.write(io, CONFIG['user'], CONFIG['pass'], data)
92
- end
94
+ Ssbx::Util.write(CONFIG['file']) do |io|
95
+ bx.write(io, u, p, data)
96
+ end
93
97
  end
94
98
 
95
99
  if CONFIG['out']
96
100
  f = Ssbx::File.new
97
101
  bx = Ssbx::Box.new(f)
98
- data = File.open(CONFIG['file'], 'rb') do |io|
102
+ data = Ssbx::Util.read(CONFIG['file']) do |io|
99
103
  bx.read(io, CONFIG['user'], CONFIG['pass'])
100
104
  end
101
105
 
102
- if CONFIG['out'] == '-'
103
- STDOUT.write(data)
104
- else
105
- File.open(CONFIG['out'], 'wb') do |io|
106
- io.write(data)
106
+ Ssbx::Util.write(CONFIG['out']) { |io| io.write(data) }
107
+ end
108
+
109
+ if CONFIG['edit']
110
+ f = Ssbx::File.new
111
+ bx = Ssbx::Box.new(f)
112
+
113
+ data = if File.file? CONFIG['file']
114
+ Ssbx::Util.read(CONFIG['file']) do |io|
115
+ bx.read(io, CONFIG['user'], CONFIG['pass'])
116
+ end
117
+ else
118
+ ''
119
+ end
120
+
121
+ tmpfile = Tempfile.new("ssbx")
122
+ tmpfile.write(data)
123
+ tmpfile.flush
124
+
125
+ begin
126
+ editor = CONFIG['editor'] || ENV['EDITOR']
127
+
128
+ system("#{editor} #{tmpfile.path}")
129
+
130
+ tmpfile.rewind
131
+ data = File.read(tmpfile)
132
+ File.open(CONFIG['file'], 'wb') do |io|
133
+ bx.write(io, CONFIG['user'], CONFIG['pass'], data)
107
134
  end
135
+ ensure
136
+ tmpfile.unlink
108
137
  end
109
138
  end
110
139
 
111
140
  if CONFIG['list']
112
141
  f = Ssbx::File.new
113
142
  bx = Ssbx::Box.new(f)
114
- File.open(CONFIG['file'], 'rb') do |io|
143
+
144
+ Ssbx::Util.read(CONFIG['file']) do |io|
115
145
  f.read(io)
116
146
  end
117
147
 
data/lib/ssbx/file.rb CHANGED
@@ -16,9 +16,10 @@ module Ssbx
16
16
  # The file data.
17
17
  attr_accessor :data
18
18
 
19
- def initialize
19
+ def initialize(optional_stream = nil)
20
20
  @keys = []
21
21
  @data = ''
22
+ read(optional_stream) if optional_stream
22
23
  end
23
24
 
24
25
  def write(out)
@@ -38,7 +39,7 @@ module Ssbx
38
39
  out.write(@data)
39
40
  end
40
41
 
41
- def read(istream)
42
+ def read(istream)
42
43
  @keys = []
43
44
  # Read the key record length...
44
45
  istream.read(4).unpack('N')[0].times do
data/lib/ssbx/util.rb ADDED
@@ -0,0 +1,47 @@
1
+ module Ssbx
2
+ module Util
3
+ def self.read(istream)
4
+ if istream.is_a? String
5
+ stream = if istream == '-'
6
+ STDIN
7
+ else
8
+ ::File.open(istream, 'rb')
9
+ end
10
+
11
+ if block_given?
12
+ begin
13
+ yield stream
14
+ ensure
15
+ stream.close
16
+ end
17
+ else
18
+ stream
19
+ end
20
+ else
21
+ raise Exception.new("Unsupported type #{istream.class}.")
22
+ end
23
+ end
24
+
25
+ def self.write(ostream)
26
+ if ostream.is_a? String
27
+ stream = if ostream == '-'
28
+ STDOUT
29
+ else
30
+ ::File.open(ostream, 'wb')
31
+ end
32
+
33
+ if block_given?
34
+ begin
35
+ yield stream
36
+ ensure
37
+ stream.close
38
+ end
39
+ else
40
+ stream
41
+ end
42
+ else
43
+ raise Exception.new("Unsupported type #{ostream.class}.")
44
+ end
45
+ end
46
+ end
47
+ end
data/lib/ssbx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ssbx
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/ssbx.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "ssbx/version"
2
2
  require "ssbx/file"
3
3
  require "ssbx/box"
4
+ require "ssbx/util"
4
5
 
5
6
  module Ssbx
6
7
  class Error < StandardError; 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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam
@@ -59,6 +59,7 @@ files:
59
59
  - lib/ssbx.rb
60
60
  - lib/ssbx/box.rb
61
61
  - lib/ssbx/file.rb
62
+ - lib/ssbx/util.rb
62
63
  - lib/ssbx/version.rb
63
64
  - ssbx.gemspec
64
65
  homepage: https://gitlab.com/basking2/ssbx