gpgme 2.0.18 → 2.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: a49b16c07c13ffabf1863cda30eaedde8a0f20c7d4d43b0a720d2a1c4a5b0e5e
4
- data.tar.gz: 8b6b8eadee6e26459aea02072630407a61c2115a23b12f093404f674f2804c7c
2
+ SHA1:
3
+ metadata.gz: 85da3b0448319c6fd01c1004e64b2dc9956bc162
4
+ data.tar.gz: 843c3a9d2d6dc2c22e88c97fda497c36fc107f9e
5
5
  SHA512:
6
- metadata.gz: 02c849c3ff6422f5d83aa9ceec3c18e588fbff50f3fb58ed77524aacd563a3d9b8d6d6772723bdc213eb2af38fe5f341ff8177521e7575f3c9285e580e866f8c
7
- data.tar.gz: 384b74ba60aee10134d4dada885cb34b1c4b509026b8fb6e77f2e7bf5b06bd982797f123670780e2cf2ac933158d4cb442ffe704d84d2796e1ba42a13705b92b
6
+ metadata.gz: 8c7e91e339472d57de455c3e3f38fc37f7fcdfaf0cd003053eca160f48e4c459ddfa09c4d559fa6aaaef2596da5be450114986539ea6168a25802c852bd95065
7
+ data.tar.gz: dc5de7e968adea666fc353be5e7368b7087fbccc4d301fb07aacba0d22ba309cb5256269118c69b8565bd721c872fdf89cf217c988f523dcbf7919b445d3c7e0
@@ -370,8 +370,8 @@ module GPGME
370
370
  #
371
371
  # If passed, the key will be exported to +keydata+, which must be
372
372
  # a {GPGME::Data} object.
373
- def export_keys(recipients, keydata = Data.new)
374
- err = GPGME::gpgme_op_export(self, recipients, 0, keydata)
373
+ def export_keys(recipients, keydata = Data.new, mode=0)
374
+ err = GPGME::gpgme_op_export(self, recipients, mode, keydata)
375
375
  exc = GPGME::error_to_exception(err)
376
376
  raise exc if exc
377
377
  keydata
@@ -165,8 +165,16 @@ module GPGME
165
165
  end
166
166
 
167
167
  ##
168
- # Sets the encoding for this buffer. Accepts only values in one of the
169
- # DATA_ENCODING_* constants.
168
+ # Sets the encoding for this buffer. Accepts only integer values 0 to 7:
169
+ #
170
+ # 0 = GPGME_DATA_ENCODING_NONE (Not specified)
171
+ # 1 = GPGME_DATA_ENCODING_BINARY
172
+ # 2 = GPGME_DATA_ENCODING_BASE64
173
+ # 3 = GPGME_DATA_ENCODING_ARMOR (Either PEM or OpenPGP Armor)
174
+ # 4 = GPGME_DATA_ENCODING_URL (LF delimited URL list)
175
+ # 5 = GPGME_DATA_ENCODING_URLESC (Ditto, but percent escaped)
176
+ # 6 = GPGME_DATA_ENCODING_URL0 (Nul delimited URL list)
177
+ # 7 = GPGME_DATA_ENCODING_MIME (Data is a MIME part)
170
178
  #
171
179
  # @raise [GPGME::Error::InvalidValue] if the value isn't accepted.
172
180
  def encoding=(encoding)
@@ -81,6 +81,7 @@ module GPGME
81
81
  # @param [Hash] options
82
82
  # * +:output+ specify where to write the key to. It will be converted to
83
83
  # a {GPGME::Data}, so it could be a file, for example.
84
+ # * +:minimal+ set to true to let the export mode be 'minimal'.
84
85
  # * Any other option accepted by {GPGME::Ctx.new}
85
86
  #
86
87
  # @return [GPGME::Data] the exported key.
@@ -94,9 +95,14 @@ module GPGME
94
95
  #
