Skip to content

Commit

Permalink
Merge a236895 into e84f42e
Browse files Browse the repository at this point in the history
  • Loading branch information
duckdalbe committed Sep 7, 2019
2 parents e84f42e + a236895 commit a485a3e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/gpgme/ctx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ def generate_key(parms, pubkey = nil, seckey = nil)
#
# If passed, the key will be exported to +keydata+, which must be
# a {GPGME::Data} object.
def export_keys(recipients, keydata = Data.new)
err = GPGME::gpgme_op_export(self, recipients, 0, keydata)
def export_keys(recipients, keydata = Data.new, mode=0)
err = GPGME::gpgme_op_export(self, recipients, mode, keydata)
exc = GPGME::error_to_exception(err)
raise exc if exc
keydata
Expand Down
8 changes: 7 additions & 1 deletion lib/gpgme/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def get(fingerprint)
# @param [Hash] options
# * +:output+ specify where to write the key to. It will be converted to
# a {GPGME::Data}, so it could be a file, for example.
# * +:minimal+ set to true to let the export mode be 'minimal'.
# * Any other option accepted by {GPGME::Ctx.new}
#
# @return [GPGME::Data] the exported key.
Expand All @@ -94,9 +95,14 @@ def get(fingerprint)
#
def export(pattern, options = {})
output = Data.new(options[:output])
if options.delete(:minimal) == true
export_mode = 4
else
export_mode = 0
end

GPGME::Ctx.new(options) do |ctx|
ctx.export_keys(pattern, output)
ctx.export_keys(pattern, output, export_mode)
end

output.seek(0)
Expand Down
18 changes: 18 additions & 0 deletions test/ctx_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,24 @@ def checking_value(value,par2,par3,par4,fd)
import_keys # If the test fails for some reason, it won't break others.
end

it "exports a minimal key if given the mode" do
key = GPGME::Key.find(:public).first
output_normal = GPGME::Data.new
output_minimal = GPGME::Data.new
ctx = GPGME::Ctx.new

ctx.export_keys(key.sha, output_normal)
ctx.export_keys(key.sha, output_minimal, 4)

output_normal.seek(0)
output_minimal.seek(0)

assert_equal output_normal.read.size, 3000
assert_equal output_minimal.read.size, 2000

import_keys # If the test fails for some reason, it won't break others.
end

it "exports only one key" do
original_keys = GPGME::Key.find(:public)
key = original_keys.first
Expand Down

0 comments on commit a485a3e

Please sign in to comment.