gpgr 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,8 +83,8 @@ not be accepted - I'm happy to assume that it is.
83
83
 
84
84
  ##Status
85
85
 
86
- Functional if sparsely documented. Gem 0.0.1 has been cut.
86
+ Published as a gem, current version 0.0.4
87
87
 
88
88
  [1]: http://www.pccl.co.uk
89
89
  [2]: http://macgpg.sourceforge.net/
90
- [3]: http://sourceforge.net/projects/macgpg2/files/
90
+ [3]: http://sourceforge.net/projects/macgpg2/files/
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.3"
7
+ GPGR_VERSION = "0.0.4"
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 = "lib/gpgr.rb"
26
26
  rdoc.rdoc_dir = "doc/html"
27
27
  rdoc.title = "Gpgr Documentation"
28
28
  end
@@ -40,7 +40,7 @@ spec = Gem::Specification.new do |spec|
40
40
  spec.has_rdoc = true
41
41
  spec.extra_rdoc_files = %w{HACKING README.markdown LICENSE COPYING}
42
42
  spec.rdoc_options << '--title' << 'Gpgr Documentation' <<
43
- '--main' << 'README' << '-q'
43
+ '--main' << 'lib/gpgr.rb' << '-q'
44
44
  spec.author = "Ryan Stenhouse"
45
45
  spec.email = " ryan@ryanstenhouse.eu"
46
46
  spec.rubyforge_project = "gpgr"
@@ -13,9 +13,20 @@
13
13
  #
14
14
  # require 'rubygems'
15
15
  # require 'gpgr'
16
+ #
17
+ # # Synopsis
18
+ # #
16
19
  # list_of_keys = [ 'foo@example.com', 'bar@example.com' ]
17
20
  # Gpgr::Encrypt.file('/some_file.txt', :to => '/encrypted.gpg').encrypt_using(list_of_keys)
18
- #
21
+ #
22
+ # # To import all the public keys in a given directory
23
+ # #
24
+ # Gpgr::Keys.import_keys_at('/path/to/public/keys')
25
+ #
26
+ # # Will encrypt for every single person you have a public key for
27
+ # #
28
+ # Gpgr::Encrypt.file('/some_file.txt', :to => '/encrypted.gpg').encrypt_using(Gpgr::Keys.installed_public_keys)
29
+ #
19
30
  module Gpgr
20
31
 
21
32
  # Returns the command to execute to run GPG. It is defualted to /use/bin/env gpg
@@ -45,9 +56,19 @@ module Gpgr
45
56
  default_options = { :to => "#{path}.pgp" }.merge(options)
46
57
  GpgFileForEncryption.new(path, default_options[:to])
47
58
  end
48
-
59
+
60
+ # Raised if there is an invalid e-mail address provided to encrypt with
61
+ #
49
62
  class InvalidEmailException < Exception; end
50
63
 
64
+ # Raised if the input or output files for the GPG Encryption are invalid somehow
65
+ #
66
+ class InvalidFileException < Exception; end
67
+
68
+
69
+ # Contians the details used to encrypt specified +file+, is what actually does
70
+ # any encryption.
71
+ #
51
72
  class GpgFileForEncryption
52
73
 
53
74
  attr_accessor :email_addresses, :file, :file_output
@@ -83,6 +104,15 @@ module Gpgr
83
104
  #
84
105
  def encrypt
85
106
  bad_key = @email_addresses.empty?
107
+
108
+ if File.exists?(@file)
109
+ unless File.readable?(@file)
110
+ raise InvalidFileException.new("File at #{@file} is not readable.") and return
111
+ end
112
+ else
113
+ raise InvalidFileException.new("File at #{@file} does not exist.") and return
114
+ end
115
+
86
116
  @email_addresses.each do |add|
87
117
  unless Gpgr::Keys.public_key_installed?(add)
88
118
  bad_key = true
@@ -118,9 +148,8 @@ module Gpgr
118
148
  # those which are likely to be GPG / PGP Public Keys.
119
149
  #
120
150
  def self.import_keys_at(path)
121
- d = Dir.new(path)
122
- d.each do |file|
123
- puts file.inspect
151
+ Dir.new(path).each do |file|
152
+ next if ['..','.'].include?(file)
124
153
  Gpgr::Keys.import(path + '/' + file)
125
154
  end
126
155
  end
@@ -0,0 +1,31 @@
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)
@@ -0,0 +1,25 @@
1
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
2
+ Version: GnuPG v1.4.9 (GNU/Linux)
3
+
4
+ mQGiBEuiWdgRBACSK3Jckkap+7WT/UT90wF3Gwrn8MFfquOlVpPFdmcgOoHqJqe+
5
+ 7Ve6HuGD4DD7Pdtth51p/GjpiDUmLCtsWsmtyokNEcWt8qeAJSdwxs6vurmCETDv
6
+ iNeW5NEFedpDaT8VfLhZYOvL0w0yEiKgozANUw30FbqlONSDSV95XVIzwwCglhtj
7
+ m9yosv/1WSIhE7I/FqQIsZkD/jTZwhlf18N3rSAhPf3mdN3bDQwoQ3J4enRfiIYQ
8
+ HMkAsgQIolDnmB+OYJveJloOy64c3kW7tLy66k0qNsHALYyIm0fVagZ2c2QsjPfo
9
+ f/5AR7mOQH9tyGwimSA3imSbPHUry9J81tFYyAghSlpaFaSzXwaZeVQz9UkYua1v
10
+ C1O3A/wLCgdmSiZPmvUwGO6aRtOlCYkOF1ESFXHf0yrGalEG7z3HnTt5kquuxEqH
11
+ Ju4z5SaCVomj223CiDhoqhuKegv42v1OqSUy2n8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ZQt2WKHkZVXorMEUAKOSazQ6HIhJBBgRAgAJBQJLolnhAhsM
22
+ AAoJEIFnadPdcVVHY+cAoKSonlAWGbyxzypSFjQ97qYWGqhpAKCdtvWGFEajnFn1
23
+ Lmb/MRJBEeVVOQ==
24
+ =6klI
25
+ -----END PGP PUBLIC KEY BLOCK-----
@@ -33,7 +33,16 @@ class TestFileEncryptionFunctionality < Test::Unit::TestCase
33
33
  assert_raise Gpgr::Encrypt::InvalidEmailException do