95
96
  def export(pattern, options = {})
96
97
  output = Data.new(options[:output])
98
+ if options.delete(:minimal) == true
99
+ export_mode = 4
100
+ else
101
+ export_mode = 0
102
+ end
97
103
 
98
104
  GPGME::Ctx.new(options) do |ctx|
99
- ctx.export_keys(pattern, output)
105
+ ctx.export_keys(pattern, output, export_mode)
100
106
  end
101
107
 
102
108
  output.seek(0)
@@ -122,6 +128,12 @@ module GPGME
122
128
  ctx.import_result
123
129
  end
124
130
  end
131
+
132
+ # Checks if a key is valid
133
+ def valid?(key)
134
+ GPGME::Key.import(key).considered == 1
135
+ end
136
+
125
137
  end
126
138
 
127
139
  ##
@@ -1,4 +1,4 @@
1
1
  module GPGME
2
2
  # The version of GPGME ruby binding you are using
3
- VERSION = "2.0.18"
3
+ VERSION = "2.0.19"
4
4
  end
@@ -128,6 +128,11 @@ describe GPGME::Crypto do
128
128
  end
129
129
 
130
130
  describe "symmetric encryption/decryption" do
131
+ before do
132
+ info = GPGME::Engine.info.first
133
+ skip if /\A2\.[01]|\A1\./ === info.version
134
+ end
135
+
131
136
  it "requires a password to encrypt" do
132
137
  assert_raises GPGME::Error::BadPassphrase do
133
138
  GPGME::Crypto.new.encrypt TEXT[:plain], :symmetric => true
@@ -27,6 +27,11 @@ describe GPGME::Ctx do
27
27
  end
28
28
 
29
29
  describe :new do
30
+ before do
31
+ info = GPGME::Engine.info.first
32
+ skip if /\A2\.[01]|\A1\./ === info.version
33
+ end
34
+
30
35
  # We consider :armor, :protocol, :textmode and :keylist_mode as tested
31
36
  # with the other tests of this file. Here we test the rest
32
37
 
@@ -399,6 +404,26 @@ RUBY
399
404
  import_keys # If the test fails for some reason, it won't break others.
400
405
  end
401
406
 
407
+ it "exports a minimal key if given the mode" do
408
+ remove_all_keys
409
+ GPGME::Key.import(KEY_WITH_SIGNATURE[:public])
410
+ key = GPGME::Key.find(KEY_WITH_SIGNATURE[:sha]).first
411
+ output_normal = GPGME::Data.new
412
+ output_minimal = GPGME::Data.new
413
+ ctx = GPGME::Ctx.new
414
+
415
+ ctx.export_keys(key.sha, output_normal)
416
+ ctx.export_keys(key.sha, output_minimal, 4)
417
+
418
+ output_normal.seek(0)
419
+ output_minimal.seek(0)
420
+
421
+ assert_equal output_normal.read.size, 849
422
+ assert_equal output_minimal.read.size, 668
423
+
424
+ import_keys # If the test fails for some reason, it won't break others.
425
+ end
426
+
402
427
  it "exports only one key" do
403
428
  original_keys = GPGME::Key.find(:public)
404
429
  key = original_keys.first
