Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bb638cc
Showing
10 changed files
with
3,042 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'mkmf' | ||
|
||
if have_library('gpgme', 'gpgme_check_version') and have_header('gpgme.h') | ||
create_makefile ('gpgme_n') | ||
end |
Oops, something went wrong.