GPGME::Ctx#generate_key fixed and with tests

This commit is contained in:
Albert Llop 2011-04-23 21:43:56 +02:00
Родитель c170dcd9aa
Коммит cb87d30678
2 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -270,7 +270,7 @@ module GPGME
#
# If +pubkey+ and +seckey+ are both set to +nil+, it stores the generated
# key pair into your key ring.
def generate_key(parms, pubkey = Data.new, seckey = Data.new)
def generate_key(parms, pubkey = nil, seckey = nil)
err = GPGME::gpgme_op_genkey(self, parms, pubkey, seckey)
exc = GPGME::error_to_exception(err)
raise exc if exc

Просмотреть файл

@ -198,6 +198,33 @@ describe GPGME::Ctx do
end
end
describe "key generation" do
it "generates a key according to specifications" do
key = <<-RUBY
<GnupgKeyParms format="internal">
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: Key Tester
Name-Comment: with some comments
Name-Email: test_generation@example.com
Expire-Date: 0
Passphrase: wadus
</GnupgKeyParms>
RUBY
keys_amount = GPGME::Key.find(:public).size
GPGME::Ctx.new do |ctx|
ctx.generate_key(key.chomp)
end
assert_equal keys_amount + 1, GPGME::Key.find(:public).size
GPGME::Key.find(:public, "test_generation@example.com").each do |k|
k.delete!(true)
end
end
end
end