@@ -0,0 +1,52 @@
1
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
2
+ Version: GnuPG v1.4.11 (Darwin)
3
+
4
+ QmSuBE1tOWYRDAC0MiL/mUsW1I18H9TZzurEXM0HMxFcQ5LlGm+0Zk+tSI/AVk4G
5
+ mZRppURYAFPyOQLOT6sm4vPXJ29uRJ8WSHtryg1Hq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l6CiXRRf9EDcu
37
+ QmPUs4IXZJDsWC4mS5T9PHgyHRP5geml6IAtN2627eaKDPx5VeC8DSG/6oMrFzNB
38
+ VxCd5t3Exzi+3ZOOTJnECMABZc6lK7rIOiQHHLW6vHIy5MggT/Dz6NuQuT9ID2uO
39
+ wzx6w9XMdRXJ0uuEJlhTZtcjlKu+B8i9hHgj1zqNT67Zkkz0/YTVHtNYDpOzjc7A
40
+ c+m/Qok/ERUjVcYS6dIJnJU+3V4L5APTAAMFC/sHCYUR5oa/uCktq//r09xRc/bu
41
+ 4uuzNJvsLzHcUA4udFSq2AneqrH/HCkrE0G4U79GMVpSddb+IamNWgJwfk4YHfNV
42
+ Vx2NhAWoCAIve0q+ueXGTGKkHyb0QobT/AmM/4Mtuln7cUfrkEmI8N8YIwPDqCGz
43
+ rWxvoPaOSUSxNfkyrV6IX8vjotx3NKm9n/6f5l/ncDrNSNruSywMq0fiLYS1+bCb
44
+ jsrTfWJKcM284ZwazKgcuhcCkXombkNQtQv7uD8FveWNVhC+LXtsyLGrzFNJVbNr
45
+ khKYfUFyoMY50PdvF4Ai1uJ0IYXQvIPnHbxPXMWa5PezrTWzlIXaVvVfgypC/tCY
46
+ p1QgiS+ln60NoK1m2ZFrUO3rklM44L1BNO9qjrUjYFVlmRd+qEBoXWGJLFp1g7Nh
47
+ 1mijiKdrwmCzWsnRSmPRYtOujeojP8bH4ca9RekwqLbRVeX/dLi02GD0pOp6SI6B
48
+ Bk3J0Wzp2Ko47Vj8v03hdBozKZT93a4NeyrNZdiIYQQYEQgACQUCTW05ZgIbDAAK
49
+ CRDLUpBCN9v3ISGmAP0VXwY7BH81NRpwAYp/eeSGP1vxBCdqVAHMc4o3TUoWHAEA
50
+ vioivJ/Qvnb7nlHwagl5rLNXhiz/H71jmFS9x0x7FLg=
51
+ =T/Ce
52
+ -----END PGP PUBLIC KEY BLOCK-----
@@ -66,13 +66,13 @@ describe GPGME::Key do
66
66
  # Testing the lazy way with expectations. I think tests in
67
67
  # the Ctx class are enough.
68
68
  it "exports any key that matches the pattern" do
69
- GPGME::Ctx.any_instance.expects(:export_keys).with("", anything)
69
+ GPGME::Ctx.any_instance.expects(:export_keys).with("", anything, 0)
70
70
  GPGME::Key.export("")
71
71
  end
72
72
 
73
73
  it "exports any key that matches the pattern, can specify output" do
74
74
  data = GPGME::Data.new
75
- GPGME::Ctx.any_instance.expects(:export_keys).with("wadus", data)
75
+ GPGME::Ctx.any_instance.expects(:export_keys).with("wadus", data, 0)
76
76
  ret = GPGME::Key.export("wadus", :output => data)
77
77
  assert_equal data, ret
78
78
  end
@@ -81,6 +81,11 @@ describe GPGME::Key do
81
81
  GPGME::Ctx.expects(:new).with(:armor => true).yields(mock(:export_keys => true))
82
82
  GPGME::Key.export("wadus", :armor => true)
83
83
  end
84
+
85
+ it "can export a minimal key" do
86
+ GPGME::Ctx.any_instance.expects(:export_keys).with("wadus", anything, 4)
87
+ GPGME::Key.export("wadus", :minimal => true)
88
+ end
84
89
  end
85
90
 
86
91
  describe "#export" do
@@ -180,7 +185,7 @@ describe GPGME::Key do
180
185
 
181
186
  with_key EXPIRED_KEY do
182
187
  key = GPGME::Key.find(:secret, EXPIRED_KEY[:sha]).first
183
- assert key.expired
188
+ assert key.expired if key
184
189
  end
