Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rearrange the repository layout.

  • Loading branch information...
commit bb638cc363a07d1c9ab105f2bec051c82124353a 0 parents
@ueno authored
340 COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) 19yy <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19yy name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
8 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 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 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 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 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 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 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
2,055 gpgme_n.c
@@ -0,0 +1,2055 @@
+/* gpgme_n.c
+ Copyright (C) 2003,2006 Daiki Ueno
+
+This file is a part of Ruby-GPGME.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+/* This module provides low level interface to the GPGME library.
+ There is simple strategy for defining ruby API binding, though this
+ module was written entirely by hand.
+
+1. Each symbol exported from this module is one of a class, a module
+ function, and a constant. No instance methods are defined.
+2. Each symbol exported from this module follows the same naming
+ convention of the library API. That is, symbol names are followed
+ by `gpgme_' for functions and are followed by `GPGME_' for
+ constants.
+3. Output arguments should have to be wrapped. For example, the 4th
+ argument of `gpgme_data_read' has type `size_t *' to store the amount
+ read. The corresponding ruby interface accepts an empty array for
+ this purpose. */
+
+#include "ruby.h"
+#include "gpgme.h"
+
+/* StringValuePtr is not available in 1.6. */
+#ifndef StringValuePtr
+#define StringValuePtr(str) RSTRING(str)->ptr
+#endif
+
+/* STR2CSTR is obsoleted in 1.8. */
+#ifndef StringValueCStr
+#define StringValueCStr STR2CSTR
+#endif
+
+/* RARRAY_LEN is not available in 1.8. */
+#ifndef RARRAY_LEN
+#define RARRAY_LEN(a) RARRAY(a)->len
+#endif
+
+/* RARRAY_PTR is not available in 1.8. */
+#ifndef RARRAY_PTR
+#define RARRAY_PTR(a) RARRAY(a)->ptr
+#endif
+
+#define WRAP_GPGME_DATA(dh) \
+ Data_Wrap_Struct(cGpgmeData, 0, gpgme_data_release, dh) \
+/* `gpgme_data_t' is typedef'ed as `struct gpgme_data *'. */
+#define UNWRAP_GPGME_DATA(vdh, dh) \
+ Data_Get_Struct(vdh, struct gpgme_data, dh);
+
+#define WRAP_GPGME_CTX(ctx) \
+ Data_Wrap_Struct(cGpgmeCtx, 0, gpgme_release, ctx) \
+/* `gpgme_ctx_t' is typedef'ed as `struct gpgme_context *'. */
+#define UNWRAP_GPGME_CTX(vctx, ctx) \
+ Data_Get_Struct(vctx, struct gpgme_context, ctx)
+
+#define WRAP_GPGME_KEY(key) \
+ Data_Wrap_Struct(cGpgmeKey, 0, gpgme_key_release, key) \
+/* `gpgme_key_t' is typedef'ed as `struct _gpgme_key *'. */
+#define UNWRAP_GPGME_KEY(vkey, key) \
+ Data_Get_Struct(vkey, struct _gpgme_key, key)
+
+#define WRAP_GPGME_TRUST_ITEM(item) \
+ Data_Wrap_Struct(cGpgmeTrustItem, 0, gpgme_trust_item_release, item) \
+/* `gpgme_trust_item_t' is typedef'ed as `struct _gpgme_trust_item *'. */
+#define UNWRAP_GPGME_TRUST_ITEM(vitem, item) \
+ Data_Get_Struct(vitem, struct _gpgme_trust_item, item)
+
+static VALUE cGpgmeEngineInfo,
+ cGpgmeCtx,
+ cGpgmeData,
+ cGpgmeKey,
+ cGpgmeSubKey,
+ cGpgmeUserId,
+ cGpgmeKeySig,
+ cGpgmeVerifyResult,
+ cGpgmeSignature,
+ cGpgmeSigNotation,
+ cGpgmeTrustItem;
+
+static VALUE
+rb_s_gpgme_check_version (dummy, vreq)
+ VALUE dummy, vreq;
+{
+ const char *result = gpgme_check_version (NIL_P(vreq) ? NULL :
+ StringValueCStr(vreq));
+ return result ? rb_str_new2 (result) : Qnil;
+}
+
+static VALUE
+rb_s_gpgme_engine_check_version (dummy, vproto)
+ VALUE dummy, vproto;
+{
+ gpgme_error_t err = gpgme_engine_check_version (NUM2INT(vproto));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_get_engine_info (dummy, rinfo)
+ VALUE dummy, rinfo;
+{
+ gpgme_engine_info_t info;
+ gpgme_error_t err;
+
+ err = gpgme_get_engine_info (&info);
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ {
+ for (; info; info = info->next)
+ {
+ VALUE vinfo = rb_class_new_instance (0, NULL, cGpgmeEngineInfo);
+ rb_iv_set (vinfo, "@protocol", INT2FIX(info->protocol));
+ if (info->file_name)
+ rb_iv_set (vinfo, "@file_name", rb_str_new2 (info->file_name));
+ if (info->version)
+ rb_iv_set (vinfo, "@version", rb_str_new2 (info->version));
+ if (info->req_version)
+ rb_iv_set (vinfo, "@req_version", rb_str_new2 (info->req_version));
+ rb_ary_push (rinfo, vinfo);
+ }
+ }
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_err_code (dummy, verr)
+ VALUE dummy, verr;
+{
+ return INT2FIX(gpgme_err_code (NUM2LONG(verr)));
+}
+
+static VALUE
+rb_s_gpgme_err_source (dummy, verr)
+ VALUE dummy, verr;
+{
+ return INT2FIX(gpgme_err_source (NUM2LONG(verr)));
+}
+
+static VALUE
+rb_s_gpgme_strerror (dummy, verr)
+ VALUE dummy, verr;
+{
+ return rb_str_new2 (gpgme_strerror (NUM2LONG(verr)));
+}
+
+static VALUE
+rb_s_gpgme_data_new (dummy, rdh)
+ VALUE dummy, rdh;
+{
+ gpgme_data_t dh;
+ gpgme_error_t err = gpgme_data_new (&dh);
+
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ rb_ary_push (rdh, WRAP_GPGME_DATA(dh));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_data_new_from_mem (dummy, rdh, vbuffer, vsize, vcopy)
+ VALUE dummy, rdh, vbuffer, vsize, vcopy;
+{
+ gpgme_data_t dh;
+ VALUE vdh;
+ size_t size = NUM2UINT(vsize);
+ gpgme_error_t err;
+
+ if (RSTRING(vbuffer)->len < size)
+ rb_raise (rb_eArgError, "argument out of range");
+
+ rb_str_modify (vbuffer);
+ err = gpgme_data_new_from_mem (&dh, StringValuePtr(vbuffer), size,
+ NUM2INT(vcopy));
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ {
+ vdh = WRAP_GPGME_DATA(dh);
+ /* Keep a references to VBUFFER to avoid GC. */
+ rb_iv_set (vdh, "@buffer", vbuffer);
+ rb_ary_push (rdh, vdh);
+ }
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_data_new_from_file (dummy, rdh, vfilename, vcopy)
+ VALUE dummy, rdh, vfilename, vcopy;
+{
+ gpgme_data_t dh;
+ gpgme_error_t err = gpgme_data_new_from_file (&dh,
+ StringValueCStr(vfilename),
+ NUM2INT(vcopy));
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ rb_ary_push (rdh, WRAP_GPGME_DATA(dh));
+ return LONG2NUM(err);
+}
+
+static int
+read_cb (hook, buffer, count, nread)
+ void *hook;
+ char *buffer;
+ size_t count, *nread;
+{
+ VALUE vcb = (VALUE)hook, vreadfunc, vhook_value, vbuffer, rnread;
+
+ vreadfunc = RARRAY(vcb)->ptr[0];
+ vhook_value = RARRAY(vcb)->ptr[1];
+ vbuffer = rb_str_new (buffer, count);
+ rnread = rb_ary_new ();
+
+ rb_funcall (vreadfunc, rb_intern ("call"), 4,
+ vhook_value, vbuffer, INT2NUM(count), rnread);
+ if (RARRAY(rnread)->len < 1)
+ rb_raise (rb_eRuntimeError,
+ "can't determine the number of bytes actually read");
+ *nread = RARRAY(rnread)->ptr[0];
+ memcpy (buffer, StringValuePtr(vbuffer), *nread);
+ return *nread;
+}
+
+static VALUE
+rb_s_gpgme_data_new_with_read_cb (dummy, rdh, vreadfunc, vhook_value)
+ VALUE dummy, rdh, vreadfunc, vhook_value;
+{
+ gpgme_data_t dh;
+ VALUE vdh, vcb = rb_ary_new ();
+ gpgme_error_t err;
+
+ rb_ary_push (vcb, vreadfunc);
+ rb_ary_push (vcb, vhook_value);
+
+ err = gpgme_data_new_with_read_cb (&dh, read_cb, (void*)vcb);
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ {
+ vdh = WRAP_GPGME_DATA(dh);
+ /* Keep a references to avoid GC. */
+ rb_iv_set (vdh, "@read_cb", vcb);
+ rb_ary_push (rdh, vdh);
+ }
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_data_release (dummy, vdh)
+ VALUE dummy, vdh;
+{
+ gpgme_data_t dh;
+
+ UNWRAP_GPGME_DATA(vdh, dh);
+ if (!dh)
+ rb_raise (rb_eRuntimeError,
+ "GpgmeData has already been released.");
+ gpgme_data_release (dh);
+ DATA_PTR(vdh) = NULL;
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_data_release_and_get_mem (dummy, vdh, rlength)
+ VALUE dummy, vdh, rlength;
+{
+ gpgme_data_t dh;
+ char *buffer;
+ VALUE vbuffer;
+ size_t length;
+
+ UNWRAP_GPGME_DATA(vdh, dh);
+ if (!dh)
+ rb_raise (rb_eRuntimeError,
+ "GpgmeData has already been released.");
+ buffer = gpgme_data_release_and_get_mem (dh, &length);
+ DATA_PTR(vdh) = NULL;
+ if (buffer == NULL)
+ return Qnil;
+ vbuffer = rb_str_new (buffer, length);
+ free (buffer);
+ rb_ary_push (rlength, UINT2NUM(length));
+ return vbuffer;
+}
+
+static VALUE
+rb_s_gpgme_data_read (dummy, vdh, rbuffer, vlength)
+ VALUE dummy, vdh, rbuffer, vlength;
+{
+ gpgme_data_t dh;
+ ssize_t length = NUM2LONG(vlength), nread;
+
+ if (!NIL_P(rbuffer))
+ {
+ if (RSTRING(rbuffer)->len < length)
+ rb_raise (rb_eArgError, "argument out of range");
+ rb_str_modify (rbuffer);
+ }
+ UNWRAP_GPGME_DATA(vdh, dh);
+ nread = gpgme_data_read (dh, NIL_P(rbuffer) ? NULL : StringValuePtr(rbuffer),
+ length);
+ return LONG2NUM(nread);
+}
+
+static VALUE
+rb_s_gpgme_data_rewind (dummy, vdh)
+ VALUE dummy, vdh;
+{
+ gpgme_data_t dh;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_DATA(vdh, dh);
+ err = gpgme_data_rewind (dh);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_data_write (dummy, vdh, vbuf, vlen)
+ VALUE dummy, vdh, vbuf, vlen;
+{
+ gpgme_data_t dh;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_DATA(vdh, dh);
+ err = gpgme_data_write (dh, StringValuePtr(vbuf), NUM2UINT(vlen));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_data_get_type (dummy, vdh)
+ VALUE dummy, vdh;
+{
+ gpgme_data_t dh;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_DATA(vdh, dh);
+ err = gpgme_data_get_type (dh);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_data_get_encoding (dummy, vdh)
+ VALUE dummy, vdh;
+{
+ gpgme_data_t dh;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_DATA(vdh, dh);
+ err = gpgme_data_get_encoding (dh);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_data_set_encoding (dummy, vdh, venc)
+ VALUE dummy, vdh, venc;
+{
+ gpgme_data_t dh;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_DATA(vdh, dh);
+ err = gpgme_data_set_encoding (dh, NUM2INT(venc));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_new (dummy, rctx)
+ VALUE dummy, rctx;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err = gpgme_new (&ctx);
+
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ rb_ary_push (rctx, WRAP_GPGME_CTX(ctx));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_release (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ if (!ctx)
+ rb_raise (rb_eRuntimeError,
+ "gpgme_ctx_t has already been released.");
+ gpgme_release (ctx);
+ DATA_PTR(vctx) = NULL;
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_set_protocol (dummy, vctx, vproto)
+ VALUE dummy, vctx, vproto;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_set_protocol (ctx, NUM2INT(vproto));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_get_protocol (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+ gpgme_protocol_t proto;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ proto = gpgme_get_protocol (ctx);
+ return INT2NUM(proto);
+}
+
+static VALUE
+rb_s_gpgme_set_armor (dummy, vctx, vyes)
+ VALUE dummy, vctx, vyes;
+{
+ gpgme_ctx_t ctx;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ gpgme_set_armor (ctx, NUM2INT(vyes));
+
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_get_armor (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+ int yes;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ yes = gpgme_get_armor (ctx);
+ return INT2NUM(yes);
+}
+
+static VALUE
+rb_s_gpgme_set_textmode (dummy, vctx, vyes)
+ VALUE dummy, vctx, vyes;
+{
+ gpgme_ctx_t ctx;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ gpgme_set_textmode (ctx, NUM2INT(vyes));
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_get_textmode (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+ int yes;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ yes = gpgme_get_textmode (ctx);
+ return INT2NUM(yes);
+}
+
+static VALUE
+rb_s_gpgme_set_include_certs (dummy, vctx, vnr_of_certs)
+ VALUE dummy, vctx, vnr_of_certs;
+{
+ gpgme_ctx_t ctx;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ gpgme_set_include_certs (ctx, NUM2INT(vnr_of_certs));
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_get_include_certs (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_get_include_certs (ctx);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_set_keylist_mode (dummy, vctx, vmode)
+ VALUE dummy, vctx, vmode;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_set_keylist_mode (ctx, NUM2INT(vmode));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_get_keylist_mode (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+ int mode;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ mode = gpgme_get_keylist_mode (ctx);
+ return INT2NUM(mode);
+}
+
+static gpgme_error_t
+passphrase_cb (hook, uid_hint, passphrase_info, prev_was_bad, fd)
+ void *hook;
+ const char *uid_hint, *passphrase_info;
+ int prev_was_bad, fd;
+{
+ VALUE vcb = (VALUE)hook, vpassfunc, vhook_value, verr;
+
+ vpassfunc = RARRAY(vcb)->ptr[0];
+ vhook_value = RARRAY(vcb)->ptr[1];
+
+ verr = rb_funcall (vpassfunc, rb_intern ("call"), 5,
+ vhook_value,
+ uid_hint ? rb_str_new2 (uid_hint) : Qnil,
+ passphrase_info ? rb_str_new2 (passphrase_info) : Qnil,
+ INT2NUM(prev_was_bad),
+ INT2NUM(fd));
+ return NUM2LONG(verr);
+}
+
+static VALUE
+rb_s_gpgme_set_passphrase_cb (dummy, vctx, vpassfunc, vhook_value)
+ VALUE dummy, vctx, vpassfunc, vhook_value;
+{
+ gpgme_ctx_t ctx;
+ VALUE vcb = rb_ary_new ();
+
+ rb_ary_push (vcb, vpassfunc);
+ rb_ary_push (vcb, vhook_value);
+ /* Keep a references to avoid GC. */
+ rb_iv_set (vctx, "@passphrase_cb", vcb);
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, (void*)vcb);
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_get_passphrase_cb (dummy, vctx, rpassfunc, rhook_value)
+ VALUE dummy, vctx, rpassfunc, rhook_value;
+{
+ VALUE vcb = rb_iv_get (vctx, "@passphrase_cb");
+
+ /* No need to call gpgme_get_passphrase_cb. */
+ rb_ary_push (rpassfunc, RARRAY(vcb)->ptr[0]);
+ rb_ary_push (rhook_value, RARRAY(vcb)->ptr[1]);
+ return Qnil;
+}
+
+static void
+progress_cb (hook, what, type, current, total)
+ void *hook;
+ const char *what;
+ int type, current, total;
+{
+ VALUE vcb = (VALUE)hook, vprogfunc, vhook_value;
+
+ vprogfunc = RARRAY(vcb)->ptr[0];
+ vhook_value = RARRAY(vcb)->ptr[1];
+
+ rb_funcall (vprogfunc, rb_intern ("call"), 5, vhook_value, INT2NUM(type),
+ INT2NUM(current), INT2NUM(total));
+}
+
+static VALUE
+rb_s_gpgme_set_progress_cb (dummy, vctx, vprogfunc, vhook_value)
+ VALUE dummy, vctx, vprogfunc, vhook_value;
+{
+ gpgme_ctx_t ctx;
+ VALUE vcb = rb_ary_new ();
+
+ rb_ary_push (vcb, vprogfunc);
+ rb_ary_push (vcb, vhook_value);
+ /* Keep a references to avoid GC. */
+ rb_iv_set (vctx, "@progress_cb", vcb);
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ gpgme_set_progress_cb (ctx, progress_cb, (void*)vctx);
+
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_get_progress_cb (dummy, vctx, rprogfunc, rhook_value)
+ VALUE dummy, vctx, rprogfunc, rhook_value;
+{
+ VALUE vcb = rb_iv_get (vctx, "@progress_cb");
+ rb_ary_push (rprogfunc, RARRAY(vcb)->ptr[0]);
+ rb_ary_push (rhook_value, RARRAY(vcb)->ptr[1]);
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_op_keylist_start (dummy, vctx, vpattern, vsecret_only)
+ VALUE dummy, vctx, vpattern, vsecret_only;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_op_keylist_start (ctx, NIL_P(vpattern) ? NULL :
+ StringValueCStr(vpattern),
+ NUM2INT(vsecret_only));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_keylist_ext_start (dummy, vctx, vpattern, vsecret_only)
+ VALUE dummy, vctx, vpattern, vsecret_only;
+{
+ gpgme_ctx_t ctx;
+ const char **pattern = NULL;
+ int i, err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+
+ if (!NIL_P(vpattern))
+ {
+ /* Convert RARRAY into `const char *' array. */
+ pattern = (const char **)ALLOCA_N(const char *,
+ RARRAY(vpattern)->len + 1);
+ for (i = 0; i<RARRAY(vpattern)->len; i++)
+ pattern[i] = StringValueCStr(RARRAY(vpattern)->ptr[i]);
+ pattern[RARRAY(vpattern)->len] = NULL;
+ }
+
+ err = gpgme_op_keylist_ext_start (ctx, pattern, NUM2INT(vsecret_only), 0);
+ return LONG2NUM(err);
+}
+
+static VALUE
+wrap_gpgme_key (key)
+ gpgme_key_t key;
+{
+ VALUE vkey = WRAP_GPGME_KEY(key), vsubkeys, vuids;
+ gpgme_subkey_t subkey;
+ gpgme_user_id_t user_id;
+
+ rb_iv_set (vkey, "@keylist_mode", INT2FIX(key->keylist_mode));
+ rb_iv_set (vkey, "@revoked", INT2FIX(key->revoked));
+ rb_iv_set (vkey, "@expired", INT2FIX(key->expired));
+ rb_iv_set (vkey, "@disabled", INT2FIX(key->disabled));
+ rb_iv_set (vkey, "@invalid", INT2FIX(key->invalid));
+ rb_iv_set (vkey, "@can_encrypt", INT2FIX(key->can_encrypt));
+ rb_iv_set (vkey, "@can_sign", INT2FIX(key->can_sign));
+ rb_iv_set (vkey, "@can_certify", INT2FIX(key->can_certify));
+ rb_iv_set (vkey, "@can_authenticate", INT2FIX(key->can_authenticate));
+ rb_iv_set (vkey, "@secret", INT2FIX(key->secret));
+ rb_iv_set (vkey, "@protocol", INT2FIX(key->protocol));
+ if (key->issuer_serial)
+ rb_iv_set (vkey, "@issuer_serial", rb_str_new2 (key->issuer_serial));
+ if (key->issuer_name)
+ rb_iv_set (vkey, "@issuer_name", rb_str_new2 (key->issuer_name));
+ if (key->chain_id)
+ rb_iv_set (vkey, "@chain_id", rb_str_new2 (key->chain_id));
+ rb_iv_set (vkey, "@owner_trust", INT2FIX(key->owner_trust));
+ vsubkeys = rb_ary_new ();
+ rb_iv_set (vkey, "@subkeys", vsubkeys);
+ for (subkey = key->subkeys; subkey; subkey = subkey->next)
+ {
+ VALUE vsubkey = rb_class_new_instance(0, NULL, cGpgmeSubKey);
+ rb_iv_set (vsubkey, "@revoked", INT2FIX(subkey->revoked));
+ rb_iv_set (vsubkey, "@expired", INT2FIX(subkey->expired));
+ rb_iv_set (vsubkey, "@disabled", INT2FIX(subkey->disabled));
+ rb_iv_set (vsubkey, "@invalid", INT2FIX(subkey->invalid));
+ rb_iv_set (vsubkey, "@can_encrypt", INT2FIX(subkey->can_encrypt));
+ rb_iv_set (vsubkey, "@can_sign", INT2FIX(subkey->can_sign));
+ rb_iv_set (vsubkey, "@can_certify", INT2FIX(subkey->can_certify));
+ rb_iv_set (vsubkey, "@can_authenticate",
+ INT2FIX(subkey->can_authenticate));
+ rb_iv_set (vsubkey, "@secret", INT2FIX(subkey->secret));
+ rb_iv_set (vsubkey, "@pubkey_algo", INT2FIX(subkey->pubkey_algo));
+ rb_iv_set (vsubkey, "@length", UINT2NUM(subkey->length));
+ rb_iv_set (vsubkey, "@keyid", rb_str_new2 (subkey->keyid));
+ rb_iv_set (vsubkey, "@fpr", rb_str_new2 (subkey->fpr));
+ rb_iv_set (vsubkey, "@timestamp", LONG2NUM(subkey->timestamp));
+ rb_iv_set (vsubkey, "@expires", LONG2NUM(subkey->expires));
+ rb_ary_push (vsubkeys, vsubkey);
+ }
+ vuids = rb_ary_new ();
+ rb_iv_set (vkey, "@uids", vuids);
+ for (user_id = key->uids; user_id; user_id = user_id->next)
+ {
+ VALUE vuser_id = rb_class_new_instance(0, NULL, cGpgmeUserId),
+ vsignatures = rb_ary_new ();
+ rb_iv_set (vuser_id, "@revoked", INT2FIX(user_id->revoked));
+ rb_iv_set (vuser_id, "@invalid", INT2FIX(user_id->invalid));
+ rb_iv_set (vuser_id, "@validity", INT2FIX(user_id->validity));
+ rb_iv_set (vuser_id, "@uid", rb_str_new2 (user_id->uid));
+ rb_iv_set (vuser_id, "@name", rb_str_new2 (user_id->name));
+ rb_iv_set (vuser_id, "@comment", rb_str_new2 (user_id->comment));
+ rb_iv_set (vuser_id, "@email", rb_str_new2 (user_id->email));
+
+ gpgme_key_sig_t key_sig;
+ for (key_sig = user_id->signatures; key_sig; key_sig = key_sig->next)
+ {
+ VALUE vkey_sig = rb_class_new_instance(0, NULL, cGpgmeKeySig);
+ rb_iv_set (vkey_sig, "@revoked", INT2FIX(key_sig->revoked));
+ rb_iv_set (vkey_sig, "@expired", INT2FIX(key_sig->expired));
+ rb_iv_set (vkey_sig, "@invalid", INT2FIX(key_sig->invalid));
+ rb_iv_set (vkey_sig, "@exportable", INT2FIX(key_sig->exportable));
+ rb_iv_set (vkey_sig, "@pubkey_algo", INT2FIX(key_sig->pubkey_algo));
+ rb_iv_set (vkey_sig, "@keyid", rb_str_new2 (key_sig->keyid));
+ rb_iv_set (vkey_sig, "@timestamp", LONG2NUM(key_sig->timestamp));
+ rb_iv_set (vkey_sig, "@expires", LONG2NUM(key_sig->expires));
+ rb_ary_push (vsignatures, vkey_sig);
+ }
+ rb_ary_push (vuids, vuser_id);
+ }
+ return vkey;
+}
+
+static VALUE
+rb_s_gpgme_op_keylist_next (dummy, vctx, rkey)
+ VALUE dummy, vctx, rkey;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t key;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_op_keylist_next (ctx, &key);
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ rb_ary_push (rkey, wrap_gpgme_key (key));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_keylist_end (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_op_keylist_end (ctx);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_get_key (dummy, vctx, vfpr, rkey, vsecret)
+ VALUE dummy, vctx, vfpr, rkey, vsecret;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+ gpgme_key_t key;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_get_key (ctx, StringValueCStr(vfpr), &key, NUM2INT(vsecret));
+
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ rb_ary_push (rkey, wrap_gpgme_key (key));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_key_get_string_attr (dummy, vkey, vwhat, vidx)
+ VALUE dummy, vkey, vwhat, vidx;
+{
+ gpgme_key_t key;
+ const char *attr;
+
+ UNWRAP_GPGME_KEY(vkey, key);
+ attr = gpgme_key_get_string_attr (key, NUM2INT(vwhat), NULL, NUM2INT(vidx));
+ if (!attr)
+ return Qnil;
+ return rb_str_new2 (attr);
+}
+
+static VALUE
+rb_s_gpgme_key_get_ulong_attr (dummy, vkey, vwhat, vidx)
+ VALUE dummy, vkey, vwhat, vidx;
+{
+ gpgme_key_t key;
+ unsigned long attr;
+
+ UNWRAP_GPGME_KEY(vkey, key);
+ attr = gpgme_key_get_ulong_attr (key, NUM2INT(vwhat), NULL,
+ NUM2INT(vidx));
+ return ULONG2NUM(attr);
+}
+
+static VALUE
+rb_s_gpgme_key_ref (dummy, vkey)
+ VALUE dummy, vkey;
+{
+ gpgme_key_t key;
+
+ UNWRAP_GPGME_KEY(vkey, key);
+ gpgme_key_ref (key);
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_key_unref (dummy, vkey)
+ VALUE dummy, vkey;
+{
+ gpgme_key_t key;
+
+ UNWRAP_GPGME_KEY(vkey, key);
+ gpgme_key_unref (key);
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_op_genkey (dummy, vctx, vparms, vpubkey, vseckey)
+ VALUE dummy, vctx, vparms, vpubkey, vseckey;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t pubkey = NULL, seckey = NULL;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ if (!NIL_P(vpubkey))
+ UNWRAP_GPGME_DATA(vpubkey, pubkey);
+ if (!NIL_P(vseckey))
+ UNWRAP_GPGME_DATA(vseckey, seckey);
+ err = gpgme_op_genkey (ctx, StringValueCStr(vparms), pubkey, seckey);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_genkey_start (dummy, vctx, vparms, vpubkey, vseckey)
+ VALUE dummy, vctx, vparms, vpubkey, vseckey;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t pubkey = NULL, seckey = NULL;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ if (!NIL_P(vpubkey))
+ UNWRAP_GPGME_DATA(vpubkey, pubkey);
+ if (!NIL_P(vseckey))
+ UNWRAP_GPGME_DATA(vseckey, seckey);
+ err = gpgme_op_genkey_start (ctx, StringValueCStr(vparms), pubkey, seckey);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_export (dummy, vctx, vpattern, vreserved, vkeydata)
+ VALUE dummy, vctx, vpattern, vreserved, vkeydata;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t keydata;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
+
+ err = gpgme_op_export (ctx, StringValueCStr(vpattern), NUM2UINT(vreserved),
+ keydata);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_export_start (dummy, vctx, vpattern, vreserved, vkeydata)
+ VALUE dummy, vctx, vpattern, vreserved, vkeydata;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t keydata;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
+
+ err = gpgme_op_export_start (ctx, StringValueCStr(vpattern),
+ NUM2UINT(vreserved), keydata);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_import (dummy, vctx, vkeydata)
+ VALUE dummy, vctx, vkeydata;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t keydata;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
+
+ err = gpgme_op_import (ctx, keydata);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_import_start (dummy, vctx, vkeydata)
+ VALUE dummy, vctx, vkeydata;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t keydata;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
+
+ err = gpgme_op_import_start (ctx, keydata);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_import_ext (dummy, vctx, vkeydata, rnr)
+ VALUE dummy, vctx, vkeydata, rnr;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t keydata;
+ int nr, err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
+
+ err = gpgme_op_import_ext (ctx, keydata, &nr);
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ rb_ary_push (rnr, INT2NUM(nr));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_delete (dummy, vctx, vkey, vallow_secret)
+ VALUE dummy, vctx, vkey, vallow_secret;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t key;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_KEY(vkey, key);
+
+ err = gpgme_op_delete (ctx, key, NUM2INT(vallow_secret));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_delete_start (dummy, vctx, vkey, vallow_secret)
+ VALUE dummy, vctx, vkey, vallow_secret;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t key;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_KEY(vkey, key);
+
+ err = gpgme_op_delete_start (ctx, key, NUM2INT(vallow_secret));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_trustlist_start (dummy, vctx, vpattern, vmax_level)
+ VALUE dummy, vctx, vpattern, vmax_level;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_op_trustlist_start (ctx, StringValueCStr(vpattern),
+ NUM2INT(vmax_level));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_trustlist_next (dummy, vctx, ritem)
+ VALUE dummy, vctx, ritem;
+{
+ gpgme_ctx_t ctx;
+ gpgme_trust_item_t item;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_op_trustlist_next (ctx, &item);
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ rb_ary_push (ritem, WRAP_GPGME_TRUST_ITEM(item));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_trustlist_end (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_op_trustlist_end (ctx);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_trust_item_get_string_attr (dummy, vitem, vwhat, vidx)
+ VALUE dummy, vitem, vwhat, vidx;
+{
+ gpgme_trust_item_t item;
+ const char *attr;
+
+ UNWRAP_GPGME_TRUST_ITEM(vitem, item);
+ attr = gpgme_trust_item_get_string_attr (item, NUM2INT(vwhat), NULL,
+ NUM2INT(vidx));
+ if (!attr)
+ return Qnil;
+ return rb_str_new2 (attr);
+}
+
+static VALUE
+rb_s_gpgme_trust_item_get_int_attr (dummy, vitem, vwhat, vidx)
+ VALUE dummy, vitem, vwhat, vidx;
+{
+ gpgme_trust_item_t item;
+ int attr;
+
+ UNWRAP_GPGME_TRUST_ITEM(vitem, item);
+ attr = gpgme_trust_item_get_int_attr (item, NUM2INT(vwhat), NULL,
+ NUM2INT(vidx));
+ return INT2NUM(attr);
+}
+
+static VALUE
+rb_s_gpgme_trust_item_release (dummy, vitem)
+ VALUE dummy, vitem;
+{
+ gpgme_trust_item_t item;
+
+ UNWRAP_GPGME_TRUST_ITEM(vitem, item);
+ if (!item)
+ rb_raise (rb_eRuntimeError,
+ "gpgme_trust_item_t has already been released.");
+ gpgme_trust_item_release (item);
+ DATA_PTR(vitem) = NULL;
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_op_decrypt (dummy, vctx, vcipher, vplain)
+ VALUE dummy, vctx, vcipher, vplain;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t cipher, plain;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vcipher, cipher);
+ UNWRAP_GPGME_DATA(vplain, plain);
+
+ err = gpgme_op_decrypt (ctx, cipher, plain);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_decrypt_start (dummy, vctx, vcipher, vplain)
+ VALUE dummy, vctx, vcipher, vplain;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t cipher, plain;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vcipher, cipher);
+ UNWRAP_GPGME_DATA(vplain, plain);
+
+ err = gpgme_op_decrypt_start (ctx, cipher, plain);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_verify (dummy, vctx, vsig, vsigned_text, vplain)
+ VALUE dummy, vctx, vsig, vsigned_text, vplain;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t sig, signed_text = NULL, plain = NULL;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vsig, sig);
+ if (!NIL_P(vsigned_text))
+ UNWRAP_GPGME_DATA(vsigned_text, signed_text);
+ if (!NIL_P(vplain))
+ UNWRAP_GPGME_DATA(vplain, plain);
+
+ err = gpgme_op_verify (ctx, sig, signed_text, plain);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_verify_start (dummy, vctx, vsig, vsigned_text, vplain)
+ VALUE dummy, vctx, vsig, vsigned_text, vplain;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t sig, signed_text, plain;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vsig, sig);
+ UNWRAP_GPGME_DATA(vsigned_text, signed_text);
+ UNWRAP_GPGME_DATA(vplain, plain);
+
+ err = gpgme_op_verify_start (ctx, sig, signed_text, plain);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_verify_result (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+ gpgme_verify_result_t verify_result;
+ gpgme_signature_t signature;
+ VALUE vverify_result, vsignatures = rb_ary_new ();
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+
+ verify_result = gpgme_op_verify_result (ctx);
+ vverify_result = rb_class_new_instance(0, NULL, cGpgmeVerifyResult);
+ rb_iv_set (vverify_result, "@signatures", vsignatures);
+ for (signature = verify_result->signatures; signature;
+ signature = signature->next)
+ {
+ VALUE vsignature = rb_class_new_instance(0, NULL, cGpgmeSignature),
+ vnotations = rb_ary_new ();
+ gpgme_sig_notation_t notation;
+ rb_iv_set (vsignature, "@summary", INT2FIX(signature->summary));
+ rb_iv_set (vsignature, "@fpr", rb_str_new2 (signature->fpr));
+ rb_iv_set (vsignature, "@status", LONG2NUM(signature->status));
+ rb_iv_set (vsignature, "@notations", vnotations);
+ for (notation = signature->notations; notation;
+ notation = notation->next)
+ {
+ VALUE vnotation = rb_class_new_instance(0, NULL, cGpgmeSigNotation);
+ rb_iv_set (vnotation, "@name", rb_str_new2 (notation->name));
+ rb_iv_set (vnotation, "@value", rb_str_new2 (notation->value));
+ rb_ary_push (vnotations, vnotation);
+ }
+ rb_iv_set (vsignature, "@timestamp", ULONG2NUM(signature->timestamp));
+ rb_iv_set (vsignature, "@exp_timestamp",
+ ULONG2NUM(signature->exp_timestamp));
+ rb_iv_set (vsignature, "@wrong_key_usage",
+ INT2FIX(signature->wrong_key_usage));
+ rb_iv_set (vsignature, "@validity", INT2FIX(signature->validity));
+ rb_iv_set (vsignature, "@validity_reason",
+ LONG2NUM(signature->validity_reason));
+ rb_ary_push (vsignatures, vsignature);
+ }
+ return vverify_result;
+}
+
+static VALUE
+rb_s_gpgme_get_sig_status (dummy, vctx, vidx, rstat, rcreated)
+ VALUE dummy, vctx, vidx, rstat, rcreated;
+{
+ gpgme_ctx_t ctx;
+ gpgme_sig_stat_t stat;
+ time_t created;
+ const char *fingerprint;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ fingerprint = gpgme_get_sig_status (ctx, NUM2INT(vidx), &stat, &created);
+ if (!fingerprint)
+ return Qnil;
+ rb_ary_push (rstat, INT2NUM(stat));
+ rb_ary_push (rcreated, rb_time_new (created, 0));
+ return rb_str_new2 (fingerprint);
+}
+
+static VALUE
+rb_s_gpgme_get_sig_string_attr (dummy, vctx, vidx, vwhat, vwhatidx)
+ VALUE dummy, vctx, vidx, vwhat, vwhatidx;
+{
+ gpgme_ctx_t ctx;
+ const char *attr;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ attr = gpgme_get_sig_string_attr (ctx, NUM2INT(vidx), NUM2INT(vwhat),
+ NUM2INT(vwhatidx));
+ if (!attr)
+ return Qnil;
+ return rb_str_new2 (attr);
+}
+
+static VALUE
+rb_s_gpgme_get_sig_ulong_attr (dummy, vctx, vidx, vwhat, vwhatidx)
+ VALUE dummy, vctx, vidx, vwhat, vwhatidx;
+{
+ gpgme_ctx_t ctx;
+ unsigned long attr;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ attr = gpgme_get_sig_ulong_attr (ctx, NUM2INT(vidx), NUM2INT(vwhat),
+ NUM2INT(vwhatidx));
+ return ULONG2NUM(attr);
+}
+
+static VALUE
+rb_s_gpgme_get_sig_key (dummy, vctx, vidx, rkey)
+ VALUE dummy, vctx, vidx, rkey;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t key;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ err = gpgme_get_sig_key (ctx, NUM2INT(vidx), &key);
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
+ rb_ary_push (rkey, WRAP_GPGME_KEY(key));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_decrypt_verify (dummy, vctx, vcipher, vplain)
+ VALUE dummy, vctx, vcipher, vplain;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t cipher, plain;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vcipher, cipher);
+ UNWRAP_GPGME_DATA(vplain, plain);
+
+ err = gpgme_op_decrypt_verify (ctx, cipher, plain);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_decrypt_verify_start (dummy, vctx, vcipher, vplain)
+ VALUE dummy, vctx, vcipher, vplain;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t cipher, plain;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vcipher, cipher);
+ UNWRAP_GPGME_DATA(vplain, plain);
+
+ err = gpgme_op_decrypt_verify_start (ctx, cipher, plain);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_signers_clear (dummy, vctx)
+ VALUE dummy, vctx;
+{
+ gpgme_ctx_t ctx;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ gpgme_signers_clear (ctx);
+ return Qnil;
+}
+
+static VALUE
+rb_s_gpgme_signers_add (dummy, vctx, vkey)
+ VALUE dummy, vctx, vkey;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t key;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_KEY(vkey, key);
+
+ err = gpgme_signers_add (ctx, key);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_signers_enum (dummy, vctx, vseq)
+ VALUE dummy, vctx, vseq;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t key;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+
+ key = gpgme_signers_enum (ctx, NUM2INT(vseq));
+ if (!key)
+ return Qnil;
+ return WRAP_GPGME_KEY(key);
+}
+
+static VALUE
+rb_s_gpgme_op_sign (dummy, vctx, vplain, vsig, vmode)
+ VALUE dummy, vctx, vplain, vsig, vmode;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t plain, sig;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vplain, plain);
+ UNWRAP_GPGME_DATA(vsig, sig);
+
+ err = gpgme_op_sign (ctx, plain, sig, NUM2INT(vmode));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_sign_start (dummy, vctx, vplain, vsig, vmode)
+ VALUE dummy, vctx, vplain, vsig, vmode;
+{
+ gpgme_ctx_t ctx;
+ gpgme_data_t plain, sig;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ UNWRAP_GPGME_DATA(vplain, plain);
+ UNWRAP_GPGME_DATA(vsig, sig);
+
+ err = gpgme_op_sign_start (ctx, plain, sig, NUM2INT(vmode));
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_encrypt (dummy, vctx, vrecp, vflags, vplain, vcipher)
+ VALUE dummy, vctx, vrecp, vflags, vplain, vcipher;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t *recp = NULL;
+ gpgme_data_t plain, cipher;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ /* If RECP is `NULL', symmetric rather than public key encryption is
+ performed. */
+ if (!NIL_P(vrecp))
+ {
+ int i;
+ recp = ALLOCA_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
+ recp[i] = NULL;
+ }
+ UNWRAP_GPGME_DATA(vplain, plain);
+ UNWRAP_GPGME_DATA(vcipher, cipher);
+
+ err = gpgme_op_encrypt (ctx, recp, NUM2INT(vflags), plain, cipher);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_encrypt_start (dummy, vctx, vrecp, vflags, vplain, vcipher)
+ VALUE dummy, vctx, vrecp, vflags, vplain, vcipher;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t *recp = NULL;
+ gpgme_data_t plain, cipher;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ /* If RECP is `NULL', symmetric rather than public key encryption is
+ performed. */
+ if (!NIL_P(vrecp))
+ {
+ int i;
+ recp = ALLOCA_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
+ recp[i] = NULL;
+ }
+ UNWRAP_GPGME_DATA(vplain, plain);
+ UNWRAP_GPGME_DATA(vcipher, cipher);
+
+ err = gpgme_op_encrypt_start (ctx, recp, NUM2INT(vflags), plain, cipher);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_encrypt_sign (dummy, vctx, vrecp, vflags, vplain, vcipher)
+ VALUE dummy, vctx, vrecp, vflags, vplain, vcipher;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t *recp = NULL;
+ gpgme_data_t plain, cipher;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ /* If RECP is `NULL', symmetric rather than public key encryption is
+ performed. */
+ if (!NIL_P(vrecp))
+ {
+ int i;
+ recp = ALLOCA_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
+ recp[i] = NULL;
+ }
+ UNWRAP_GPGME_DATA(vplain, plain);
+ UNWRAP_GPGME_DATA(vcipher, cipher);
+
+ err = gpgme_op_encrypt_sign (ctx, recp, NUM2INT(vflags), plain, cipher);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_op_encrypt_sign_start (dummy, vctx, vrecp, vflags, vplain, vcipher)
+ VALUE dummy, vctx, vrecp, vflags, vplain, vcipher;
+{
+ gpgme_ctx_t ctx;
+ gpgme_key_t *recp = NULL;
+ gpgme_data_t plain, cipher;
+ gpgme_error_t err;
+
+ UNWRAP_GPGME_CTX(vctx, ctx);
+ /* If RECP is `NULL', symmetric rather than public key encryption is
+ performed. */
+ if (!NIL_P(vrecp))
+ {
+ int i;
+ recp = ALLOCA_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
+ recp[i] = NULL;
+ }
+ UNWRAP_GPGME_DATA(vplain, plain);
+ UNWRAP_GPGME_DATA(vcipher, cipher);
+
+ err = gpgme_op_encrypt_sign_start (ctx, recp, NUM2INT(vflags), plain, cipher);
+ return LONG2NUM(err);
+}
+
+static VALUE
+rb_s_gpgme_wait (dummy, vctx, rstatus, vhang)
+ VALUE dummy, vctx, rstatus, vhang;
+{
+ gpgme_ctx_t ctx = NULL;
+ gpgme_error_t status;
+
+ /* The CTX argument can be `NULL'. In that case, `gpgme_wait' waits
+ for any context to complete its operation. */
+ if (!NIL_P(vctx))
+ UNWRAP_GPGME_CTX(vctx, ctx);
+
+ ctx = gpgme_wait (ctx, &status, NUM2INT(vhang));
+ rb_ary_push (rstatus, INT2NUM(status));
+
+ return WRAP_GPGME_CTX(ctx);
+}
+
+void Init_gpgme_n ()
+{
+ VALUE mGPGME;
+
+ mGPGME = rb_define_module ("GPGME");
+
+ rb_define_module_function (mGPGME, "gpgme_check_version",
+ rb_s_gpgme_check_version, 1);
+ rb_define_module_function (mGPGME, "gpgme_engine_check_version",
+ rb_s_gpgme_engine_check_version, 1);
+ rb_define_module_function (mGPGME, "gpgme_get_engine_info",
+ rb_s_gpgme_get_engine_info, 1);
+
+ rb_define_module_function (mGPGME, "gpgme_err_code",
+ rb_s_gpgme_err_code, 1);
+ rb_define_module_function (mGPGME, "gpgme_err_source",
+ rb_s_gpgme_err_source, 1);
+ rb_define_module_function (mGPGME, "gpgme_strerror",
+ rb_s_gpgme_strerror, 1);
+
+ cGpgmeEngineInfo =
+ rb_define_class_under (mGPGME, "GpgmeEngineInfo", rb_cObject);
+ cGpgmeCtx =
+ rb_define_class_under (mGPGME, "GpgmeCtx", rb_cObject);
+ cGpgmeData =
+ rb_define_class_under (mGPGME, "GpgmeData", rb_cObject);
+ cGpgmeKey =
+ rb_define_class_under (mGPGME, "GpgmeKey", rb_cObject);
+ cGpgmeSubKey =
+ rb_define_class_under (mGPGME, "GpgmeSubKey", rb_cObject);
+ cGpgmeUserId =
+ rb_define_class_under (mGPGME, "GpgmeUserId", rb_cObject);
+ cGpgmeKeySig =
+ rb_define_class_under (mGPGME, "GpgmeKeySig", rb_cObject);
+ cGpgmeVerifyResult =
+ rb_define_class_under (mGPGME, "GpgmeVerifyResult", rb_cObject);
+ cGpgmeSignature =
+ rb_define_class_under (mGPGME, "GpgmeSignature", rb_cObject);
+ cGpgmeSigNotation =
+ rb_define_class_under (mGPGME, "GpgmeSigNotation", rb_cObject);
+ cGpgmeTrustItem =
+ rb_define_class_under (mGPGME, "GpgmeTrustItem", rb_cObject);
+
+ /* Creating Data Buffers
+ *
+ * gpgme_data_new_from_filepart is not currently supported.
+ */
+ rb_define_module_function (mGPGME, "gpgme_data_new",
+ rb_s_gpgme_data_new, 1);
+ rb_define_module_function (mGPGME, "gpgme_data_new_from_mem",
+ rb_s_gpgme_data_new_from_mem, 4);
+ rb_define_module_function (mGPGME, "gpgme_data_new_from_file",
+ rb_s_gpgme_data_new_from_file, 3);
+ rb_define_module_function (mGPGME, "gpgme_data_new_with_read_cb",
+ rb_s_gpgme_data_new_with_read_cb, 3);
+
+ /* Destroying Data Buffers */
+ rb_define_module_function (mGPGME, "gpgme_data_release",
+ rb_s_gpgme_data_release, 1);
+ rb_define_module_function (mGPGME, "gpgme_data_release_and_get_mem",
+ rb_s_gpgme_data_release_and_get_mem, 2);
+
+ /* Manipulating Data Buffers */
+ rb_define_module_function (mGPGME, "gpgme_data_read",
+ rb_s_gpgme_data_read, 3);
+ rb_define_module_function (mGPGME, "gpgme_data_rewind",
+ rb_s_gpgme_data_rewind, 1);
+ rb_define_module_function (mGPGME, "gpgme_data_write",
+ rb_s_gpgme_data_write, 3);
+ rb_define_module_function (mGPGME, "gpgme_data_get_type",
+ rb_s_gpgme_data_get_type, 1);
+ rb_define_module_function (mGPGME, "gpgme_data_get_encoding",
+ rb_s_gpgme_data_get_encoding, 1);
+ rb_define_module_function (mGPGME, "gpgme_data_set_encoding",
+ rb_s_gpgme_data_set_encoding, 2);
+
+ /* Creating Contexts */
+ rb_define_module_function (mGPGME, "gpgme_new",
+ rb_s_gpgme_new, 1);
+
+ /* Destroying Contexts */
+ rb_define_module_function (mGPGME, "gpgme_release",
+ rb_s_gpgme_release, 2);
+
+ /* Context Attributes */
+ rb_define_module_function (mGPGME, "gpgme_set_protocol",
+ rb_s_gpgme_set_protocol, 2);
+ rb_define_module_function (mGPGME, "gpgme_get_protocol",
+ rb_s_gpgme_get_protocol, 1);
+ rb_define_module_function (mGPGME, "gpgme_set_armor",
+ rb_s_gpgme_set_armor, 2);
+ rb_define_module_function (mGPGME, "gpgme_get_armor",
+ rb_s_gpgme_get_armor, 1);
+ rb_define_module_function (mGPGME, "gpgme_set_textmode",
+ rb_s_gpgme_set_textmode, 2);
+ rb_define_module_function (mGPGME, "gpgme_get_textmode",
+ rb_s_gpgme_get_textmode, 1);
+ rb_define_module_function (mGPGME, "gpgme_set_include_certs",
+ rb_s_gpgme_set_include_certs, 2);
+ rb_define_module_function (mGPGME, "gpgme_get_include_certs",
+ rb_s_gpgme_get_include_certs, 1);
+ rb_define_module_function (mGPGME, "gpgme_set_keylist_mode",
+ rb_s_gpgme_set_keylist_mode, 2);
+ rb_define_module_function (mGPGME, "gpgme_get_keylist_mode",
+ rb_s_gpgme_get_keylist_mode, 1);
+ rb_define_module_function (mGPGME, "gpgme_set_passphrase_cb",
+ rb_s_gpgme_set_passphrase_cb, 3);
+ rb_define_module_function (mGPGME, "gpgme_get_passphrase_cb",
+ rb_s_gpgme_get_passphrase_cb, 3);
+ rb_define_module_function (mGPGME, "gpgme_set_progress_cb",
+ rb_s_gpgme_set_progress_cb, 3);
+ rb_define_module_function (mGPGME, "gpgme_get_progress_cb",
+ rb_s_gpgme_get_progress_cb, 3);
+
+ /* Key Management */
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_start",
+ rb_s_gpgme_op_keylist_start, 3);
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_ext_start",
+ rb_s_gpgme_op_keylist_ext_start, 4);
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_next",
+ rb_s_gpgme_op_keylist_next, 2);
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_end",
+ rb_s_gpgme_op_keylist_end, 1);
+ rb_define_module_function (mGPGME, "gpgme_get_key",
+ rb_s_gpgme_get_key, 4);
+ rb_define_module_function (mGPGME, "gpgme_key_get_string_attr",
+ rb_s_gpgme_key_get_string_attr, 3);
+ rb_define_module_function (mGPGME, "gpgme_key_get_ulong_attr",
+ rb_s_gpgme_key_get_ulong_attr, 3);
+ rb_define_module_function (mGPGME, "gpgme_key_ref",
+ rb_s_gpgme_key_ref, 1);
+ rb_define_module_function (mGPGME, "gpgme_key_unref",
+ rb_s_gpgme_key_unref, 1);
+ rb_define_module_function (mGPGME, "gpgme_op_genkey",
+ rb_s_gpgme_op_genkey, 4);
+ rb_define_module_function (mGPGME, "gpgme_op_genkey_start",
+ rb_s_gpgme_op_genkey_start, 4);
+ rb_define_module_function (mGPGME, "gpgme_op_export",
+ rb_s_gpgme_op_export, 3);
+ rb_define_module_function (mGPGME, "gpgme_op_export_start",
+ rb_s_gpgme_op_export_start, 3);
+ rb_define_module_function (mGPGME, "gpgme_op_import",
+ rb_s_gpgme_op_import, 2);
+ rb_define_module_function (mGPGME, "gpgme_op_import_start",
+ rb_s_gpgme_op_import_start, 2);
+ rb_define_module_function (mGPGME, "gpgme_op_import_ext",
+ rb_s_gpgme_op_import_ext, 3);
+ rb_define_module_function (mGPGME, "gpgme_op_delete",
+ rb_s_gpgme_op_delete, 3);
+ rb_define_module_function (mGPGME, "gpgme_op_delete_start",
+ rb_s_gpgme_op_delete_start, 3);
+
+ /* Trust Item Management */
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_start",
+ rb_s_gpgme_op_trustlist_start, 3);
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_next",
+ rb_s_gpgme_op_trustlist_next, 2);
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_end",
+ rb_s_gpgme_op_trustlist_end, 1);
+ rb_define_module_function (mGPGME, "gpgme_trust_item_get_string_attr",
+ rb_s_gpgme_trust_item_get_string_attr, 3);
+ rb_define_module_function (mGPGME, "gpgme_trust_item_get_int_attr",
+ rb_s_gpgme_trust_item_get_int_attr, 3);
+ rb_define_module_function (mGPGME, "gpgme_trust_item_release",
+ rb_s_gpgme_trust_item_release, 1);
+
+ /* Decrypt */
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt",
+ rb_s_gpgme_op_decrypt, 3);
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_start",
+ rb_s_gpgme_op_decrypt_start, 3);
+
+ /* Verify */
+ rb_define_module_function (mGPGME, "gpgme_op_verify",
+ rb_s_gpgme_op_verify, 4);
+ rb_define_module_function (mGPGME, "gpgme_op_verify_start",
+ rb_s_gpgme_op_verify_start, 4);
+ rb_define_module_function (mGPGME, "gpgme_op_verify_result",
+ rb_s_gpgme_op_verify_result, 1);
+ rb_define_module_function (mGPGME, "gpgme_get_sig_status",
+ rb_s_gpgme_get_sig_status, 4);
+ rb_define_module_function (mGPGME, "gpgme_get_sig_string_attr",
+ rb_s_gpgme_get_sig_string_attr, 4);
+ rb_define_module_function (mGPGME, "gpgme_get_sig_ulong_attr",
+ rb_s_gpgme_get_sig_ulong_attr, 4);
+ rb_define_module_function (mGPGME, "gpgme_get_sig_key",
+ rb_s_gpgme_get_sig_key, 3);
+
+ /* Decrypt and Verify */
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_verify",
+ rb_s_gpgme_op_decrypt_verify, 3);
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_verify_start",
+ rb_s_gpgme_op_decrypt_verify_start, 3);
+
+ /* Sign */
+ rb_define_module_function (mGPGME, "gpgme_signers_clear",
+ rb_s_gpgme_signers_clear, 1);
+ rb_define_module_function (mGPGME, "gpgme_signers_add",
+ rb_s_gpgme_signers_add, 2);
+ rb_define_module_function (mGPGME, "gpgme_signers_enum",
+ rb_s_gpgme_signers_enum, 2);
+ rb_define_module_function (mGPGME, "gpgme_op_sign",
+ rb_s_gpgme_op_sign, 4);
+ rb_define_module_function (mGPGME, "gpgme_op_sign_start",
+ rb_s_gpgme_op_sign_start, 4);
+
+ /* Encrypt */
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt",
+ rb_s_gpgme_op_encrypt, 5);
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_start",
+ rb_s_gpgme_op_encrypt_start, 5);
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_sign",
+ rb_s_gpgme_op_encrypt_sign, 5);
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_sign_start",
+ rb_s_gpgme_op_encrypt_sign_start, 5);
+
+ /* Run Control */
+ rb_define_module_function (mGPGME, "gpgme_wait",
+ rb_s_gpgme_wait, 3);
+
+ /* gpgme_err_code_t */
+ rb_define_const (mGPGME, "GPG_ERR_EOF",
+ INT2FIX(GPG_ERR_EOF));
+ rb_define_const (mGPGME, "GPG_ERR_NO_ERROR",
+ INT2FIX(GPG_ERR_NO_ERROR));
+ rb_define_const (mGPGME, "GPG_ERR_GENERAL",
+ INT2FIX(GPG_ERR_GENERAL));
+ rb_define_const (mGPGME, "GPG_ERR_ENOMEM",
+ INT2FIX(GPG_ERR_ENOMEM));
+ rb_define_const (mGPGME, "GPG_ERR_INV_VALUE",
+ INT2FIX(GPG_ERR_INV_VALUE));
+ rb_define_const (mGPGME, "GPG_ERR_UNUSABLE_PUBKEY",
+ INT2FIX(GPG_ERR_UNUSABLE_PUBKEY));
+ rb_define_const (mGPGME, "GPG_ERR_UNUSABLE_SECKEY",
+ INT2FIX(GPG_ERR_UNUSABLE_SECKEY));
+ rb_define_const (mGPGME, "GPG_ERR_NO_DATA",
+ INT2FIX(GPG_ERR_NO_DATA));
+ rb_define_const (mGPGME, "GPG_ERR_CONFLICT",
+ INT2FIX(GPG_ERR_CONFLICT));
+ rb_define_const (mGPGME, "GPG_ERR_NOT_IMPLEMENTED",
+ INT2FIX(GPG_ERR_NOT_IMPLEMENTED));
+ rb_define_const (mGPGME, "GPG_ERR_DECRYPT_FAILED",
+ INT2FIX(GPG_ERR_DECRYPT_FAILED));
+ rb_define_const (mGPGME, "GPG_ERR_BAD_PASSPHRASE",
+ INT2FIX(GPG_ERR_BAD_PASSPHRASE));
+ rb_define_const (mGPGME, "GPG_ERR_CANCELED",
+ INT2FIX(GPG_ERR_CANCELED));
+ rb_define_const (mGPGME, "GPG_ERR_INV_ENGINE",
+ INT2FIX(GPG_ERR_INV_ENGINE));
+ rb_define_const (mGPGME, "GPG_ERR_AMBIGUOUS_NAME",
+ INT2FIX(GPG_ERR_AMBIGUOUS_NAME));
+ rb_define_const (mGPGME, "GPG_ERR_WRONG_KEY_USAGE",
+ INT2FIX(GPG_ERR_WRONG_KEY_USAGE));
+ rb_define_const (mGPGME, "GPG_ERR_CERT_REVOKED",
+ INT2FIX(GPG_ERR_CERT_REVOKED));
+ rb_define_const (mGPGME, "GPG_ERR_CERT_EXPIRED",
+ INT2FIX(GPG_ERR_CERT_EXPIRED));
+ rb_define_const (mGPGME, "GPG_ERR_NO_CRL_KNOWN",
+ INT2FIX(GPG_ERR_NO_CRL_KNOWN));
+ rb_define_const (mGPGME, "GPG_ERR_NO_POLICY_MATCH",
+ INT2FIX(GPG_ERR_NO_POLICY_MATCH));
+ rb_define_const (mGPGME, "GPG_ERR_NO_SECKEY",
+ INT2FIX(GPG_ERR_NO_SECKEY));
+ rb_define_const (mGPGME, "GPG_ERR_MISSING_CERT",
+ INT2FIX(GPG_ERR_MISSING_CERT));
+ rb_define_const (mGPGME, "GPG_ERR_BAD_CERT_CHAIN",
+ INT2FIX(GPG_ERR_BAD_CERT_CHAIN));
+ rb_define_const (mGPGME, "GPG_ERR_UNSUPPORTED_ALGORITHM",
+ INT2FIX(GPG_ERR_UNSUPPORTED_ALGORITHM));
+ rb_define_const (mGPGME, "GPG_ERR_BAD_SIGNATURE",
+ INT2FIX(GPG_ERR_BAD_SIGNATURE));
+ rb_define_const (mGPGME, "GPG_ERR_NO_PUBKEY",
+ INT2FIX(GPG_ERR_NO_PUBKEY));
+
+ /* gpgme_err_source_t */
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_UNKNOWN",
+ INT2FIX(GPG_ERR_SOURCE_UNKNOWN));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGME",
+ INT2FIX(GPG_ERR_SOURCE_GPGME));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPG",
+ INT2FIX(GPG_ERR_SOURCE_GPG));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGSM",
+ INT2FIX(GPG_ERR_SOURCE_GPGSM));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GCRYPT",
+ INT2FIX(GPG_ERR_SOURCE_GCRYPT));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGAGENT",
+ INT2FIX(GPG_ERR_SOURCE_GPGAGENT));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_PINENTRY",
+ INT2FIX(GPG_ERR_SOURCE_PINENTRY));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_SCD",
+ INT2FIX(GPG_ERR_SOURCE_SCD));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_KEYBOX",
+ INT2FIX(GPG_ERR_SOURCE_KEYBOX));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_1",
+ INT2FIX(GPG_ERR_SOURCE_USER_1));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_2",
+ INT2FIX(GPG_ERR_SOURCE_USER_2));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_3",
+ INT2FIX(GPG_ERR_SOURCE_USER_3));
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_4",
+ INT2FIX(GPG_ERR_SOURCE_USER_4));
+
+ /* gpgme_data_encoding_t */
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_NONE",
+ INT2FIX(GPGME_DATA_ENCODING_NONE));
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_BINARY",
+ INT2FIX(GPGME_DATA_ENCODING_BINARY));
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_BASE64",
+ INT2FIX(GPGME_DATA_ENCODING_BASE64));
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_ARMOR",
+ INT2FIX(GPGME_DATA_ENCODING_ARMOR));
+
+ /* gpgme_sig_stat_t */
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NONE",
+ INT2FIX(GPGME_SIG_STAT_NONE));
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD",
+ INT2FIX(GPGME_SIG_STAT_GOOD));
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_BAD",
+ INT2FIX(GPGME_SIG_STAT_BAD));
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NOKEY",
+ INT2FIX(GPGME_SIG_STAT_NOKEY));
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NOSIG",
+ INT2FIX(GPGME_SIG_STAT_NOSIG));
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_ERROR",
+ INT2FIX(GPGME_SIG_STAT_ERROR));
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_DIFF",
+ INT2FIX(GPGME_SIG_STAT_DIFF));
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD_EXP",
+ INT2FIX(GPGME_SIG_STAT_GOOD_EXP));
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD_EXPKEY",
+ INT2FIX(GPGME_SIG_STAT_GOOD_EXPKEY));
+
+ /* gpgme_sigsum_t */
+ rb_define_const (mGPGME, "GPGME_SIGSUM_VALID",
+ INT2FIX(GPGME_SIGSUM_VALID));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_GREEN",
+ INT2FIX(GPGME_SIGSUM_GREEN));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_RED",
+ INT2FIX(GPGME_SIGSUM_RED));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_REVOKED",
+ INT2FIX(GPGME_SIGSUM_KEY_REVOKED));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_EXPIRED",
+ INT2FIX(GPGME_SIGSUM_KEY_EXPIRED));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_SIG_EXPIRED",
+ INT2FIX(GPGME_SIGSUM_SIG_EXPIRED));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_MISSING",
+ INT2FIX(GPGME_SIGSUM_KEY_MISSING));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_CRL_MISSING",
+ INT2FIX(GPGME_SIGSUM_CRL_MISSING));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_CRL_TOO_OLD",
+ INT2FIX(GPGME_SIGSUM_CRL_TOO_OLD));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_BAD_POLICY",
+ INT2FIX(GPGME_SIGSUM_BAD_POLICY));
+ rb_define_const (mGPGME, "GPGME_SIGSUM_SYS_ERROR",
+ INT2FIX(GPGME_SIGSUM_SYS_ERROR));
+
+ /* gpgme_sig_mode_t */
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_NORMAL",
+ INT2FIX(GPGME_SIG_MODE_NORMAL));
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_DETACH",
+ INT2FIX(GPGME_SIG_MODE_DETACH));
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_CLEAR",
+ INT2FIX(GPGME_SIG_MODE_CLEAR));
+
+ /* gpgme_attr_t */
+ rb_define_const (mGPGME, "GPGME_ATTR_KEYID",
+ INT2FIX(GPGME_ATTR_KEYID));
+ rb_define_const (mGPGME, "GPGME_ATTR_FPR",
+ INT2FIX(GPGME_ATTR_FPR));
+ rb_define_const (mGPGME, "GPGME_ATTR_ALGO",
+ INT2FIX(GPGME_ATTR_ALGO));
+ rb_define_const (mGPGME, "GPGME_ATTR_LEN",
+ INT2FIX(GPGME_ATTR_LEN));
+ rb_define_const (mGPGME, "GPGME_ATTR_CREATED",
+ INT2FIX(GPGME_ATTR_CREATED));
+ rb_define_const (mGPGME, "GPGME_ATTR_EXPIRE",
+ INT2FIX(GPGME_ATTR_EXPIRE));
+ rb_define_const (mGPGME, "GPGME_ATTR_OTRUST",
+ INT2FIX(GPGME_ATTR_OTRUST));
+ rb_define_const (mGPGME, "GPGME_ATTR_USERID",
+ INT2FIX(GPGME_ATTR_USERID));
+ rb_define_const (mGPGME, "GPGME_ATTR_NAME",
+ INT2FIX(GPGME_ATTR_NAME));
+ rb_define_const (mGPGME, "GPGME_ATTR_EMAIL",
+ INT2FIX(GPGME_ATTR_EMAIL));
+ rb_define_const (mGPGME, "GPGME_ATTR_COMMENT",
+ INT2FIX(GPGME_ATTR_COMMENT));
+ rb_define_const (mGPGME, "GPGME_ATTR_VALIDITY",
+ INT2FIX(GPGME_ATTR_VALIDITY));
+ rb_define_const (mGPGME, "GPGME_ATTR_LEVEL",
+ INT2FIX(GPGME_ATTR_LEVEL));
+ rb_define_const (mGPGME, "GPGME_ATTR_TYPE",
+ INT2FIX(GPGME_ATTR_TYPE));
+ rb_define_const (mGPGME, "GPGME_ATTR_IS_SECRET",
+ INT2FIX(GPGME_ATTR_IS_SECRET));
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_REVOKED",
+ INT2FIX(GPGME_ATTR_KEY_REVOKED));
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_INVALID",
+ INT2FIX(GPGME_ATTR_KEY_INVALID));
+ rb_define_const (mGPGME, "GPGME_ATTR_UID_REVOKED",
+ INT2FIX(GPGME_ATTR_UID_REVOKED));
+ rb_define_const (mGPGME, "GPGME_ATTR_UID_INVALID",
+ INT2FIX(GPGME_ATTR_UID_INVALID));
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_CAPS",
+ INT2FIX(GPGME_ATTR_KEY_CAPS));
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_ENCRYPT",
+ INT2FIX(GPGME_ATTR_CAN_ENCRYPT));
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_SIGN",
+ INT2FIX(GPGME_ATTR_CAN_SIGN));
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_CERTIFY",
+ INT2FIX(GPGME_ATTR_CAN_CERTIFY));
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_EXPIRED",
+ INT2FIX(GPGME_ATTR_KEY_EXPIRED));
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_DISABLED",
+ INT2FIX(GPGME_ATTR_KEY_DISABLED));
+ rb_define_const (mGPGME, "GPGME_ATTR_SERIAL",
+ INT2FIX(GPGME_ATTR_SERIAL));
+ rb_define_const (mGPGME, "GPGME_ATTR_ISSUER",
+ INT2FIX(GPGME_ATTR_ISSUER));
+ rb_define_const (mGPGME, "GPGME_ATTR_CHAINID",
+ INT2FIX(GPGME_ATTR_CHAINID));
+ rb_define_const (mGPGME, "GPGME_ATTR_SIG_STATUS",
+ INT2FIX(GPGME_ATTR_SIG_STATUS));
+ rb_define_const (mGPGME, "GPGME_ATTR_ERRTOK",
+ INT2FIX(GPGME_ATTR_ERRTOK));
+ rb_define_const (mGPGME, "GPGME_ATTR_SIG_SUMMARY",
+ INT2FIX(GPGME_ATTR_SIG_SUMMARY));
+
+ /* gpgme_validity_t */
+ rb_define_const (mGPGME, "GPGME_VALIDITY_UNKNOWN",
+ INT2FIX(GPGME_VALIDITY_UNKNOWN));
+ rb_define_const (mGPGME, "GPGME_VALIDITY_UNDEFINED",
+ INT2FIX(GPGME_VALIDITY_UNDEFINED));
+ rb_define_const (mGPGME, "GPGME_VALIDITY_NEVER",
+ INT2FIX(GPGME_VALIDITY_NEVER));
+ rb_define_const (mGPGME, "GPGME_VALIDITY_MARGINAL",
+ INT2FIX(GPGME_VALIDITY_MARGINAL));
+ rb_define_const (mGPGME, "GPGME_VALIDITY_FULL",
+ INT2FIX(GPGME_VALIDITY_FULL));
+ rb_define_const (mGPGME, "GPGME_VALIDITY_ULTIMATE",
+ INT2FIX(GPGME_VALIDITY_ULTIMATE));
+
+ /* gpgme_protocol_t */
+ rb_define_const (mGPGME, "GPGME_PROTOCOL_OpenPGP",
+ INT2FIX(GPGME_PROTOCOL_OpenPGP));
+ rb_define_const (mGPGME, "GPGME_PROTOCOL_CMS",
+ INT2FIX(GPGME_PROTOCOL_CMS));
+
+ /* gpgme_status_code_t */
+ rb_define_const (mGPGME, "GPGME_STATUS_EOF",
+ INT2FIX(GPGME_STATUS_EOF));
+ /* mkstatus starts here */
+ rb_define_const (mGPGME, "GPGME_STATUS_ENTER",
+ INT2FIX(GPGME_STATUS_ENTER));
+ rb_define_const (mGPGME, "GPGME_STATUS_LEAVE",
+ INT2FIX(GPGME_STATUS_LEAVE));
+ rb_define_const (mGPGME, "GPGME_STATUS_ABORT",
+ INT2FIX(GPGME_STATUS_ABORT));
+
+ rb_define_const (mGPGME, "GPGME_STATUS_GOODSIG",
+ INT2FIX(GPGME_STATUS_GOODSIG));
+ rb_define_const (mGPGME, "GPGME_STATUS_BADSIG",
+ INT2FIX(GPGME_STATUS_BADSIG));
+ rb_define_const (mGPGME, "GPGME_STATUS_ERRSIG",
+ INT2FIX(GPGME_STATUS_ERRSIG));
+
+ rb_define_const (mGPGME, "GPGME_STATUS_BADARMOR",
+ INT2FIX(GPGME_STATUS_BADARMOR));
+
+ rb_define_const (mGPGME, "GPGME_STATUS_RSA_OR_IDEA",
+ INT2FIX(GPGME_STATUS_RSA_OR_IDEA));
+ rb_define_const (mGPGME, "GPGME_STATUS_KEYEXPIRED",
+ INT2FIX(GPGME_STATUS_KEYEXPIRED));
+ rb_define_const (mGPGME, "GPGME_STATUS_KEYREVOKED",
+ INT2FIX(GPGME_STATUS_KEYREVOKED));
+
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_UNDEFINED",
+ INT2FIX(GPGME_STATUS_TRUST_UNDEFINED));
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_NEVER",
+ INT2FIX(GPGME_STATUS_TRUST_NEVER));
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_MARGINAL",
+ INT2FIX(GPGME_STATUS_TRUST_MARGINAL));
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_FULLY",
+ INT2FIX(GPGME_STATUS_TRUST_FULLY));
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_ULTIMATE",
+ INT2FIX(GPGME_STATUS_TRUST_ULTIMATE));
+
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_INFO",
+ INT2FIX(GPGME_STATUS_SHM_INFO));
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET",
+ INT2FIX(GPGME_STATUS_SHM_GET));
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET_BOOL",
+ INT2FIX(GPGME_STATUS_SHM_GET_BOOL));
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET_HIDDEN",
+ INT2FIX(GPGME_STATUS_SHM_GET_HIDDEN));
+
+ rb_define_const (mGPGME, "GPGME_STATUS_NEED_PASSPHRASE",
+ INT2FIX(GPGME_STATUS_NEED_PASSPHRASE));
+ rb_define_const (mGPGME, "GPGME_STATUS_VALIDSIG",
+ INT2FIX(GPGME_STATUS_VALIDSIG));
+ rb_define_const (mGPGME, "GPGME_STATUS_SIG_ID",
+ INT2FIX(GPGME_STATUS_SIG_ID));
+ rb_define_const (mGPGME, "GPGME_STATUS_ENC_TO",
+ INT2FIX(GPGME_STATUS_ENC_TO));
+ rb_define_const (mGPGME, "GPGME_STATUS_NODATA",
+ INT2FIX(GPGME_STATUS_NODATA));
+ rb_define_const (mGPGME, "GPGME_STATUS_BAD_PASSPHRASE",
+ INT2FIX(GPGME_STATUS_BAD_PASSPHRASE));
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_PUBKEY",
+ INT2FIX(GPGME_STATUS_NO_PUBKEY));
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_SECKEY",
+ INT2FIX(GPGME_STATUS_NO_SECKEY));
+ rb_define_const (mGPGME, "GPGME_STATUS_NEED_PASSPHRASE_SYM",
+ INT2FIX(GPGME_STATUS_NEED_PASSPHRASE_SYM));
+ rb_define_const (mGPGME, "GPGME_STATUS_DECRYPTION_FAILED",
+ INT2FIX(GPGME_STATUS_DECRYPTION_FAILED));
+ rb_define_const (mGPGME, "GPGME_STATUS_DECRYPTION_OKAY",
+ INT2FIX(GPGME_STATUS_DECRYPTION_OKAY));
+ rb_define_const (mGPGME, "GPGME_STATUS_MISSING_PASSPHRASE",
+ INT2FIX(GPGME_STATUS_MISSING_PASSPHRASE));
+ rb_define_const (mGPGME, "GPGME_STATUS_GOOD_PASSPHRASE",
+ INT2FIX(GPGME_STATUS_GOOD_PASSPHRASE));
+ rb_define_const (mGPGME, "GPGME_STATUS_GOODMDC",
+ INT2FIX(GPGME_STATUS_GOODMDC));
+ rb_define_const (mGPGME, "GPGME_STATUS_BADMDC",
+ INT2FIX(GPGME_STATUS_BADMDC));
+ rb_define_const (mGPGME, "GPGME_STATUS_ERRMDC",
+ INT2FIX(GPGME_STATUS_ERRMDC));
+ rb_define_const (mGPGME, "GPGME_STATUS_IMPORTED",
+ INT2FIX(GPGME_STATUS_IMPORTED));
+ rb_define_const (mGPGME, "GPGME_STATUS_IMPORT_RES",
+ INT2FIX(GPGME_STATUS_IMPORT_RES));
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_START",
+ INT2FIX(GPGME_STATUS_FILE_START));
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_DONE",
+ INT2FIX(GPGME_STATUS_FILE_DONE));
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_ERROR",
+ INT2FIX(GPGME_STATUS_FILE_ERROR));
+
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_DECRYPTION",
+ INT2FIX(GPGME_STATUS_BEGIN_DECRYPTION));
+ rb_define_const (mGPGME, "GPGME_STATUS_END_DECRYPTION",
+ INT2FIX(GPGME_STATUS_END_DECRYPTION));
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_ENCRYPTION",
+ INT2FIX(GPGME_STATUS_BEGIN_ENCRYPTION));
+ rb_define_const (mGPGME, "GPGME_STATUS_END_ENCRYPTION",
+ INT2FIX(GPGME_STATUS_END_ENCRYPTION));
+
+ rb_define_const (mGPGME, "GPGME_STATUS_DELETE_PROBLEM",
+ INT2FIX(GPGME_STATUS_DELETE_PROBLEM));
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_BOOL",
+ INT2FIX(GPGME_STATUS_GET_BOOL));
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_LINE",
+ INT2FIX(GPGME_STATUS_GET_LINE));
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_HIDDEN",
+ INT2FIX(GPGME_STATUS_GET_HIDDEN));
+ rb_define_const (mGPGME, "GPGME_STATUS_GOT_IT",
+ INT2FIX(GPGME_STATUS_GOT_IT));
+ rb_define_const (mGPGME, "GPGME_STATUS_PROGRESS",
+ INT2FIX(GPGME_STATUS_PROGRESS));
+ rb_define_const (mGPGME, "GPGME_STATUS_SIG_CREATED",
+ INT2FIX(GPGME_STATUS_SIG_CREATED));
+ rb_define_const (mGPGME, "GPGME_STATUS_SESSION_KEY",
+ INT2FIX(GPGME_STATUS_SESSION_KEY));
+ rb_define_const (mGPGME, "GPGME_STATUS_NOTATION_NAME",
+ INT2FIX(GPGME_STATUS_NOTATION_NAME));
+ rb_define_const (mGPGME, "GPGME_STATUS_NOTATION_DATA",
+ INT2FIX(GPGME_STATUS_NOTATION_DATA));
+ rb_define_const (mGPGME, "GPGME_STATUS_POLICY_URL",
+ INT2FIX(GPGME_STATUS_POLICY_URL));
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_STREAM",
+ INT2FIX(GPGME_STATUS_BEGIN_STREAM));
+ rb_define_const (mGPGME, "GPGME_STATUS_END_STREAM",
+ INT2FIX(GPGME_STATUS_END_STREAM));
+ rb_define_const (mGPGME, "GPGME_STATUS_KEY_CREATED",
+ INT2FIX(GPGME_STATUS_KEY_CREATED));
+ rb_define_const (mGPGME, "GPGME_STATUS_USERID_HINT",
+ INT2FIX(GPGME_STATUS_USERID_HINT));
+ rb_define_const (mGPGME, "GPGME_STATUS_UNEXPECTED",
+ INT2FIX(GPGME_STATUS_UNEXPECTED));
+ rb_define_const (mGPGME, "GPGME_STATUS_INV_RECP",
+ INT2FIX(GPGME_STATUS_INV_RECP));
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_RECP",
+ INT2FIX(GPGME_STATUS_NO_RECP));
+ rb_define_const (mGPGME, "GPGME_STATUS_ALREADY_SIGNED",
+ INT2FIX(GPGME_STATUS_ALREADY_SIGNED));
+ rb_define_const (mGPGME, "GPGME_STATUS_SIGEXPIRED",
+ INT2FIX(GPGME_STATUS_SIGEXPIRED));
+ rb_define_const (mGPGME, "GPGME_