34
34
  o.encrypt
35
35
  end
36
- assert !File.exists(o.file_output)
36
+ assert !File.exists?(o.file_output)
37
+ end
38
+
39
+ def test_encrypt_will_not_work_if_source_file_doesnt_exist
40
+ o = Gpgr::Encrypt.file('/tmp/i_just_made_this_up')
41
+ o.using [ 'nobody@example.com' ]
42
+ assert_raise Gpgr::Encrypt::InvalidFileException do
43
+ o.encrypt
44
+ end
45
+ assert !File.exists?(o.file_output)
37
46
  end
38
47
 
39
48
  end
@@ -8,35 +8,6 @@ GPGR_ROOT = File.expand_path(File.dirname(__FILE__) + '/../lib')
8
8
  #
9
9
  require GPGR_ROOT + '/gpgr.rb'
10
10
 
11
-
12
-
13
- # Helper methods for the tests.
14
- #
15
-
16
- def generate_key_for(email, name)
17
- file_path = "/tmp/gpgr_testing_#{Time.now.to_i}"
18
- params = <<-PGP
19
- Key-Type: DSA
20
- Key-Length: 1024
21
- Subkey-Type: ELG-E
22
- Subkey-Length: 1024
23
- Name-Real: #{name}
24
- Name-Comment: with stupid passphrase
25
- Name-Email: #{email}
26
- Expire-Date: 0
27
- Passphrase: abc
28
- %pubring #{file_path}.pub
29
- %secring #{file_path}.sec
30
- %commit
31
- PGP
32
- `echo '#{params}' | gpg -q --no-verbose --batch --gen-key -a`
33
- if File.exists?(file_path + '.pub')
34
- return file_path + '.pub'
35
- else
36
- raise "ARRGH"
37
- end
38
- end
39
-
40
11
  def remove_installed_key(email)
41
12
  system "gpg -q --no-verbose --delete-key --yes --batch #{email}"
42
13
  end
@@ -40,10 +40,8 @@ class TestKeyManagementFunctionality < Test::Unit::TestCase
40
40
  end
41
41
 
42
42
  def setup_for_key_tests
43
- puts "=>\tGenerating keys for test - please wait"
44
- @john_key = generate_key_for('john@example.com','John Test')
45
- @mark_key = generate_key_for('mark@example.com','Mark Test')
46
- puts "=>\tDone!"
43
+ @john_key = File.dirname(__FILE__) + '/john_and_marks_keys/john.pub'
44
+ @mark_key = File.dirname(__FILE__) + '/john_and_marks_keys/mark.pub'
47
45
  end
48
46
 
49
47
  def teardown_for_key_tests
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 4
9
+ version: 0.0.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Ryan Stenhouse
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-18 00:00:00 +00:00
17
+ date: 2010-03-19 00:00:00 +00:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -26,16 +31,19 @@ extra_rdoc_files:
26
31
  - COPYING
27
32
  files:
28
33
  - lib/gpgr.rb
29
- - test/test_keys/testing_1268859031.pub
34
+ - test/generate_keys.rb
35
+ - test/john_and_marks_keys/john.pub
36
+ - test/john_and_marks_keys/mark.pub
37
+ - test/test_file_encryption_functionality.rb
38
+ - test/test_helper.rb
39
+ - test/test_key_management_functionality.rb
30
40
  - test/test_keys/testing_1268859016.pub
31
41
  - test/test_keys/testing_1268859023.pub
32
- - test/test_key_management_functionality.rb
33
- - test/test_file_encryption_functionality.rb
42
+ - test/test_keys/testing_1268859031.pub
34
43
  - test/test_keys_with_non_key_files/test.csv
35
- - test/test_keys_with_non_key_files/testing_1268859031.pub
36
44
  - test/test_keys_with_non_key_files/testing_1268859016.pub
37
45
  - test/test_keys_with_non_key_files/testing_1268859023.pub
38
- - test/test_helper.rb
46
+ - test/test_keys_with_non_key_files/testing_1268859031.pub
39
47
  - Rakefile
40
48
  - HACKING
41
49
  - README.markdown
@@ -50,7 +58,7 @@ rdoc_options:
50
58
  - --title
51
59
  - Gpgr Documentation
52
60
  - --main
53
- - README
61
+ - lib/gpgr.rb
54
62
  - -q
55
63
  require_paths:
56
64
  - lib
@@ -58,18 +66,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
66
  requirements:
59
67
  - - ">="
60
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
61
71
  version: "0"
62
- version:
63
72
  required_rubygems_version: !ruby/object:Gem::Requirement
64
73
  requirements:
65
74
  - - ">="
66
75
  - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
67
78
  version: "0"
68
- version:
69
79
  requirements: []
70
80
 
71
81
  rubyforge_project: gpgr
72
- rubygems_version: 1.3.5
82
+ rubygems_version: 1.3.6
73
83
  signing_key:
74
84
  specification_version: 3
75
85
  summary: A lightweight GPG CLI interface for encyrypting files