185
190
  end
186
191
 
@@ -199,6 +204,18 @@ describe GPGME::Key do
199
204
  end
200
205
  end
201
206
 
207
+ describe :valid? do
208
+ it "returns true on a valid key" do
209
+ valid_key = File.read("test/files/testkey_pub.gpg")
210
+ assert GPGME::Key.valid?(valid_key)
211
+ end
212
+
213
+ it "returns false on an invalid key" do
214
+ invalid_key = File.read("test/files/testkey_pub_invalid.gpg")
215
+ assert !GPGME::Key.valid?(invalid_key)
216
+ end
217
+ end
218
+
202
219
  describe :to_s do
203
220
  it "can be coerced into a String" do
204
221
  key = GPGME::Key.find(:secret).first
@@ -206,4 +223,3 @@ describe GPGME::Key do
206
223
  end
207
224
  end
208
225
  end
209
-
@@ -0,0 +1,22 @@
1
+ #! /bin/bash
2
+ # Dummy pinentry
3
+ #
4
+ # Copyright 2008 g10 Code GmbH
5
+ #
6
+ # This file is free software; as a special exception the author gives
7
+ # unlimited permission to copy and/or distribute it, with or without
8
+ # modifications, as long as this notice is preserved.
9
+ #
10
+ # This file is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
12
+ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ # PURPOSE.
14
+
15
+ echo OK Your orders please
16
+
17
+ while read cmd; do
18
+ case $cmd in
19
+ GETPIN) echo D gpgme; echo OK;;
20
+ *) echo OK;;
21
+ esac
22
+ done
@@ -26,8 +26,11 @@ describe GPGME::SubKey do
26
26
  refute subkey.expired
27
27
 
28
28
  with_key EXPIRED_KEY do
29
- subkey = GPGME::Key.find(:secret, EXPIRED_KEY[:sha]).first.primary_subkey
30
- assert subkey.expired
29
+ key = GPGME::Key.find(:secret, EXPIRED_KEY[:sha]).first
30
+ if key
31
+ subkey = key.primary_subkey
32
+ assert subkey.expired
33
+ end
31
34
  end
32
35
  end
33
36
 
@@ -386,6 +386,31 @@ HyEbgNA=
386
386
  -----END PGP PRIVATE KEY BLOCK-----
387
387
  RUBY
388
388
 
