ruby-gpgme/examples/genkey.rb

56 строки
1.3 KiB
Ruby
Исходник Обычный вид История

2006-10-14 01:03:49 +04:00
#!/usr/bin/env ruby
require 'gpgme'
# If you do not have gpg-agent installed, comment out the following
# and set it as :passphrase_callback.
#
# def passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd)
# $stderr.write("Passphrase for #{uid_hint}: ")
# $stderr.flush
# begin
# system('stty -echo')
# io = IO.for_fd(fd, 'w')
# io.puts(gets)
# io.flush
# ensure
# (0 ... $_.length).each do |i| $_[i] = ?0 end if $_
# system('stty echo')
# end
# $stderr.puts
# end
2006-10-14 01:03:49 +04:00
2006-10-20 10:02:46 +04:00
unless ENV['GPG_AGENT_INFO']
$stderr.puts("gpg-agent is not running. See the comment in #{$0}.")
exit(1)
end
2006-10-19 02:48:53 +04:00
unless ENV['GNUPGHOME']
2006-10-20 06:31:21 +04:00
$stderr.write('As GNUPGHOME is not set, the generated key pair will be stored into *your* keyring. Really proceed? (y/N) ')
2006-10-19 02:48:53 +04:00
$stderr.flush
2006-10-20 06:29:27 +04:00
exit(1) unless gets.chomp == 'y'
2006-10-19 02:48:53 +04:00
end
def progfunc(hook, what, type, current, total)
2006-10-17 14:59:56 +04:00
$stderr.write("#{what}: #{current}/#{total}\r")
$stderr.flush
end
ctx = GPGME::Ctx.new({:progress_callback => method(:progfunc),
# :passphrase_callback => method(:passfunc)
})
2006-10-17 14:59:56 +04:00
ctx.genkey(<<'EOF', nil, nil)
2006-10-14 01:03:49 +04:00
<GnupgKeyParms format="internal">
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: Joe Tester
Name-Comment: with stupid passphrase
Name-Email: joe@foo.bar
2006-10-17 14:59:56 +04:00
Expire-Date: 0
Passphrase: abc
2006-10-14 01:03:49 +04:00
</GnupgKeyParms>
EOF
2006-10-17 14:59:56 +04:00
$stderr.puts