ruby_gpg 0.2.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.
- data/CHANGELOG.markdown +11 -1
- data/README.markdown +5 -0
- data/VERSION +1 -1
- data/lib/ruby_gpg.rb +30 -4
- data/ruby_gpg.gemspec +3 -3
- data/spec/ruby_gpg_spec.rb +77 -1
- metadata +21 -40
data/CHANGELOG.markdown
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# v0.3.0 (2010-07-16)
|
2
|
+
|
3
|
+
In which other people do my work for me...
|
4
|
+
|
5
|
+
## Thanks to Scott and Divya of [gitcaps](http://github.com/gitcapps) for:
|
6
|
+
|
7
|
+
* New `RubyGpg.encrypt_string` method.
|
8
|
+
* Option to allow decryption of ascii armored files (*.asc).
|
9
|
+
* Option to specify output filename.
|
10
|
+
|
1
11
|
# v0.2.0 (2010-03-17)
|
2
12
|
|
3
13
|
* Add `RubyGpg.decrypt_string` method.
|
@@ -8,4 +18,4 @@
|
|
8
18
|
|
9
19
|
# v0.1.0 (2010-03-16)
|
10
20
|
|
11
|
-
* First version with `RubyGpg.encrypt` and `RubyGpg.decrypt` methods.
|
21
|
+
* First version with `RubyGpg.encrypt` and `RubyGpg.decrypt` methods.
|
data/README.markdown
CHANGED
@@ -27,6 +27,11 @@ for some reason, I guess you have to settle for this.
|
|
27
27
|
For more details, see the
|
28
28
|
[RDocs](http://rdoc.info/projects/blaix/ruby_gpg).
|
29
29
|
|
30
|
+
## Credits
|
31
|
+
|
32
|
+
Scott and Divya of [gitcaps](http://github.com/gitcapps) added some sorely
|
33
|
+
missing features. Thanks, guys.
|
34
|
+
|
30
35
|
## Copyright
|
31
36
|
|
32
37
|
Copyright (c) 2010 Justin Blake. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/ruby_gpg.rb
CHANGED
@@ -13,14 +13,32 @@ module RubyGpg
|
|
13
13
|
" --no-secmem-warning --no-permission-warning --no-tty --yes"
|
14
14
|
end
|
15
15
|
|
16
|
-
def encrypt(file, recipient)
|
17
|
-
|
16
|
+
def encrypt(file, recipient, opts = {})
|
17
|
+
options = {
|
18
|
+
:armor => false
|
19
|
+
}.merge(opts)
|
20
|
+
|
21
|
+
output = output_filename(file, options)
|
22
|
+
|
23
|
+
ascii = options[:armor] == true ? "-a " : ""
|
24
|
+
|
25
|
+
command = "#{gpg_command} #{ascii}--output #{output}" +
|
18
26
|
" --recipient \"#{recipient}\" --encrypt #{file}"
|
27
|
+
|
19
28
|
run_command(command)
|
20
29
|
end
|
21
30
|
|
22
|
-
|
23
|
-
|
31
|
+
# Encrypt a string from stdin
|
32
|
+
def encrypt_string(string, recipient, opts = {})
|
33
|
+
command = gpg_command.dup
|
34
|
+
command << " -a" if opts[:armor]
|
35
|
+
command << " --encrypt"
|
36
|
+
command << " --recipient \"#{recipient}\""
|
37
|
+
run_command(command, string)
|
38
|
+
end
|
39
|
+
|
40
|
+
def decrypt(file, passphrase = nil, opts = {})
|
41
|
+
outfile = opts[:output].nil? ? file.gsub(/\.gpg$|\.asc$/, '') : opts[:output]
|
24
42
|
command = "#{gpg_command} --output #{outfile}"
|
25
43
|
command << " --passphrase #{passphrase}" if passphrase
|
26
44
|
command << " --decrypt #{file}"
|
@@ -35,6 +53,7 @@ module RubyGpg
|
|
35
53
|
end
|
36
54
|
|
37
55
|
private
|
56
|
+
|
38
57
|
def run_command(command, input = nil)
|
39
58
|
output = ""
|
40
59
|
Open3.popen3(command) do |stdin, stdout, stderr|
|
@@ -48,4 +67,11 @@ module RubyGpg
|
|
48
67
|
end
|
49
68
|
output
|
50
69
|
end
|
70
|
+
|
71
|
+
# Return the output filename to use
|
72
|
+
def output_filename(file, opts)
|
73
|
+
extension = opts[:armor] ? "asc" : "gpg"
|
74
|
+
opts[:output].nil? ? "#{file}.#{extension}" : opts[:output]
|
75
|
+
end
|
76
|
+
|
51
77
|
end
|
data/ruby_gpg.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruby_gpg}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin Blake"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-16}
|
13
13
|
s.description = %q{Ruby wrapper for the gpg binary}
|
14
14
|
s.email = %q{justin@megablaix.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.homepage = %q{http://github.com/blaix/ruby_gpg}
|
43
43
|
s.rdoc_options = ["--charset=UTF-8"]
|
44
44
|
s.require_paths = ["lib"]
|
45
|
-
s.rubygems_version = %q{1.3.
|
45
|
+
s.rubygems_version = %q{1.3.5}
|
46
46
|
s.summary = %q{Ruby wrapper for the gpg binary}
|
47
47
|
s.test_files = [
|
48
48
|
"spec/ruby_gpg_spec.rb",
|
data/spec/ruby_gpg_spec.rb
CHANGED
@@ -82,6 +82,61 @@ describe "RubyGpg" do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
describe '.encrypt(filename, recipient, opts) with armor specified' do
|
86
|
+
def run_encrypt
|
87
|
+
RubyGpg.encrypt('filename', 'recipient', {:armor => true})
|
88
|
+
end
|
89
|
+
|
90
|
+
it "saves armored version to filename.asc" do
|
91
|
+
expect_command_to_match("-a --output filename.asc")
|
92
|
+
run_encrypt
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '.encrypt(filename, recipient, opts) with ascii output file specified' do
|
97
|
+
def run_encrypt
|
98
|
+
RubyGpg.encrypt('filename', 'recipient', {:armor => true, :output => "foo.asc"})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "saves armored version to foo.asc" do
|
102
|
+
expect_command_to_match("-a --output foo.asc")
|
103
|
+
run_encrypt
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '.encrypt_string(string, recipient, opts)' do
|
108
|
+
def run_encrypt_string
|
109
|
+
RubyGpg.encrypt_string("string to encrypt", "recipient")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "uses the configured gpg command" do
|
113
|
+
expect_command_to_match(/^#{Regexp.escape(RubyGpg.gpg_command)}/)
|
114
|
+
run_encrypt_string
|
115
|
+
end
|
116
|
+
|
117
|
+
it "issues an encrypt command to gpg" do
|
118
|
+
expect_command_to_match("--encrypt")
|
119
|
+
run_encrypt_string
|
120
|
+
end
|
121
|
+
|
122
|
+
it "issues the encrypts command for the passed recipient" do
|
123
|
+
expect_command_to_match("--recipient \"recipient\"")
|
124
|
+
run_encrypt_string
|
125
|
+
end
|
126
|
+
|
127
|
+
it "sends the passed string as stdin" do
|
128
|
+
@stdin.expects(:write).with('string to encrypt')
|
129
|
+
run_encrypt_string
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns the encrypted string" do
|
133
|
+
@stdout.write("encrypted string")
|
134
|
+
@stdout.rewind
|
135
|
+
run_encrypt_string.should == "encrypted string"
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
85
140
|
describe '.decrypt(filename)' do
|
86
141
|
def run_decrypt(passphrase = nil)
|
87
142
|
RubyGpg.decrypt('filename.gpg', passphrase)
|
@@ -108,7 +163,9 @@ describe "RubyGpg" do
|
|
108
163
|
end
|
109
164
|
|
110
165
|
it "saves decrypted version to filename without .gpg extension" do
|
111
|
-
|
166
|
+
# Note the space after "filename". Without the space it is possible that
|
167
|
+
# the file extention still exists
|
168
|
+
expect_command_to_match("--output filename ")
|
112
169
|
run_decrypt
|
113
170
|
end
|
114
171
|
|
@@ -122,6 +179,25 @@ describe "RubyGpg" do
|
|
122
179
|
end
|
123
180
|
end
|
124
181
|
|
182
|
+
describe '.decrypt(filename) for asc file' do
|
183
|
+
def run_decrypt(passphrase = nil, opts = {})
|
184
|
+
RubyGpg.decrypt('filename.asc', passphrase, opts)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "issues the decrypt command for the ascii filename" do
|
188
|
+
# Note the space after "filename". Without the space it is possible that
|
189
|
+
# the file extention still exists
|
190
|
+
expect_command_to_match("--output filename ")
|
191
|
+
run_decrypt
|
192
|
+
end
|
193
|
+
|
194
|
+
it "issues the decrypt command for the filename passed in options" do
|
195
|
+
expect_command_to_match("--output foo.txt ")
|
196
|
+
run_decrypt(nil, {:output => "foo.txt"})
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
125
201
|
describe '.decrypt_string(string)' do
|
126
202
|
def run_decrypt_string(passphrase = nil)
|
127
203
|
RubyGpg.decrypt_string('encrypted string', passphrase)
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_gpg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
version: 0.2.0
|
4
|
+
version: 0.3.0
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Justin Blake
|
@@ -14,61 +9,49 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2010-
|
12
|
+
date: 2010-07-16 00:00:00 -04:00
|
18
13
|
default_executable:
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: rspec
|
22
|
-
|
23
|
-
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 2
|
30
|
-
- 9
|
31
23
|
version: 1.2.9
|
32
|
-
|
33
|
-
version_requirements: *id001
|
24
|
+
version:
|
34
25
|
- !ruby/object:Gem::Dependency
|
35
26
|
name: yard
|
36
|
-
|
37
|
-
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
30
|
requirements:
|
39
31
|
- - ">="
|
40
32
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
33
|
version: "0"
|
44
|
-
|
45
|
-
version_requirements: *id002
|
34
|
+
version:
|
46
35
|
- !ruby/object:Gem::Dependency
|
47
36
|
name: cucumber
|
48
|
-
|
49
|
-
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
40
|
requirements:
|
51
41
|
- - ">="
|
52
42
|
- !ruby/object:Gem::Version
|
53
|
-
segments:
|
54
|
-
- 0
|
55
43
|
version: "0"
|
56
|
-
|
57
|
-
version_requirements: *id003
|
44
|
+
version:
|
58
45
|
- !ruby/object:Gem::Dependency
|
59
46
|
name: mocha
|
60
|
-
|
61
|
-
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
62
50
|
requirements:
|
63
51
|
- - ">="
|
64
52
|
- !ruby/object:Gem::Version
|
65
|
-
segments:
|
66
|
-
- 0
|
67
|
-
- 9
|
68
|
-
- 8
|
69
53
|
version: 0.9.8
|
70
|
-
|
71
|
-
version_requirements: *id004
|
54
|
+
version:
|
72
55
|
description: Ruby wrapper for the gpg binary
|
73
56
|
email: justin@megablaix.com
|
74
57
|
executables: []
|
@@ -113,20 +96,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
96
|
requirements:
|
114
97
|
- - ">="
|
115
98
|
- !ruby/object:Gem::Version
|
116
|
-
segments:
|
117
|
-
- 0
|
118
99
|
version: "0"
|
100
|
+
version:
|
119
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
102
|
requirements:
|
121
103
|
- - ">="
|
122
104
|
- !ruby/object:Gem::Version
|
123
|
-
segments:
|
124
|
-
- 0
|
125
105
|
version: "0"
|
106
|
+
version:
|
126
107
|
requirements: []
|
127
108
|
|
128
109
|
rubyforge_project:
|
129
|
-
rubygems_version: 1.3.
|
110
|
+
rubygems_version: 1.3.5
|
130
111
|
signing_key:
|
131
112
|
specification_version: 3
|
132
113
|
summary: Ruby wrapper for the gpg binary
|