gpgr 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/gpgr.rb +21 -6
- data/test/test_file_encryption_functionality.rb +39 -0
- data/test/test_helper.rb +3 -3
- metadata +10 -17
- data/test/generate_keys.rb +0 -31
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake/testtask'
|
|
4
4
|
require "rake/rdoctask"
|
5
5
|
require "rake/gempackagetask"
|
6
6
|
|
7
|
-
GPGR_VERSION = "0.0.
|
7
|
+
GPGR_VERSION = "0.0.2"
|
8
8
|
|
9
9
|
task :default => [:test]
|
10
10
|
|
@@ -22,7 +22,7 @@ Rake::RDocTask.new do |rdoc|
|
|
22
22
|
"COPYING",
|
23
23
|
"LICENSE",
|
24
24
|
"HACKING", "lib/" )
|
25
|
-
rdoc.main = "README
|
25
|
+
rdoc.main = "README"
|
26
26
|
rdoc.rdoc_dir = "doc/html"
|
27
27
|
rdoc.title = "Gpgr Documentation"
|
28
28
|
end
|
data/lib/gpgr.rb
CHANGED
@@ -46,6 +46,8 @@ module Gpgr
|
|
46
46
|
GpgFileForEncryption.new(path, default_options[:to])
|
47
47
|
end
|
48
48
|
|
49
|
+
class InvalidEmailException < Exception; end
|
50
|
+
|
49
51
|
class GpgFileForEncryption
|
50
52
|
|
51
53
|
attr_accessor :email_addresses, :file, :file_output
|
@@ -87,10 +89,11 @@ module Gpgr
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
if bad_key
|
90
|
-
raise "One or more of the e-mail addresses you supplied don't have valid keys assigned!"
|
92
|
+
raise InvalidEmailException.new("One or more of the e-mail addresses you supplied don't have valid keys assigned!")
|
93
|
+
else
|
94
|
+
command = Gpgr.command + " -q --no-verbose --yes -a -o #{@file_output} -r " + @email_addresses.join(' -r ') + " -e #{@file}"
|
95
|
+
system(command)
|
91
96
|
end
|
92
|
-
command = Gpgr.command + " --yes -a -o #{@file_output} -r " + @email_addresses.join(' -r ') + " -e #{@file}"
|
93
|
-
system(command)
|
94
97
|
end
|
95
98
|
|
96
99
|
end
|
@@ -108,7 +111,7 @@ module Gpgr
|
|
108
111
|
# and added to the keyring for the user executing this command.
|
109
112
|
#
|
110
113
|
def self.import(path_to_key)
|
111
|
-
system "#{Gpgr.command} --yes --import #{File.expand_path(path_to_key)}"
|
114
|
+
system "#{Gpgr.command} -q --no-verbose --yes --import #{File.expand_path(path_to_key)}"
|
112
115
|
end
|
113
116
|
|
114
117
|
# Iterates through all of the files at a specified path and attempts to import
|
@@ -127,9 +130,21 @@ module Gpgr
|
|
127
130
|
#
|
128
131
|
def self.installed_public_keys
|
129
132
|
keys = []
|
130
|
-
|
131
|
-
|
133
|
+
email_regexp = /\<(.*@.*)\>/
|
134
|
+
|
135
|
+
# Select the output to grep for, which is different depending on the version
|
136
|
+
# of GPG installed. This is tested on 1.4 and 2.1.
|
137
|
+
#
|
138
|
+
if `#{Gpgr.command} --version | grep GnuPG`.include?('1.')
|
139
|
+
grep_for = 'pub'
|
140
|
+
else
|
141
|
+
grep_for = 'uid'
|
132
142
|
end
|
143
|
+
|
144
|
+
`#{Gpgr.command} --list-public-keys --with-colons | grep #{grep_for}`.split("\n").each do |key|
|
145
|
+
keys << email_regexp.match(key)[1].upcase
|
146
|
+
end
|
147
|
+
|
133
148
|
keys.uniq
|
134
149
|
end
|
135
150
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestFileEncryptionFunctionality < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_file_method_returns_expected_object
|
6
|
+
o = Gpgr::Encrypt.file(__FILE__)
|
7
|
+
assert_equal Gpgr::Encrypt::GpgFileForEncryption, o.class
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_default_values_are_corrently_set
|
11
|
+
o = Gpgr::Encrypt.file(__FILE__)
|
12
|
+
assert_equal File.expand_path(__FILE__), o.file
|
13
|
+
assert_equal File.expand_path(__FILE__) + '.pgp', o.file_output
|
14
|
+
assert o.email_addresses.empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_can_set_output_file_path
|
18
|
+
o = Gpgr::Encrypt.file(__FILE__ , :to => '/tmp/boogaboog.gpg')
|
19
|
+
assert_equal File.expand_path(__FILE__), o.file
|
20
|
+
assert_equal '/tmp/boogaboog.gpg', o.file_output
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_using_updates_email_addresses
|
24
|
+
o = Gpgr::Encrypt.file(__FILE__)
|
25
|
+
assert o.email_addresses.empty?
|
26
|
+
o.using [ 'test@test.com' ]
|
27
|
+
assert !o.email_addresses.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_encrypt_will_not_work_with_a_bad_email
|
31
|
+
o = Gpgr::Encrypt.file(__FILE__)
|
32
|
+
o.using [ 'nobody@example.com' ]
|
33
|
+
assert_raise Gpgr::Encrypt::InvalidEmailException do
|
34
|
+
o.encrypt
|
35
|
+
end
|
36
|
+
assert !File.exists(o.file_output)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -29,7 +29,7 @@ Passphrase: abc
|
|
29
29
|
%secring #{file_path}.sec
|
30
30
|
%commit
|
31
31
|
PGP
|
32
|
-
`echo '#{params}' | gpg --batch --gen-key -a`
|
32
|
+
`echo '#{params}' | gpg -q --no-verbose --batch --gen-key -a`
|
33
33
|
if File.exists?(file_path + '.pub')
|
34
34
|
return file_path + '.pub'
|
35
35
|
else
|
@@ -38,11 +38,11 @@ Passphrase: abc
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def remove_installed_key(email)
|
41
|
-
system "gpg --delete-key --yes --batch #{email}"
|
41
|
+
system "gpg -q --no-verbose --delete-key --yes --batch #{email}"
|
42
42
|
end
|
43
43
|
|
44
44
|
def cleanup_batch_keys
|
45
45
|
remove_installed_key 'testymctest1@example.com'
|
46
46
|
remove_installed_key 'testymctest2@example.com'
|
47
47
|
remove_installed_key 'testymctest3@example.com'
|
48
|
-
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gpgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 0.0.1
|
4
|
+
version: 0.0.2
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Ryan Stenhouse
|
@@ -14,7 +9,7 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-18 00:00:00 +00:00
|
18
13
|
default_executable:
|
19
14
|
dependencies: []
|
20
15
|
|
@@ -31,16 +26,16 @@ extra_rdoc_files:
|
|
31
26
|
- COPYING
|
32
27
|
files:
|
33
28
|
- lib/gpgr.rb
|
34
|
-
- test/
|
35
|
-
- test/test_helper.rb
|
36
|
-
- test/test_key_management_functionality.rb
|
29
|
+
- test/test_keys/testing_1268859031.pub
|
37
30
|
- test/test_keys/testing_1268859016.pub
|
38
31
|
- test/test_keys/testing_1268859023.pub
|
39
|
-
- test/
|
32
|
+
- test/test_key_management_functionality.rb
|
33
|
+
- test/test_file_encryption_functionality.rb
|
40
34
|
- test/test_keys_with_non_key_files/test.csv
|
35
|
+
- test/test_keys_with_non_key_files/testing_1268859031.pub
|
41
36
|
- test/test_keys_with_non_key_files/testing_1268859016.pub
|
42
37
|
- test/test_keys_with_non_key_files/testing_1268859023.pub
|
43
|
-
- test/
|
38
|
+
- test/test_helper.rb
|
44
39
|
- Rakefile
|
45
40
|
- HACKING
|
46
41
|
- README.markdown
|
@@ -63,20 +58,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
58
|
requirements:
|
64
59
|
- - ">="
|
65
60
|
- !ruby/object:Gem::Version
|
66
|
-
segments:
|
67
|
-
- 0
|
68
61
|
version: "0"
|
62
|
+
version:
|
69
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
64
|
requirements:
|
71
65
|
- - ">="
|
72
66
|
- !ruby/object:Gem::Version
|
73
|
-
segments:
|
74
|
-
- 0
|
75
67
|
version: "0"
|
68
|
+
version:
|
76
69
|
requirements: []
|
77
70
|
|
78
71
|
rubyforge_project: gpgr
|
79
|
-
rubygems_version: 1.3.
|
72
|
+
rubygems_version: 1.3.5
|
80
73
|
signing_key:
|
81
74
|
specification_version: 3
|
82
75
|
summary: A lightweight GPG CLI interface for encyrypting files
|
data/test/generate_keys.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
path = File.expand_path(File.dirname(__FILE__) + '/test_keys')
|
2
|
-
|
3
|
-
|
4
|
-
def generate_key(name, email, start_path)
|
5
|
-
file_path = "#{start_path}/testing_#{Time.now.to_i}"
|
6
|
-
params = <<-PGP
|
7
|
-
Key-Type: DSA
|
8
|
-
Key-Length: 1024
|
9
|
-
Subkey-Type: ELG-E
|
10
|
-
Subkey-Length: 1024
|
11
|
-
Name-Real: #{name}
|
12
|
-
Name-Comment: with stupid passphrase
|
13
|
-
Name-Email: #{email}
|
14
|
-
Expire-Date: 0
|
15
|
-
Passphrase: abc
|
16
|
-
%pubring #{file_path}.pub
|
17
|
-
%secring #{file_path}.sec
|
18
|
-
%commit
|
19
|
-
PGP
|
20
|
-
`echo '#{params}' | gpg --batch --gen-key -a`
|
21
|
-
if File.exists?(file_path + '.pub')
|
22
|
-
return file_path + '.pub'
|
23
|
-
else
|
24
|
-
raise "ARRGH"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
generate_key('TestyMcTest1', 'testymctest1@example.com', path)
|
30
|
-
generate_key('TestyMcTest2', 'testymctest2@example.com', path)
|
31
|
-
generate_key('TestyMcTest3', 'testymctest3@example.com', path)
|