389
+ key_with_signature = <<-RUBY
390
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
391
+
392
+ mI0ETbL4sAEEANBs/WsOxRCLdsW1h8LKGT6eJpAs6omGV/G7TJnMsk92BUIub3oZ
393
+ 9oRC1L0l4EKB6o8/vULziT815dbbVxwQIOyDXEqP4sokRxjSNNkpPb+RuIjdmP6e
394
+ SJ2NxCxV/GxLhjZZTHG5SPH4Gei3TtdiHMHoar0rwEcVdS693K/6Ww8ZABEBAAG0
395
+ IVRlc3QgbnVtYmVyIDEgPHRlc3QxQGV4YW1wbGUuY29tPoi4BBMBAgAiBQJNsviw
396
+ AhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRD7yLd2W11cdyxOA/4gPEK1
397
+ qF8bp0YJfc91Ob/J70N5gNuO06AeBa8o6MHTUheCp5CMFD8RISDegsiYey3O+Wvk
398
+ rg+BmIQWqGTglDIDOM8B1Bmc+T+C0sRwIwmHqDo5a9mR2QnlcFqZ3SNV5MdxDUa4
399
+ GJk4LbUj/JwU2nR8Z4eA7OC1LjOexFKAfLX654izBBABCAAdFiEEVsoxCW7JMuDZ
400
+ Ydv9OSviynfWZWYFAl1ziQcACgkQOSviynfWZWYScwP/a/shuIWvLCZLllW0YWy8
401
+ NUPgTZ4TnJogOp4zm9+uNla9GJepM1Wj7+m1ZNzXskqESoAB00k2dYOGwek0hPHp
402
+ 1MwpcMJvAu7m+LrfGVcG6IAkjQWvifsP8QIe05yNW3jsK+qQJpy1dejzgaHt7dLL
403
+ /rS6ySBxhIvpo5tsfe+C8PO4jQRNsviwAQQAvVKqiSoVA6oQ8nT3zLEGDgNeED3M
404
+ fHMeYbFMi7GTpvURsTXcPH0SLXzGVn8Aevaa+ConFWMQuWMsTPiqVQR6/kKE8RJ/
405
+ ynDHbnXuOGNdOBd96GdsIgqTMwrtWVvzhSKFrhDB1y8iFyQ9QlVTJG4jo8EcaN6L
406
+ T0hoo64XJktD5CUAEQEAAYifBBgBAgAJBQJNsviwAhsMAAoJEPvIt3ZbXVx3X/8E
407
+ AIiCsyWlIOUvhFN5a/V2TyA2XjXEKSn9iWi7uLhVT7ShrWSGGhdNBwiqJuDh5KxX
408
+ 3VXa9fePMXrfbALdj1fRqCAFfKZAcKrNNls+psSaYLJwLhCUzD8Ht9M+LrGeZDPz
409
+ wzAqTfgPb5M2Inssarr5Lpdlu1X8y37cfNVHscqBZyfS
410
+ =KOQt
411
+ -----END PGP PUBLIC KEY BLOCK-----
412
+ RUBY
413
+
389
414
  encrypted_text = <<-RUBY
390
415
  -----BEGIN PGP MESSAGE-----
391
416
  Version: GnuPG v1.4.11 (Darwin)
@@ -506,6 +531,11 @@ EXPIRED_KEY = {
506
531
  :secret => expired_key_secret
507
532
  }
508
533
 
534
+ KEY_WITH_SIGNATURE = {
535
+ :sha => 'test1@example.com',
536
+ :public => key_with_signature
537
+ }
538
+
509
539
  TEXT = {
510
540
  :plain => "Hi there",
511
541
  :encrypted => encrypted_text.chomp,
@@ -99,11 +99,17 @@ def ensure_keys(proto)
99
99
  # We use a different home directory for the keys to not disturb current
100
100
  # installation
101
101
  require 'tmpdir'
102
+ require 'pathname'
102
103
 
103
104
  if DIRS.empty?
104
105
  dir = Dir.mktmpdir
105
106
  GPGME::Engine.home_dir = dir
106
107
  DIRS.push(dir)
108
+ pinentry = Pathname.new(__FILE__).dirname + 'pinentry'
109
+ gpg_agent_conf = Pathname.new(dir) + 'gpg-agent.conf'
110
+ gpg_agent_conf.open('w+') {|io|
111
+ io.write("pinentry-program #{pinentry}\n")
112
+ }
107
113
  remove_all_keys
108
114
  import_keys
109
115
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpgme
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.18
4
+ version: 2.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daiki Ueno
@@ -141,9 +141,11 @@ files:
141
141
  - test/ctx_test.rb
142
142
  - test/data_test.rb
143
143
  - test/files/testkey_pub.gpg
144
+ - test/files/testkey_pub_invalid.gpg
144
145
  - test/files/testkey_sec.gpg
145
146
  - test/gpgme_test.rb
146
147
  - test/key_test.rb
148
+ - test/pinentry
147
149
  - test/signature_test.rb
148
150
  - test/sub_key_test.rb
149
151
  - test/support/resources.rb
@@ -169,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
171
  version: '0'
170
172
  requirements: []
171
173
  rubyforge_project: ruby-gpgme
172
- rubygems_version: 2.7.3
174
+ rubygems_version: 2.6.14.3
173
175
  signing_key:
174
176
  specification_version: 4
175
177
  summary: Ruby binding of GPGME.