Skip to content

Commit

Permalink
Rearrange the repository layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
ueno committed Oct 13, 2006
0 parents commit bb638cc
Show file tree
Hide file tree
Showing 10 changed files with 3,042 additions and 0 deletions.
340 changes: 340 additions & 0 deletions COPYING

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions MANIFEST
@@ -0,0 +1,8 @@
lib/gpgme.rb
COPYING
extconf.rb
gpgme_n.c
examples/genkey.rb
examples/keylist.rb
examples/roundtrip.rb
examples/sign.rb
42 changes: 42 additions & 0 deletions examples/genkey.rb
@@ -0,0 +1,42 @@
#!/usr/bin/env ruby
require 'gpgme'

ctx = GPGME::Ctx.new

passphrase_cb = proc {|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.chomp)
io.flush
ensure
system('stty echo')
end
puts
GPGME::GPG_ERR_NO_ERROR
}
ctx.set_passphrase_cb(passphrase_cb)

begin
pair = ctx.genkey(<<'EOF')
<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
Passphrase: abcdabcdfs
Expire-Date: 2010-08-15
</GnupgKeyParms>
EOF
rescue GPGME::Error => err
$stderr.puts(err.message)
exit!
end

puts("Pubkey:\n#{pair[0].read}")
puts("Seckey:\n#{pair[1].read}")
11 changes: 11 additions & 0 deletions examples/keylist.rb
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
require 'gpgme'

pat = ARGV.shift
ctx = GPGME::Ctx.new
ctx.each_keys(pat) do |key|
puts(key.subkeys[0].keyid)
key.uids.each do |user_id|
puts("\t#{user_id.name} <#{user_id.email}>")
end
end
26 changes: 26 additions & 0 deletions examples/roundtrip.rb
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby
require 'gpgme'

ctx = GPGME::Ctx.new
ctx.armor = true
passphrase_cb = proc {|hook, uid_hint, passphrase_info, prev_was_bad, fd|
io = IO.for_fd(fd, 'w')
io.puts('test')
io.flush
GPGME::GPG_ERR_NO_ERROR
}
ctx.set_passphrase_cb(passphrase_cb)

plain = GPGME::Data.new_from_mem('test test test')
puts("Plaintext:\n#{plain.read}")
plain.rewind

# Perform symmetric encryption on PLAIN.
cipher = ctx.encrypt(nil, plain)
cipher.rewind
puts("Ciphertext:\n#{cipher.read}")
cipher.rewind

plain = ctx.decrypt(cipher)
plain.rewind
puts("Plaintext:\n#{plain.read}")
26 changes: 26 additions & 0 deletions examples/sign.rb
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby
require 'gpgme'

ctx = GPGME::Ctx.new

passphrase_cb = proc {|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.chomp)
io.flush
ensure
system('stty echo')
end
puts
GPGME::GPG_ERR_NO_ERROR
}
ctx.set_passphrase_cb(passphrase_cb)

plain = GPGME::Data.new_from_mem('test test test')

signed = ctx.sign(plain, GPGME::GPGME_SIG_MODE_CLEAR)
signed.rewind
puts("#{signed.read}")
28 changes: 28 additions & 0 deletions examples/verify.rb
@@ -0,0 +1,28 @@
#!/usr/bin/env ruby
require 'gpgme'

include GPGME

ctx = GPGME::Ctx.new
sig = GPGME::Data.new_from_mem(ARGF.read)
ctx.verify(sig)
signatures = ctx.verify_result.signatures
signatures.each do |signature|
from_key = ctx.get_key(signature.fpr)
from = from_key ? "#{from_key.subkeys[0].keyid} #{from_key.uids[0].uid}" :
signature.fpr
case GPGME::gpgme_err_code(signature.status)
when GPGME::GPG_ERR_NO_ERROR
puts("Good signature from #{from}")
when GPGME::GPG_ERR_SIG_EXPIRED
puts("Expired signature from #{from}")
when GPGME::GPG_ERR_KEY_EXPIRED
puts("Signature made from expired key #{from}")
when GPGME::GPG_ERR_CERT_REVOKED
puts("Signature made from revoked key #{from}")
when GPGME::GPG_ERR_BAD_SIGNATURE
puts("Bad signature from #{from}")
when GPGME::GPG_ERR_NO_ERROR
puts("No public key for #{from}")
end
end
5 changes: 5 additions & 0 deletions extconf.rb
@@ -0,0 +1,5 @@
require 'mkmf'

if have_library('gpgme', 'gpgme_check_version') and have_header('gpgme.h')
create_makefile ('gpgme_n')
end

0 comments on commit bb638cc

Please sign in to comment.