ruby-gpgme 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,69 @@
1
+ * What's this?
2
+
3
+ Ruby-GPGME is a Ruby language binding of GPGME (GnuPG Made Easy).
4
+
5
+ * Requirements
6
+
7
+ - Ruby 1.8 or later
8
+ - GPGME 1.1.2 or later
9
+ - gpg-agent (optional, but recommended)
10
+
11
+ * Installation
12
+
13
+ $ ruby extconf.rb
14
+ $ make
15
+ $ make install
16
+
17
+ * Examples
18
+
19
+ examples/genkey.rb Generate a key pair in your keyring.
20
+ examples/keylist.rb List your keyring like gpg --list-keys.
21
+ examples/roundtrip.rb Encrypt a plain text and then decrypt it.
22
+ examples/sign.rb Create a clear text signature.
23
+ examples/verify.rb Verify a clear text signature given from stdin.
24
+
25
+ * API
26
+
27
+ Ruby-GPGME provides 3 levels of API. The highest level API is close
28
+ to the command line interface of GnuPG. The lowest level API is close
29
+ to the C interface of GPGME.
30
+
31
+ ** The highest level API
32
+
33
+ For example, to create a cleartext signature of the plaintext from stdin
34
+ can be written as follows.
35
+
36
+ $ ruby -rgpgme -e 'GPGME.clearsign($stdin, $stdout)'
37
+
38
+ ** The lowest level API
39
+
40
+ The same example can be rewritten in the lowest level API as follows.
41
+
42
+ $ ruby -rgpgme -e <<End
43
+ ret = Array.new
44
+ GPGME::gpgme_new(ret)
45
+ ctx = ret.shift
46
+ GPGME::gpgme_data_new_from_fd(ret, 0)
47
+ plain = ret.shift
48
+ GPGME::gpgme_data_new_from_fd(ret, 1)
49
+ sig = ret.shift
50
+ GPGME::gpgme_op_sign(ctx, plain, sig, GPGME::SIG_MODE_CLEAR)
51
+ End
52
+
53
+ As you see, it's much harder to write a program in this API than the
54
+ highest level API. However, if you are already familier with the C
55
+ interface of GPGME and/or want to control detailed behavior of GPGME,
56
+ it might be useful.
57
+
58
+ ** The mid level API
59
+
60
+ There is another API which looks object-oriented. It's easier to use
61
+ than the lowest level API though, you should first consult the highest
62
+ level API.
63
+
64
+ $ ruby -rgpgme -e <<End
65
+ ctx = GPGME::Ctx.new
66
+ plain = GPGME::Data.from_io($stdin)
67
+ sig = GPGME::Data.from_io($stdout)
68
+ ctx.sign(plain, sig, GPGME::SIG_MODE_CLEAR)
69
+ End
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgme'
3
+
4
+ # If you do not have gpg-agent installed, comment out the following
5
+ # and set it as :passphrase_callback.
6
+ #
7
+ # def passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd)
8
+ # $stderr.write("Passphrase for #{uid_hint}: ")
9
+ # $stderr.flush
10
+ # begin
11
+ # system('stty -echo')
12
+ # io = IO.for_fd(fd, 'w')
13
+ # io.puts(gets)
14
+ # io.flush
15
+ # ensure
16
+ # (0 ... $_.length).each do |i| $_[i] = ?0 end if $_
17
+ # system('stty echo')
18
+ # end
19
+ # puts
20
+ # end
21
+
22
+ unless ENV['GPG_AGENT_INFO']
23
+ $stderr.puts("gpg-agent is not running. See the comment in #{$0}.")
24
+ exit(1)
25
+ end
26
+
27
+ unless ENV['GNUPGHOME']
28
+ $stderr.write('As GNUPGHOME is not set, the generated key pair will be stored into *your* keyring. Really proceed? (y/N) ')
29
+ $stderr.flush
30
+ exit(1) unless gets.chomp == 'y'
31
+ end
32
+
33
+ def progfunc(hook, what, type, current, total)
34
+ $stderr.write("#{what}: #{current}/#{total}\r")
35
+ $stderr.flush
36
+ end
37
+
38
+ ctx = GPGME::Ctx.new({:progress_callback => method(:progfunc),
39
+ # :passphrase_callback => method(:passfunc)
40
+ })
41
+
42
+ ctx.genkey(<<'EOF', nil, nil)
43
+ <GnupgKeyParms format="internal">
44
+ Key-Type: DSA
45
+ Key-Length: 1024
46
+ Subkey-Type: ELG-E
47
+ Subkey-Length: 1024
48
+ Name-Real: Joe Tester
49
+ Name-Comment: with stupid passphrase
50
+ Name-Email: joe@foo.bar
51
+ Expire-Date: 0
52
+ Passphrase: abc
53
+ </GnupgKeyParms>
54
+ EOF
55
+ $stderr.puts
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgme'
3
+
4
+ GPGME.list_keys(ARGV.shift) do |key|
5
+ puts(key)
6
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgme'
3
+
4
+ # If you do not have gpg-agent installed, comment out the following
5
+ # and set it as :passphrase_callback.
6
+ #
7
+ # def passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd)
8
+ # $stderr.write("Passphrase for #{uid_hint}: ")
9
+ # $stderr.flush
10
+ # begin
11
+ # system('stty -echo')
12
+ # io = IO.for_fd(fd, 'w')
13
+ # io.puts(gets)
14
+ # io.flush
15
+ # ensure
16
+ # (0 ... $_.length).each do |i| $_[i] = ?0 end if $_
17
+ # system('stty echo')
18
+ # end
19
+ # puts
20
+ # end
21
+
22
+ unless ENV['GPG_AGENT_INFO']
23
+ $stderr.puts("gpg-agent is not running. See the comment in #{$0}.")
24
+ exit(1)
25
+ end
26
+
27
+ plain = 'test test test'
28
+ puts("Plaintext:\n#{plain}")
29
+
30
+ # Perform symmetric encryption on PLAIN.
31
+ cipher = GPGME::encrypt(nil, plain, {:armor => true
32
+ # :passphrase_callback => method(:passfunc)
33
+ })
34
+ puts("Ciphertext:\n#{cipher}")
35
+
36
+ plain = GPGME::decrypt(cipher, {
37
+ # :passphrase_callback => method(:passfunc)
38
+ })
39
+ puts("Plaintext:\n#{plain}")
data/examples/sign.rb ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgme'
3
+
4
+ # If you do not have gpg-agent installed, comment out the following
5
+ # and set it as :passphrase_callback.
6
+ #
7
+ # def passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd)
8
+ # $stderr.write("Passphrase for #{uid_hint}: ")
9
+ # $stderr.flush
10
+ # begin
11
+ # system('stty -echo')
12
+ # io = IO.for_fd(fd, 'w')
13
+ # io.puts(gets)
14
+ # io.flush
15
+ # ensure
16
+ # (0 ... $_.length).each do |i| $_[i] = ?0 end if $_
17
+ # system('stty echo')
18
+ # end
19
+ # puts
20
+ # end
21
+
22
+ unless ENV['GPG_AGENT_INFO']
23
+ $stderr.puts("gpg-agent is not running. See the comment in #{$0}.")
24
+ exit(1)
25
+ end
26
+
27
+ puts GPGME::clearsign('test test test', {
28
+ # :passphrase_callback => method(:passfunc)
29
+ })
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgme'
3
+
4
+ GPGME::verify(ARGF.read, nil, $stdout) do |signature|
5
+ puts(signature.to_s)
6
+ end
data/extconf.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'mkmf'
2
+
3
+ unless find_executable('gpgme-config')
4
+ $stderr.puts("gpgme-config not found")
5
+ exit(1)
6
+ end
7
+
8
+ $CFLAGS += ' ' << `gpgme-config --cflags`.chomp
9
+ $libs += ' ' << `gpgme-config --libs`.chomp
10
+
11
+ create_makefile ('gpgme_n')
data/gpgme_n.c ADDED
@@ -0,0 +1,2166 @@
1
+ /* gpgme_n.c -- low level interface to GPGME
2
+ Copyright (C) 2003,2006,2007 Daiki Ueno
3
+
4
+ This file is a part of Ruby-GPGME.
5
+
6
+ This program is free software; you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation; either version 2, or (at your option)
9
+ any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with GNU Emacs; see the file COPYING. If not, write to the
18
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ Boston, MA 02110-1301, USA. */
20
+
21
+ /* This file is (semi) automatically generated, though it was written
22
+ by hand. There are simple rules to edit this file.
23
+
24
+ 1. Each symbol exported from this module is either a class, a module
25
+ function, or a constant. No instance methods are defined here.
26
+ 2. Each symbol exported from this module follows the same naming
27
+ convention as the GPGME API. That is, symbol names are followed
28
+ by `gpgme_' for functions are followed by `GPGME_' or `GPG_' for
29
+ constants.
30
+ 3. Output arguments are wrapped in arrays. For example, the 1st
31
+ argument of `gpgme_data_new' has type `gpgme_data_t *' to store the
32
+ newly created gpgme_data_t object. The corresponding ruby
33
+ interface uses an empty array to passing it to the caller. */
34
+
35
+ #include "ruby.h"
36
+ #include "gpgme.h"
37
+ #include <errno.h>
38
+
39
+ #define RUBY_GPGME_WORKAROUND_KEYLIST_NEXT
40
+
41
+ #ifdef RUBY_GPGME_WORKAROUND_KEYLIST_NEXT
42
+ #define CHECK_KEYLIST_IN_PROGRESS(vctx) \
43
+ if (rb_iv_get (vctx, "ruby_gpgme_keylist_in_progress") != Qtrue) \
44
+ return LONG2NUM(gpgme_error (GPG_ERR_INV_STATE))
45
+ #define CHECK_KEYLIST_NOT_IN_PROGRESS(vctx) \
46
+ if (rb_iv_get (vctx, "ruby_gpgme_keylist_in_progress") == Qtrue) \
47
+ return LONG2NUM(gpgme_error (GPG_ERR_INV_STATE))
48
+ #define SET_KEYLIST_IN_PROGRESS(vctx) \
49
+ rb_iv_set (vctx, "ruby_gpgme_keylist_in_progress", Qtrue)
50
+ #define RESET_KEYLIST_IN_PROGRESS(vctx) \
51
+ rb_iv_set (vctx, "ruby_gpgme_keylist_in_progress", Qfalse)
52
+ #else
53
+ #define CHECK_KEYLIST_IN_PROGRESS(vctx)
54
+ #define CHECK_KEYLIST_NOT_IN_PROGRESS(vctx)
55
+ #define SET_KEYLIST_IN_PROGRESS(vctx)
56
+ #define RESET_KEYLIST_IN_PROGRESS(vctx)
57
+ #endif
58
+
59
+ /* StringValuePtr is not available in 1.6. */
60
+ #ifndef StringValuePtr
61
+ #define StringValuePtr(str) RSTRING(str)->ptr
62
+ #endif
63
+
64
+ /* STR2CSTR is obsoleted in 1.8. */
65
+ #ifndef StringValueCStr
66
+ #define StringValueCStr STR2CSTR
67
+ #endif
68
+
69
+ /* RARRAY_LEN is not available in 1.8. */
70
+ #ifndef RARRAY_LEN
71
+ #define RARRAY_LEN(a) RARRAY(a)->len
72
+ #endif
73
+
74
+ /* RARRAY_PTR is not available in 1.8. */
75
+ #ifndef RARRAY_PTR
76
+ #define RARRAY_PTR(a) RARRAY(a)->ptr
77
+ #endif
78
+
79
+ #define WRAP_GPGME_DATA(dh) \
80
+ Data_Wrap_Struct(cData, 0, gpgme_data_release, dh) \
81
+ /* `gpgme_data_t' is typedef'ed as `struct gpgme_data *'. */
82
+ #define UNWRAP_GPGME_DATA(vdh, dh) \
83
+ Data_Get_Struct(vdh, struct gpgme_data, dh);
84
+
85
+ #define WRAP_GPGME_CTX(ctx) \
86
+ Data_Wrap_Struct(cCtx, 0, gpgme_release, ctx) \
87
+ /* `gpgme_ctx_t' is typedef'ed as `struct gpgme_context *'. */
88
+ #define UNWRAP_GPGME_CTX(vctx, ctx) \
89
+ Data_Get_Struct(vctx, struct gpgme_context, ctx)
90
+
91
+ #define WRAP_GPGME_KEY(key) \
92
+ Data_Wrap_Struct(cKey, 0, gpgme_key_release, key) \
93
+ /* `gpgme_key_t' is typedef'ed as `struct _gpgme_key *'. */
94
+ #define UNWRAP_GPGME_KEY(vkey, key) \
95
+ Data_Get_Struct(vkey, struct _gpgme_key, key)
96
+
97
+ #define WRAP_GPGME_TRUST_ITEM(item) \
98
+ Data_Wrap_Struct(cTrustItem, 0, gpgme_trust_item_unref, item) \
99
+ /* `gpgme_trust_item_t' is typedef'ed as `struct _gpgme_trust_item *'. */
100
+ #define UNWRAP_GPGME_TRUST_ITEM(vitem, item) \
101
+ Data_Get_Struct(vitem, struct _gpgme_trust_item, item)
102
+
103
+ static VALUE cEngineInfo,
104
+ cCtx,
105
+ cData,
106
+ cKey,
107
+ cSubKey,
108
+ cUserID,
109
+ cKeySig,
110
+ cInvalidKey,
111
+ cNewSignature,
112
+ cSignature,
113
+ cSigNotation,
114
+ cTrustItem,
115
+ cDecryptResult,
116
+ cVerifyResult,
117
+ cSignResult,
118
+ cEncryptResult,
119
+ cImportStatus,
120
+ cImportResult;
121
+
122
+ static VALUE
123
+ rb_s_gpgme_check_version (VALUE dummy, VALUE vreq)
124
+ {
125
+ const char *result = gpgme_check_version (NIL_P(vreq) ? NULL :
126
+ StringValueCStr(vreq));
127
+ return result ? rb_str_new2 (result) : Qnil;
128
+ }
129
+
130
+ static VALUE
131
+ rb_s_gpgme_engine_check_version (VALUE dummy, VALUE vproto)
132
+ {
133
+ gpgme_error_t err = gpgme_engine_check_version (NUM2INT(vproto));
134
+ return LONG2NUM(err);
135
+ }
136
+
137
+ static VALUE
138
+ rb_s_gpgme_get_engine_info (VALUE dummy, VALUE rinfo)
139
+ {
140
+ gpgme_engine_info_t info;
141
+ gpgme_error_t err;
142
+
143
+ err = gpgme_get_engine_info (&info);
144
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
145
+ {
146
+ for (; info; info = info->next)
147
+ {
148
+ VALUE vinfo = rb_class_new_instance (0, NULL, cEngineInfo);
149
+ rb_iv_set (vinfo, "@protocol", INT2FIX(info->protocol));
150
+ if (info->file_name)
151
+ rb_iv_set (vinfo, "@file_name", rb_str_new2 (info->file_name));
152
+ if (info->version)
153
+ rb_iv_set (vinfo, "@version", rb_str_new2 (info->version));
154
+ if (info->req_version)
155
+ rb_iv_set (vinfo, "@req_version", rb_str_new2 (info->req_version));
156
+ rb_ary_store (rinfo, 0, vinfo);
157
+ }
158
+ }
159
+ return LONG2NUM(err);
160
+ }
161
+
162
+ static VALUE
163
+ rb_s_gpgme_pubkey_algo_name (VALUE dummy, VALUE valgo)
164
+ {
165
+ const char *name = gpgme_pubkey_algo_name (NUM2INT(valgo));
166
+ if (name)
167
+ return rb_str_new2 (name);
168
+ return Qnil;
169
+ }
170
+
171
+ static VALUE
172
+ rb_s_gpgme_hash_algo_name (VALUE dummy, VALUE valgo)
173
+ {
174
+ const char *name = gpgme_hash_algo_name (NUM2INT(valgo));
175
+ if (name)
176
+ return rb_str_new2 (name);
177
+ return Qnil;
178
+ }
179
+
180
+ static VALUE
181
+ rb_s_gpgme_err_code (VALUE dummy, VALUE verr)
182
+ {
183
+ return INT2FIX(gpgme_err_code (NUM2LONG(verr)));
184
+ }
185
+
186
+ static VALUE
187
+ rb_s_gpgme_err_source (VALUE dummy, VALUE verr)
188
+ {
189
+ return INT2FIX(gpgme_err_source (NUM2LONG(verr)));
190
+ }
191
+
192
+ static VALUE
193
+ rb_s_gpgme_strerror (VALUE dummy, VALUE verr)
194
+ {
195
+ return rb_str_new2 (gpgme_strerror (NUM2LONG(verr)));
196
+ }
197
+
198
+ static VALUE
199
+ rb_s_gpgme_data_new (VALUE dummy, VALUE rdh)
200
+ {
201
+ gpgme_data_t dh;
202
+ gpgme_error_t err = gpgme_data_new (&dh);
203
+
204
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
205
+ rb_ary_store (rdh, 0, WRAP_GPGME_DATA(dh));
206
+ return LONG2NUM(err);
207
+ }
208
+
209
+ static VALUE
210
+ rb_s_gpgme_data_new_from_mem (VALUE dummy, VALUE rdh, VALUE vbuffer,
211
+ VALUE vsize)
212
+ {
213
+ gpgme_data_t dh;
214
+ VALUE vdh;
215
+ size_t size = NUM2UINT(vsize);
216
+ gpgme_error_t err;
217
+
218
+ if (RSTRING_LEN(vbuffer) < size)
219
+ rb_raise (rb_eArgError, "argument out of range");
220
+
221
+ err = gpgme_data_new_from_mem (&dh, StringValuePtr(vbuffer), size, 1);
222
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
223
+ {
224
+ vdh = WRAP_GPGME_DATA(dh);
225
+ rb_ary_store (rdh, 0, vdh);
226
+ }
227
+ return LONG2NUM(err);
228
+ }
229
+
230
+ static VALUE
231
+ rb_s_gpgme_data_new_from_fd (VALUE dummy, VALUE rdh, VALUE vfd)
232
+ {
233
+ gpgme_data_t dh;
234
+ gpgme_error_t err = gpgme_data_new_from_fd (&dh, NUM2INT(vfd));
235
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
236
+ rb_ary_store (rdh, 0, WRAP_GPGME_DATA(dh));
237
+ return LONG2NUM(err);
238
+ }
239
+
240
+ static ssize_t
241
+ read_cb (void *handle, void *buffer, size_t size)
242
+ {
243
+ VALUE vcb = (VALUE)handle, vcbs, vhook_value, vbuffer;
244
+
245
+ vcbs = RARRAY(vcb)->ptr[0];
246
+ vhook_value = RARRAY(vcb)->ptr[1];
247
+
248
+ vbuffer = rb_funcall (vcbs, rb_intern ("read"), 2, vhook_value,
249
+ LONG2NUM(size));
250
+ if (NIL_P(vbuffer))
251
+ return 0;
252
+ memcpy (buffer, StringValuePtr(vbuffer), RSTRING_LEN(vbuffer));
253
+ return RSTRING_LEN(vbuffer);
254
+ }
255
+
256
+ static ssize_t
257
+ write_cb (void *handle, const void *buffer, size_t size)
258
+ {
259
+ VALUE vcb = (VALUE)handle, vcbs, vhook_value, vbuffer, vnwrite;
260
+
261
+ vcbs = RARRAY(vcb)->ptr[0];
262
+ vhook_value = RARRAY(vcb)->ptr[1];
263
+ vbuffer = rb_str_new (buffer, size);
264
+
265
+ vnwrite = rb_funcall (vcbs, rb_intern ("write"), 3,
266
+ vhook_value, vbuffer, LONG2NUM(size));
267
+ return NUM2LONG(vnwrite);
268
+ }
269
+
270
+ static off_t
271
+ seek_cb (void *handle, off_t offset, int whence)
272
+ {
273
+ VALUE vcb = (VALUE)handle, vcbs, vhook_value, vpos;
274
+ ID id_seek = rb_intern ("seek");
275
+
276
+ vcbs = RARRAY(vcb)->ptr[0];
277
+ vhook_value = RARRAY(vcb)->ptr[1];
278
+
279
+ if (rb_respond_to (vcbs, id_seek))
280
+ {
281
+ vpos = rb_funcall (vcbs, id_seek, 3,
282
+ vhook_value, LONG2NUM(offset), INT2FIX(whence));
283
+ return NUM2LONG(vpos);
284
+ }
285
+ errno = ENOSYS;
286
+ return -1;
287
+ }
288
+
289
+ static struct gpgme_data_cbs cbs =
290
+ {
291
+ .read = read_cb,
292
+ .write = write_cb,
293
+ .seek = seek_cb,
294
+ .release = NULL
295
+ };
296
+
297
+ static VALUE
298
+ rb_s_gpgme_data_new_from_cbs (VALUE dummy, VALUE rdh, VALUE vcbs,
299
+ VALUE vhandle)
300
+ {
301
+ gpgme_data_t dh;
302
+ gpgme_error_t err;
303
+ VALUE vcbs_handle = rb_ary_new ();
304
+
305
+ rb_ary_push (vcbs_handle, vcbs);
306
+ rb_ary_push (vcbs_handle, vhandle);
307
+
308
+ err = gpgme_data_new_from_cbs (&dh, &cbs, (void*)vcbs_handle);
309
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
310
+ {
311
+ VALUE vdh = WRAP_GPGME_DATA(dh);
312
+ /* Keep a reference to avoid GC. */
313
+ rb_iv_set (vdh, "@cbs_handle", vcbs_handle);
314
+ rb_ary_store (rdh, 0, vdh);
315
+ }
316
+ return LONG2NUM(err);
317
+ }
318
+
319
+ static VALUE
320
+ rb_s_gpgme_data_read (VALUE dummy, VALUE vdh, VALUE vlength)
321
+ {
322
+ gpgme_data_t dh;
323
+ ssize_t length = NUM2LONG(vlength), nread;
324
+ void *buffer;
325
+ VALUE vbuffer = Qnil;
326
+
327
+ UNWRAP_GPGME_DATA(vdh, dh);
328
+
329
+ buffer = ALLOC_N (char, length);
330
+ nread = gpgme_data_read (dh, buffer, length);
331
+ if (nread > 0)
332
+ vbuffer = rb_str_new (buffer, nread);
333
+ xfree (buffer);
334
+ if (nread < 0)
335
+ rb_sys_fail ("rb_s_gpgme_data_read");
336
+ return vbuffer;
337
+ }
338
+
339
+ static VALUE
340
+ rb_s_gpgme_data_seek (VALUE dummy, VALUE vdh, VALUE voffset, VALUE vwhence)
341
+ {
342
+ gpgme_data_t dh;
343
+ off_t pos;
344
+
345
+ UNWRAP_GPGME_DATA(vdh, dh);
346
+ pos = gpgme_data_seek (dh, NUM2LONG(voffset), NUM2INT(vwhence));
347
+ if (pos < 0)
348
+ rb_sys_fail ("rb_s_gpgme_data_seek");
349
+ return LONG2NUM(pos);
350
+ }
351
+
352
+ static VALUE
353
+ rb_s_gpgme_data_write (VALUE dummy, VALUE vdh, VALUE vbuf, VALUE vlen)
354
+ {
355
+ gpgme_data_t dh;
356
+ ssize_t nwrite;
357
+
358
+ UNWRAP_GPGME_DATA(vdh, dh);
359
+ nwrite = gpgme_data_write (dh, StringValuePtr(vbuf), NUM2UINT(vlen));
360
+ if (nwrite < 0)
361
+ rb_sys_fail ("rb_s_gpgme_data_write");
362
+ return LONG2NUM(nwrite);
363
+ }
364
+
365
+ static VALUE
366
+ rb_s_gpgme_data_get_encoding (VALUE dummy, VALUE vdh)
367
+ {
368
+ gpgme_data_t dh;
369
+ gpgme_error_t err;
370
+
371
+ UNWRAP_GPGME_DATA(vdh, dh);
372
+ err = gpgme_data_get_encoding (dh);
373
+ return LONG2NUM(err);
374
+ }
375
+
376
+ static VALUE
377
+ rb_s_gpgme_data_set_encoding (VALUE dummy, VALUE vdh, VALUE venc)
378
+ {
379
+ gpgme_data_t dh;
380
+ gpgme_error_t err;
381
+
382
+ UNWRAP_GPGME_DATA(vdh, dh);
383
+ err = gpgme_data_set_encoding (dh, NUM2INT(venc));
384
+ return LONG2NUM(err);
385
+ }
386
+
387
+ static VALUE
388
+ rb_s_gpgme_new (VALUE dummy, VALUE rctx)
389
+ {
390
+ gpgme_ctx_t ctx;
391
+ gpgme_error_t err = gpgme_new (&ctx);
392
+
393
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
394
+ rb_ary_store (rctx, 0, WRAP_GPGME_CTX(ctx));
395
+ return LONG2NUM(err);
396
+ }
397
+
398
+ static VALUE
399
+ rb_s_gpgme_set_protocol (VALUE dummy, VALUE vctx, VALUE vproto)
400
+ {
401
+ gpgme_ctx_t ctx;
402
+ gpgme_error_t err;
403
+
404
+ UNWRAP_GPGME_CTX(vctx, ctx);
405
+ err = gpgme_set_protocol (ctx, NUM2INT(vproto));
406
+ return LONG2NUM(err);
407
+ }
408
+
409
+ static VALUE
410
+ rb_s_gpgme_get_protocol (VALUE dummy, VALUE vctx)
411
+ {
412
+ gpgme_ctx_t ctx;
413
+ gpgme_protocol_t proto;
414
+
415
+ UNWRAP_GPGME_CTX(vctx, ctx);
416
+ proto = gpgme_get_protocol (ctx);
417
+ return INT2FIX(proto);
418
+ }
419
+
420
+ static VALUE
421
+ rb_s_gpgme_set_armor (VALUE dummy, VALUE vctx, VALUE vyes)
422
+ {
423
+ gpgme_ctx_t ctx;
424
+
425
+ UNWRAP_GPGME_CTX(vctx, ctx);
426
+ gpgme_set_armor (ctx, NUM2INT(vyes));
427
+
428
+ return Qnil;
429
+ }
430
+
431
+ static VALUE
432
+ rb_s_gpgme_get_armor (VALUE dummy, VALUE vctx)
433
+ {
434
+ gpgme_ctx_t ctx;
435
+ int yes;
436
+
437
+ UNWRAP_GPGME_CTX(vctx, ctx);
438
+ yes = gpgme_get_armor (ctx);
439
+ return INT2FIX(yes);
440
+ }
441
+
442
+ static VALUE
443
+ rb_s_gpgme_set_textmode (VALUE dummy, VALUE vctx, VALUE vyes)
444
+ {
445
+ gpgme_ctx_t ctx;
446
+
447
+ UNWRAP_GPGME_CTX(vctx, ctx);
448
+ gpgme_set_textmode (ctx, NUM2INT(vyes));
449
+ return Qnil;
450
+ }
451
+
452
+ static VALUE
453
+ rb_s_gpgme_get_textmode (VALUE dummy, VALUE vctx)
454
+ {
455
+ gpgme_ctx_t ctx;
456
+ int yes;
457
+
458
+ UNWRAP_GPGME_CTX(vctx, ctx);
459
+ yes = gpgme_get_textmode (ctx);
460
+ return INT2FIX(yes);
461
+ }
462
+
463
+ static VALUE
464
+ rb_s_gpgme_set_include_certs (VALUE dummy, VALUE vctx, VALUE vnr_of_certs)
465
+ {
466
+ gpgme_ctx_t ctx;
467
+
468
+ UNWRAP_GPGME_CTX(vctx, ctx);
469
+ gpgme_set_include_certs (ctx, NUM2INT(vnr_of_certs));
470
+ return Qnil;
471
+ }
472
+
473
+ static VALUE
474
+ rb_s_gpgme_get_include_certs (VALUE dummy, VALUE vctx)
475
+ {
476
+ gpgme_ctx_t ctx;
477
+ gpgme_error_t err;
478
+
479
+ UNWRAP_GPGME_CTX(vctx, ctx);
480
+ err = gpgme_get_include_certs (ctx);
481
+ return LONG2NUM(err);
482
+ }
483
+
484
+ static VALUE
485
+ rb_s_gpgme_set_keylist_mode (VALUE dummy, VALUE vctx, VALUE vmode)
486
+ {
487
+ gpgme_ctx_t ctx;
488
+ gpgme_error_t err;
489
+
490
+ UNWRAP_GPGME_CTX(vctx, ctx);
491
+ err = gpgme_set_keylist_mode (ctx, NUM2INT(vmode));
492
+ return LONG2NUM(err);
493
+ }
494
+
495
+ static VALUE
496
+ rb_s_gpgme_get_keylist_mode (VALUE dummy, VALUE vctx)
497
+ {
498
+ gpgme_ctx_t ctx;
499
+ int mode;
500
+
501
+ UNWRAP_GPGME_CTX(vctx, ctx);
502
+ mode = gpgme_get_keylist_mode (ctx);
503
+ return INT2FIX(mode);
504
+ }
505
+
506
+ static gpgme_error_t
507
+ passphrase_cb (void *hook, const char *uid_hint, const char *passphrase_info,
508
+ int prev_was_bad, int fd)
509
+ {
510
+ VALUE vcb = (VALUE)hook, vpassfunc, vhook_value;
511
+
512
+ vpassfunc = RARRAY(vcb)->ptr[0];
513
+ vhook_value = RARRAY(vcb)->ptr[1];
514
+
515
+ rb_funcall (vpassfunc, rb_intern ("call"), 5,
516
+ vhook_value,
517
+ uid_hint ? rb_str_new2 (uid_hint) : Qnil,
518
+ passphrase_info ? rb_str_new2 (passphrase_info) : Qnil,
519
+ INT2FIX(prev_was_bad),
520
+ INT2NUM(fd));
521
+ return gpgme_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_NO_ERROR);
522
+ }
523
+
524
+ static VALUE
525
+ rb_s_gpgme_set_passphrase_cb (VALUE dummy, VALUE vctx, VALUE vpassfunc,
526
+ VALUE vhook_value)
527
+ {
528
+ gpgme_ctx_t ctx;
529
+ VALUE vcb = rb_ary_new ();
530
+
531
+ rb_ary_push (vcb, vpassfunc);
532
+ rb_ary_push (vcb, vhook_value);
533
+ /* Keep a reference to avoid GC. */
534
+ rb_iv_set (vctx, "@passphrase_cb", vcb);
535
+
536
+ UNWRAP_GPGME_CTX(vctx, ctx);
537
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, (void*)vcb);
538
+ return Qnil;
539
+ }
540
+
541
+ static VALUE
542
+ rb_s_gpgme_get_passphrase_cb (VALUE dummy, VALUE vctx, VALUE rpassfunc,
543
+ VALUE rhook_value)
544
+ {
545
+ VALUE vcb = rb_iv_get (vctx, "@passphrase_cb");
546
+
547
+ /* No need to call gpgme_get_passphrase_cb. */
548
+ rb_ary_store (rpassfunc, 0, RARRAY(vcb)->ptr[0]);
549
+ rb_ary_store (rhook_value, 0, RARRAY(vcb)->ptr[1]);
550
+ return Qnil;
551
+ }
552
+
553
+ static void
554
+ progress_cb (void *hook, const char *what, int type, int current, int total)
555
+ {
556
+ VALUE vcb = (VALUE)hook, vprogfunc, vhook_value;
557
+
558
+ vprogfunc = RARRAY(vcb)->ptr[0];
559
+ vhook_value = RARRAY(vcb)->ptr[1];
560
+
561
+ rb_funcall (vprogfunc, rb_intern ("call"), 5, vhook_value,
562
+ rb_str_new2 (what), INT2NUM(type), INT2NUM(current),
563
+ INT2NUM(total));
564
+ }
565
+
566
+ static VALUE
567
+ rb_s_gpgme_set_progress_cb (VALUE dummy, VALUE vctx, VALUE vprogfunc,
568
+ VALUE vhook_value)
569
+ {
570
+ gpgme_ctx_t ctx;
571
+ VALUE vcb = rb_ary_new ();
572
+
573
+ rb_ary_push (vcb, vprogfunc);
574
+ rb_ary_push (vcb, vhook_value);
575
+ /* Keep a reference to avoid GC. */
576
+ rb_iv_set (vctx, "@progress_cb", vcb);
577
+
578
+ UNWRAP_GPGME_CTX(vctx, ctx);
579
+ gpgme_set_progress_cb (ctx, progress_cb, (void*)vcb);
580
+
581
+ return Qnil;
582
+ }
583
+
584
+ static VALUE
585
+ rb_s_gpgme_get_progress_cb (VALUE dummy, VALUE vctx, VALUE rprogfunc,
586
+ VALUE rhook_value)
587
+ {
588
+ VALUE vcb = rb_iv_get (vctx, "@progress_cb");
589
+ rb_ary_store (rprogfunc, 0, RARRAY(vcb)->ptr[0]);
590
+ rb_ary_store (rhook_value, 0, RARRAY(vcb)->ptr[1]);
591
+ return Qnil;
592
+ }
593
+
594
+ static VALUE
595
+ rb_s_gpgme_set_locale (VALUE dummy, VALUE vctx, VALUE vcategory, VALUE vvalue)
596
+ {
597
+ gpgme_ctx_t ctx;
598
+ gpgme_error_t err;
599
+
600
+ UNWRAP_GPGME_CTX(vctx, ctx);
601
+
602
+ err = gpgme_set_locale (ctx, NUM2INT(vcategory), StringValueCStr(vvalue));
603
+ return LONG2NUM(err);
604
+ }
605
+
606
+ static VALUE
607
+ rb_s_gpgme_op_keylist_start (VALUE dummy, VALUE vctx, VALUE vpattern,
608
+ VALUE vsecret_only)
609
+ {
610
+ gpgme_ctx_t ctx;
611
+ gpgme_error_t err;
612
+
613
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
614
+
615
+ UNWRAP_GPGME_CTX(vctx, ctx);
616
+
617
+ err = gpgme_op_keylist_start (ctx, NIL_P(vpattern) ? NULL :
618
+ StringValueCStr(vpattern),
619
+ NUM2INT(vsecret_only));
620
+ if (gpgme_err_code (err) == GPG_ERR_NO_ERROR)
621
+ SET_KEYLIST_IN_PROGRESS(vctx);
622
+ return LONG2NUM(err);
623
+ }
624
+
625
+ static VALUE
626
+ rb_s_gpgme_op_keylist_ext_start (VALUE dummy, VALUE vctx, VALUE vpattern,
627
+ VALUE vsecret_only)
628
+ {
629
+ gpgme_ctx_t ctx;
630
+ const char **pattern = NULL;
631
+ int i, err;
632
+
633
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
634
+
635
+ UNWRAP_GPGME_CTX(vctx, ctx);
636
+
637
+ if (!NIL_P(vpattern))
638
+ {
639
+ /* Convert RARRAY into `const char *' array. */
640
+ pattern = ALLOC_N(const char *, RARRAY_LEN(vpattern) + 1);
641
+ for (i = 0; i<RARRAY_LEN(vpattern); i++)
642
+ pattern[i] = StringValueCStr(RARRAY_PTR(vpattern)[i]);
643
+ pattern[RARRAY_LEN(vpattern)] = NULL;
644
+ }
645
+
646
+ err = gpgme_op_keylist_ext_start (ctx, pattern, NUM2INT(vsecret_only), 0);
647
+ if (gpgme_err_code (err) == GPG_ERR_NO_ERROR)
648
+ SET_KEYLIST_IN_PROGRESS(vctx);
649
+ if (pattern)
650
+ xfree (pattern);
651
+ return LONG2NUM(err);
652
+ }
653
+
654
+ static VALUE
655
+ save_gpgme_key_attrs (VALUE vkey, gpgme_key_t key)
656
+ {
657
+ VALUE vsubkeys, vuids;
658
+ gpgme_subkey_t subkey;
659
+ gpgme_user_id_t user_id;
660
+
661
+ rb_iv_set (vkey, "@keylist_mode", INT2FIX(key->keylist_mode));
662
+ rb_iv_set (vkey, "@revoked", INT2FIX(key->revoked));
663
+ rb_iv_set (vkey, "@expired", INT2FIX(key->expired));
664
+ rb_iv_set (vkey, "@disabled", INT2FIX(key->disabled));
665
+ rb_iv_set (vkey, "@invalid", INT2FIX(key->invalid));
666
+ rb_iv_set (vkey, "@can_encrypt", INT2FIX(key->can_encrypt));
667
+ rb_iv_set (vkey, "@can_sign", INT2FIX(key->can_sign));
668
+ rb_iv_set (vkey, "@can_certify", INT2FIX(key->can_certify));
669
+ rb_iv_set (vkey, "@can_authenticate", INT2FIX(key->can_authenticate));
670
+ rb_iv_set (vkey, "@secret", INT2FIX(key->secret));
671
+ rb_iv_set (vkey, "@protocol", INT2FIX(key->protocol));
672
+ if (key->issuer_serial)
673
+ rb_iv_set (vkey, "@issuer_serial", rb_str_new2 (key->issuer_serial));
674
+ if (key->issuer_name)
675
+ rb_iv_set (vkey, "@issuer_name", rb_str_new2 (key->issuer_name));
676
+ if (key->chain_id)
677
+ rb_iv_set (vkey, "@chain_id", rb_str_new2 (key->chain_id));
678
+ rb_iv_set (vkey, "@owner_trust", INT2FIX(key->owner_trust));
679
+ vsubkeys = rb_ary_new ();
680
+ rb_iv_set (vkey, "@subkeys", vsubkeys);
681
+ for (subkey = key->subkeys; subkey; subkey = subkey->next)
682
+ {
683
+ VALUE vsubkey = rb_class_new_instance(0, NULL, cSubKey);
684
+ rb_iv_set (vsubkey, "@revoked", INT2FIX(subkey->revoked));
685
+ rb_iv_set (vsubkey, "@expired", INT2FIX(subkey->expired));
686
+ rb_iv_set (vsubkey, "@disabled", INT2FIX(subkey->disabled));
687
+ rb_iv_set (vsubkey, "@invalid", INT2FIX(subkey->invalid));
688
+ rb_iv_set (vsubkey, "@can_encrypt", INT2FIX(subkey->can_encrypt));
689
+ rb_iv_set (vsubkey, "@can_sign", INT2FIX(subkey->can_sign));
690
+ rb_iv_set (vsubkey, "@can_certify", INT2FIX(subkey->can_certify));
691
+ rb_iv_set (vsubkey, "@can_authenticate",
692
+ INT2FIX(subkey->can_authenticate));
693
+ rb_iv_set (vsubkey, "@secret", INT2FIX(subkey->secret));
694
+ rb_iv_set (vsubkey, "@pubkey_algo", INT2FIX(subkey->pubkey_algo));
695
+ rb_iv_set (vsubkey, "@length", UINT2NUM(subkey->length));
696
+ rb_iv_set (vsubkey, "@keyid", rb_str_new2 (subkey->keyid));
697
+ if (subkey->fpr)
698
+ rb_iv_set (vsubkey, "@fpr", rb_str_new2 (subkey->fpr));
699
+ rb_iv_set (vsubkey, "@timestamp", LONG2NUM(subkey->timestamp));
700
+ rb_iv_set (vsubkey, "@expires", LONG2NUM(subkey->expires));
701
+ rb_ary_push (vsubkeys, vsubkey);
702
+ }
703
+ vuids = rb_ary_new ();
704
+ rb_iv_set (vkey, "@uids", vuids);
705
+ for (user_id = key->uids; user_id; user_id = user_id->next)
706
+ {
707
+ VALUE vuser_id = rb_class_new_instance(0, NULL, cUserID), vsignatures;
708
+ rb_iv_set (vuser_id, "@revoked", INT2FIX(user_id->revoked));
709
+ rb_iv_set (vuser_id, "@invalid", INT2FIX(user_id->invalid));
710
+ rb_iv_set (vuser_id, "@validity", INT2FIX(user_id->validity));
711
+ rb_iv_set (vuser_id, "@uid", rb_str_new2 (user_id->uid));
712
+ rb_iv_set (vuser_id, "@name", rb_str_new2 (user_id->name));
713
+ rb_iv_set (vuser_id, "@comment", rb_str_new2 (user_id->comment));
714
+ rb_iv_set (vuser_id, "@email", rb_str_new2 (user_id->email));
715
+
716
+ vsignatures = rb_ary_new ();
717
+ rb_iv_set (vuser_id, "@signatures", vsignatures);
718
+ gpgme_key_sig_t key_sig;
719
+ for (key_sig = user_id->signatures; key_sig; key_sig = key_sig->next)
720
+ {
721
+ VALUE vkey_sig = rb_class_new_instance(0, NULL, cKeySig);
722
+ rb_iv_set (vkey_sig, "@revoked", INT2FIX(key_sig->revoked));
723
+ rb_iv_set (vkey_sig, "@expired", INT2FIX(key_sig->expired));
724
+ rb_iv_set (vkey_sig, "@invalid", INT2FIX(key_sig->invalid));
725
+ rb_iv_set (vkey_sig, "@exportable", INT2FIX(key_sig->exportable));
726
+ rb_iv_set (vkey_sig, "@pubkey_algo", INT2FIX(key_sig->pubkey_algo));
727
+ rb_iv_set (vkey_sig, "@keyid", rb_str_new2 (key_sig->keyid));
728
+ rb_iv_set (vkey_sig, "@timestamp", LONG2NUM(key_sig->timestamp));
729
+ rb_iv_set (vkey_sig, "@expires", LONG2NUM(key_sig->expires));
730
+ rb_ary_push (vsignatures, vkey_sig);
731
+ }
732
+ rb_ary_push (vuids, vuser_id);
733
+ }
734
+ return vkey;
735
+ }
736
+
737
+ static VALUE
738
+ rb_s_gpgme_op_keylist_next (VALUE dummy, VALUE vctx, VALUE rkey)
739
+ {
740
+ gpgme_ctx_t ctx;
741
+ gpgme_key_t key;
742
+ gpgme_error_t err;
743
+
744
+ CHECK_KEYLIST_IN_PROGRESS(vctx);
745
+
746
+ UNWRAP_GPGME_CTX(vctx, ctx);
747
+
748
+ err = gpgme_op_keylist_next (ctx, &key);
749
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
750
+ {
751
+ VALUE vkey = WRAP_GPGME_KEY(key);
752
+ save_gpgme_key_attrs (vkey, key);
753
+ rb_ary_store (rkey, 0, vkey);
754
+ }
755
+ return LONG2NUM(err);
756
+ }
757
+
758
+ static VALUE
759
+ rb_s_gpgme_op_keylist_end (VALUE dummy, VALUE vctx)
760
+ {
761
+ gpgme_ctx_t ctx;
762
+ gpgme_error_t err;
763
+
764
+ CHECK_KEYLIST_IN_PROGRESS(vctx);
765
+
766
+ UNWRAP_GPGME_CTX(vctx, ctx);
767
+
768
+ err = gpgme_op_keylist_end (ctx);
769
+ RESET_KEYLIST_IN_PROGRESS(vctx);
770
+ return LONG2NUM(err);
771
+ }
772
+
773
+ static VALUE
774
+ rb_s_gpgme_get_key (VALUE dummy, VALUE vctx, VALUE vfpr, VALUE rkey,
775
+ VALUE vsecret)
776
+ {
777
+ gpgme_ctx_t ctx;
778
+ gpgme_error_t err;
779
+ gpgme_key_t key;
780
+
781
+ UNWRAP_GPGME_CTX(vctx, ctx);
782
+ err = gpgme_get_key (ctx, StringValueCStr(vfpr), &key, NUM2INT(vsecret));
783
+
784
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
785
+ {
786
+ VALUE vkey = WRAP_GPGME_KEY(key);
787
+ save_gpgme_key_attrs (vkey, key);
788
+ rb_ary_store (rkey, 0, vkey);
789
+ }
790
+ return LONG2NUM(err);
791
+ }
792
+
793
+ static VALUE
794
+ rb_s_gpgme_key_ref (VALUE dummy, VALUE vkey)
795
+ {
796
+ gpgme_key_t key;
797
+
798
+ UNWRAP_GPGME_KEY(vkey, key);
799
+ gpgme_key_ref (key);
800
+ return Qnil;
801
+ }
802
+
803
+ static VALUE
804
+ rb_s_gpgme_key_unref (VALUE dummy, VALUE vkey)
805
+ {
806
+ gpgme_key_t key;
807
+
808
+ UNWRAP_GPGME_KEY(vkey, key);
809
+ gpgme_key_unref (key);
810
+ return Qnil;
811
+ }
812
+
813
+ static VALUE
814
+ rb_s_gpgme_op_genkey (VALUE dummy, VALUE vctx, VALUE vparms, VALUE vpubkey,
815
+ VALUE vseckey)
816
+ {
817
+ gpgme_ctx_t ctx;
818
+ gpgme_data_t pubkey = NULL, seckey = NULL;
819
+ gpgme_error_t err;
820
+
821
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
822
+
823
+ UNWRAP_GPGME_CTX(vctx, ctx);
824
+ if (!NIL_P(vpubkey))
825
+ UNWRAP_GPGME_DATA(vpubkey, pubkey);
826
+ if (!NIL_P(vseckey))
827
+ UNWRAP_GPGME_DATA(vseckey, seckey);
828
+
829
+ err = gpgme_op_genkey (ctx, StringValueCStr(vparms), pubkey, seckey);
830
+ return LONG2NUM(err);
831
+ }
832
+
833
+ static VALUE
834
+ rb_s_gpgme_op_genkey_start (VALUE dummy, VALUE vctx, VALUE vparms,
835
+ VALUE vpubkey, VALUE vseckey)
836
+ {
837
+ gpgme_ctx_t ctx;
838
+ gpgme_data_t pubkey = NULL, seckey = NULL;
839
+ gpgme_error_t err;
840
+
841
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
842
+
843
+ UNWRAP_GPGME_CTX(vctx, ctx);
844
+ if (!NIL_P(vpubkey))
845
+ UNWRAP_GPGME_DATA(vpubkey, pubkey);
846
+ if (!NIL_P(vseckey))
847
+ UNWRAP_GPGME_DATA(vseckey, seckey);
848
+
849
+ err = gpgme_op_genkey_start (ctx, StringValueCStr(vparms), pubkey, seckey);
850
+ return LONG2NUM(err);
851
+ }
852
+
853
+ static VALUE
854
+ rb_s_gpgme_op_export (VALUE dummy, VALUE vctx, VALUE vpattern, VALUE vreserved,
855
+ VALUE vkeydata)
856
+ {
857
+ gpgme_ctx_t ctx;
858
+ gpgme_data_t keydata;
859
+ gpgme_error_t err;
860
+
861
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
862
+
863
+ UNWRAP_GPGME_CTX(vctx, ctx);
864
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
865
+
866
+ err = gpgme_op_export (ctx, StringValueCStr(vpattern), NUM2UINT(vreserved),
867
+ keydata);
868
+ return LONG2NUM(err);
869
+ }
870
+
871
+ static VALUE
872
+ rb_s_gpgme_op_export_start (VALUE dummy, VALUE vctx, VALUE vpattern,
873
+ VALUE vreserved, VALUE vkeydata)
874
+ {
875
+ gpgme_ctx_t ctx;
876
+ gpgme_data_t keydata;
877
+ gpgme_error_t err;
878
+
879
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
880
+
881
+ UNWRAP_GPGME_CTX(vctx, ctx);
882
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
883
+
884
+ err = gpgme_op_export_start (ctx, StringValueCStr(vpattern),
885
+ NUM2UINT(vreserved), keydata);
886
+ return LONG2NUM(err);
887
+ }
888
+
889
+ static VALUE
890
+ rb_s_gpgme_op_import (VALUE dummy, VALUE vctx, VALUE vkeydata)
891
+ {
892
+ gpgme_ctx_t ctx;
893
+ gpgme_data_t keydata;
894
+ gpgme_error_t err;
895
+
896
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
897
+
898
+ UNWRAP_GPGME_CTX(vctx, ctx);
899
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
900
+
901
+ err = gpgme_op_import (ctx, keydata);
902
+ return LONG2NUM(err);
903
+ }
904
+
905
+ static VALUE
906
+ rb_s_gpgme_op_import_start (VALUE dummy, VALUE vctx, VALUE vkeydata)
907
+ {
908
+ gpgme_ctx_t ctx;
909
+ gpgme_data_t keydata;
910
+ gpgme_error_t err;
911
+
912
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
913
+
914
+ UNWRAP_GPGME_CTX(vctx, ctx);
915
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
916
+
917
+ err = gpgme_op_import_start (ctx, keydata);
918
+ return LONG2NUM(err);
919
+ }
920
+
921
+ static VALUE
922
+ rb_s_gpgme_op_import_result (VALUE dummy, VALUE vctx)
923
+ {
924
+ gpgme_ctx_t ctx;
925
+ gpgme_import_result_t result;
926
+ gpgme_import_status_t status;
927
+ VALUE vresult, vimports;
928
+
929
+ UNWRAP_GPGME_CTX(vctx, ctx);
930
+
931
+ result = gpgme_op_import_result (ctx);
932
+ vresult = rb_class_new_instance (0, NULL, cImportResult);
933
+ rb_iv_set (vresult, "@considered", INT2NUM(result->considered));
934
+ rb_iv_set (vresult, "@no_user_id", INT2NUM(result->no_user_id));
935
+ rb_iv_set (vresult, "@imported", INT2NUM(result->imported));
936
+ rb_iv_set (vresult, "@imported_rsa", INT2NUM(result->imported_rsa));
937
+ rb_iv_set (vresult, "@unchanged", INT2NUM(result->unchanged));
938
+ rb_iv_set (vresult, "@new_user_ids", INT2NUM(result->new_user_ids));
939
+ rb_iv_set (vresult, "@new_sub_keys", INT2NUM(result->new_sub_keys));
940
+ rb_iv_set (vresult, "@new_signatures", INT2NUM(result->new_signatures));
941
+ rb_iv_set (vresult, "@new_revocations", INT2NUM(result->new_revocations));
942
+ rb_iv_set (vresult, "@secret_read", INT2NUM(result->secret_read));
943
+ rb_iv_set (vresult, "@secret_imported", INT2NUM(result->secret_imported));
944
+ rb_iv_set (vresult, "@secret_unchanged", INT2NUM(result->secret_unchanged));
945
+ rb_iv_set (vresult, "@not_imported", INT2NUM(result->not_imported));
946
+ vimports = rb_ary_new ();
947
+ rb_iv_set (vresult, "@imports", vimports);
948
+ for (status = result->imports; status;
949
+ status = status->next)
950
+ {
951
+ VALUE vstatus =
952
+ rb_class_new_instance (0, NULL, cImportStatus);
953
+ rb_iv_set (vstatus, "@fpr", rb_str_new2 (status->fpr));
954
+ rb_iv_set (vstatus, "@result", LONG2NUM(status->result));
955
+ rb_iv_set (vstatus, "@status", UINT2NUM(status->status));
956
+ rb_ary_push (vimports, vstatus);
957
+ }
958
+ return vresult;
959
+ }
960
+
961
+ static VALUE
962
+ rb_s_gpgme_op_delete (VALUE dummy, VALUE vctx, VALUE vkey, VALUE vallow_secret)
963
+ {
964
+ gpgme_ctx_t ctx;
965
+ gpgme_key_t key;
966
+ gpgme_error_t err;
967
+
968
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
969
+
970
+ UNWRAP_GPGME_CTX(vctx, ctx);
971
+ UNWRAP_GPGME_KEY(vkey, key);
972
+
973
+ err = gpgme_op_delete (ctx, key, NUM2INT(vallow_secret));
974
+ return LONG2NUM(err);
975
+ }
976
+
977
+ static VALUE
978
+ rb_s_gpgme_op_delete_start (VALUE dummy, VALUE vctx, VALUE vkey,
979
+ VALUE vallow_secret)
980
+ {
981
+ gpgme_ctx_t ctx;
982
+ gpgme_key_t key;
983
+ gpgme_error_t err;
984
+
985
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
986
+
987
+ UNWRAP_GPGME_CTX(vctx, ctx);
988
+ UNWRAP_GPGME_KEY(vkey, key);
989
+
990
+ err = gpgme_op_delete_start (ctx, key, NUM2INT(vallow_secret));
991
+ return LONG2NUM(err);
992
+ }
993
+
994
+ static VALUE
995
+ rb_s_gpgme_op_trustlist_start (VALUE dummy, VALUE vctx, VALUE vpattern,
996
+ VALUE vmax_level)
997
+ {
998
+ gpgme_ctx_t ctx;
999
+ gpgme_error_t err;
1000
+
1001
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1002
+
1003
+ UNWRAP_GPGME_CTX(vctx, ctx);
1004
+ err = gpgme_op_trustlist_start (ctx, StringValueCStr(vpattern),
1005
+ NUM2INT(vmax_level));
1006
+ return LONG2NUM(err);
1007
+ }
1008
+
1009
+ static VALUE
1010
+ rb_s_gpgme_op_trustlist_next (VALUE dummy, VALUE vctx, VALUE ritem)
1011
+ {
1012
+ gpgme_ctx_t ctx;
1013
+ gpgme_trust_item_t item;
1014
+ gpgme_error_t err;
1015
+ VALUE vitem;
1016
+
1017
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1018
+
1019
+ UNWRAP_GPGME_CTX(vctx, ctx);
1020
+
1021
+ err = gpgme_op_trustlist_next (ctx, &item);
1022
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
1023
+ {
1024
+ vitem = WRAP_GPGME_TRUST_ITEM(item);
1025
+ rb_iv_set (vitem, "@keyid", rb_str_new2 (item->keyid));
1026
+ rb_iv_set (vitem, "@type", INT2FIX(item->type));
1027
+ rb_iv_set (vitem, "@level", INT2FIX(item->level));
1028
+ if (item->owner_trust)
1029
+ rb_iv_set (vitem, "@owner_trust", rb_str_new2 (item->owner_trust));
1030
+ rb_iv_set (vitem, "@validity", rb_str_new2 (item->validity));
1031
+ if (item->name)
1032
+ rb_iv_set (vitem, "@name", rb_str_new2 (item->name));
1033
+ rb_ary_store (ritem, 0, vitem);
1034
+ }
1035
+ return LONG2NUM(err);
1036
+ }
1037
+
1038
+ static VALUE
1039
+ rb_s_gpgme_op_trustlist_end (VALUE dummy, VALUE vctx)
1040
+ {
1041
+ gpgme_ctx_t ctx;
1042
+ gpgme_error_t err;
1043
+
1044
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1045
+
1046
+ UNWRAP_GPGME_CTX(vctx, ctx);
1047
+
1048
+ err = gpgme_op_trustlist_end (ctx);
1049
+ return LONG2NUM(err);
1050
+ }
1051
+
1052
+ static VALUE
1053
+ rb_s_gpgme_op_decrypt (VALUE dummy, VALUE vctx, VALUE vcipher, VALUE vplain)
1054
+ {
1055
+ gpgme_ctx_t ctx;
1056
+ gpgme_data_t cipher, plain;
1057
+ gpgme_error_t err;
1058
+
1059
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1060
+
1061
+ UNWRAP_GPGME_CTX(vctx, ctx);
1062
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1063
+ UNWRAP_GPGME_DATA(vplain, plain);
1064
+
1065
+ err = gpgme_op_decrypt (ctx, cipher, plain);
1066
+ return LONG2NUM(err);
1067
+ }
1068
+
1069
+ static VALUE
1070
+ rb_s_gpgme_op_decrypt_start (VALUE dummy, VALUE vctx, VALUE vcipher,
1071
+ VALUE vplain)
1072
+ {
1073
+ gpgme_ctx_t ctx;
1074
+ gpgme_data_t cipher, plain;
1075
+ gpgme_error_t err;
1076
+
1077
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1078
+
1079
+ UNWRAP_GPGME_CTX(vctx, ctx);
1080
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1081
+ UNWRAP_GPGME_DATA(vplain, plain);
1082
+
1083
+ err = gpgme_op_decrypt_start (ctx, cipher, plain);
1084
+ return LONG2NUM(err);
1085
+ }
1086
+
1087
+ static VALUE
1088
+ rb_s_gpgme_op_decrypt_result (VALUE dummy, VALUE vctx)
1089
+ {
1090
+ gpgme_ctx_t ctx;
1091
+ gpgme_decrypt_result_t result;
1092
+ VALUE vresult;
1093
+
1094
+ UNWRAP_GPGME_CTX(vctx, ctx);
1095
+
1096
+ result = gpgme_op_decrypt_result (ctx);
1097
+ vresult = rb_class_new_instance (0, NULL, cDecryptResult);
1098
+ if (result->unsupported_algorithm)
1099
+ rb_iv_set (vresult, "@unsupported_algorithm",
1100
+ rb_str_new2 (result->unsupported_algorithm));
1101
+ rb_iv_set (vresult, "@wrong_key_usage", INT2FIX(result->wrong_key_usage));
1102
+ return vresult;
1103
+ }
1104
+
1105
+ static VALUE
1106
+ rb_s_gpgme_op_verify (VALUE dummy, VALUE vctx, VALUE vsig, VALUE vsigned_text,
1107
+ VALUE vplain)
1108
+ {
1109
+ gpgme_ctx_t ctx;
1110
+ gpgme_data_t sig, signed_text = NULL, plain = NULL;
1111
+ gpgme_error_t err;
1112
+
1113
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1114
+
1115
+ UNWRAP_GPGME_CTX(vctx, ctx);
1116
+ UNWRAP_GPGME_DATA(vsig, sig);
1117
+ if (!NIL_P(vsigned_text))
1118
+ UNWRAP_GPGME_DATA(vsigned_text, signed_text);
1119
+ if (!NIL_P(vplain))
1120
+ UNWRAP_GPGME_DATA(vplain, plain);
1121
+
1122
+ err = gpgme_op_verify (ctx, sig, signed_text, plain);
1123
+ return LONG2NUM(err);
1124
+ }
1125
+
1126
+ static VALUE
1127
+ rb_s_gpgme_op_verify_start (VALUE dummy, VALUE vctx, VALUE vsig,
1128
+ VALUE vsigned_text, VALUE vplain)
1129
+ {
1130
+ gpgme_ctx_t ctx;
1131
+ gpgme_data_t sig, signed_text = NULL, plain = NULL;
1132
+ gpgme_error_t err;
1133
+
1134
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1135
+
1136
+ UNWRAP_GPGME_CTX(vctx, ctx);
1137
+ UNWRAP_GPGME_DATA(vsig, sig);
1138
+ if (!NIL_P(vsigned_text))
1139
+ UNWRAP_GPGME_DATA(vsigned_text, signed_text);
1140
+ if (!NIL_P(vplain))
1141
+ UNWRAP_GPGME_DATA(vplain, plain);
1142
+
1143
+ err = gpgme_op_verify_start (ctx, sig, signed_text, plain);
1144
+ return LONG2NUM(err);
1145
+ }
1146
+
1147
+ static VALUE
1148
+ rb_s_gpgme_op_verify_result (VALUE dummy, VALUE vctx)
1149
+ {
1150
+ gpgme_ctx_t ctx;
1151
+ gpgme_verify_result_t verify_result;
1152
+ gpgme_signature_t signature;
1153
+ VALUE vverify_result, vsignatures = rb_ary_new ();
1154
+
1155
+ UNWRAP_GPGME_CTX(vctx, ctx);
1156
+
1157
+ verify_result = gpgme_op_verify_result (ctx);
1158
+ vverify_result = rb_class_new_instance(0, NULL, cVerifyResult);
1159
+ rb_iv_set (vverify_result, "@signatures", vsignatures);
1160
+ for (signature = verify_result->signatures; signature;
1161
+ signature = signature->next)
1162
+ {
1163
+ VALUE vsignature = rb_class_new_instance(0, NULL, cSignature),
1164
+ vnotations = rb_ary_new ();
1165
+ gpgme_sig_notation_t notation;
1166
+ rb_iv_set (vsignature, "@summary", INT2FIX(signature->summary));
1167
+ rb_iv_set (vsignature, "@fpr", rb_str_new2 (signature->fpr));
1168
+ rb_iv_set (vsignature, "@status", LONG2NUM(signature->status));
1169
+ rb_iv_set (vsignature, "@notations", vnotations);
1170
+ for (notation = signature->notations; notation;
1171
+ notation = notation->next)
1172
+ {
1173
+ VALUE vnotation = rb_class_new_instance(0, NULL, cSigNotation);
1174
+ rb_iv_set (vnotation, "@name", rb_str_new2 (notation->name));
1175
+ rb_iv_set (vnotation, "@value", rb_str_new2 (notation->value));
1176
+ rb_ary_push (vnotations, vnotation);
1177
+ }
1178
+ rb_iv_set (vsignature, "@timestamp", ULONG2NUM(signature->timestamp));
1179
+ rb_iv_set (vsignature, "@exp_timestamp",
1180
+ ULONG2NUM(signature->exp_timestamp));
1181
+ rb_iv_set (vsignature, "@wrong_key_usage",
1182
+ INT2FIX(signature->wrong_key_usage));
1183
+ rb_iv_set (vsignature, "@validity", INT2FIX(signature->validity));
1184
+ rb_iv_set (vsignature, "@validity_reason",
1185
+ LONG2NUM(signature->validity_reason));
1186
+ rb_ary_push (vsignatures, vsignature);
1187
+ }
1188
+ return vverify_result;
1189
+ }
1190
+
1191
+ static VALUE
1192
+ rb_s_gpgme_op_decrypt_verify (VALUE dummy, VALUE vctx, VALUE vcipher,
1193
+ VALUE vplain)
1194
+ {
1195
+ gpgme_ctx_t ctx;
1196
+ gpgme_data_t cipher, plain;
1197
+ gpgme_error_t err;
1198
+
1199
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1200
+
1201
+ UNWRAP_GPGME_CTX(vctx, ctx);
1202
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1203
+ UNWRAP_GPGME_DATA(vplain, plain);
1204
+
1205
+ err = gpgme_op_decrypt_verify (ctx, cipher, plain);
1206
+ return LONG2NUM(err);
1207
+ }
1208
+
1209
+ static VALUE
1210
+ rb_s_gpgme_op_decrypt_verify_start (VALUE dummy, VALUE vctx, VALUE vcipher,
1211
+ VALUE vplain)
1212
+ {
1213
+ gpgme_ctx_t ctx;
1214
+ gpgme_data_t cipher, plain;
1215
+ gpgme_error_t err;
1216
+
1217
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1218
+
1219
+ UNWRAP_GPGME_CTX(vctx, ctx);
1220
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1221
+ UNWRAP_GPGME_DATA(vplain, plain);
1222
+
1223
+ err = gpgme_op_decrypt_verify_start (ctx, cipher, plain);
1224
+ return LONG2NUM(err);
1225
+ }
1226
+
1227
+ static VALUE
1228
+ rb_s_gpgme_signers_clear (VALUE dummy, VALUE vctx)
1229
+ {
1230
+ gpgme_ctx_t ctx;
1231
+
1232
+ UNWRAP_GPGME_CTX(vctx, ctx);
1233
+ gpgme_signers_clear (ctx);
1234
+ return Qnil;
1235
+ }
1236
+
1237
+ static VALUE
1238
+ rb_s_gpgme_signers_add (VALUE dummy, VALUE vctx, VALUE vkey)
1239
+ {
1240
+ gpgme_ctx_t ctx;
1241
+ gpgme_key_t key;
1242
+ gpgme_error_t err;
1243
+
1244
+ UNWRAP_GPGME_CTX(vctx, ctx);
1245
+ UNWRAP_GPGME_KEY(vkey, key);
1246
+
1247
+ err = gpgme_signers_add (ctx, key);
1248
+ return LONG2NUM(err);
1249
+ }
1250
+
1251
+ static VALUE
1252
+ rb_s_gpgme_signers_enum (VALUE dummy, VALUE vctx, VALUE vseq)
1253
+ {
1254
+ gpgme_ctx_t ctx;
1255
+ gpgme_key_t key;
1256
+
1257
+ UNWRAP_GPGME_CTX(vctx, ctx);
1258
+
1259
+ key = gpgme_signers_enum (ctx, NUM2INT(vseq));
1260
+ if (!key)
1261
+ return Qnil;
1262
+ return WRAP_GPGME_KEY(key);
1263
+ }
1264
+
1265
+ static VALUE
1266
+ rb_s_gpgme_op_sign (VALUE dummy, VALUE vctx, VALUE vplain, VALUE vsig,
1267
+ VALUE vmode)
1268
+ {
1269
+ gpgme_ctx_t ctx;
1270
+ gpgme_data_t plain, sig;
1271
+ gpgme_error_t err;
1272
+
1273
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1274
+
1275
+ UNWRAP_GPGME_CTX(vctx, ctx);
1276
+ UNWRAP_GPGME_DATA(vplain, plain);
1277
+ UNWRAP_GPGME_DATA(vsig, sig);
1278
+
1279
+ err = gpgme_op_sign (ctx, plain, sig, NUM2INT(vmode));
1280
+ return LONG2NUM(err);
1281
+ }
1282
+
1283
+ static VALUE
1284
+ rb_s_gpgme_op_sign_start (VALUE dummy, VALUE vctx, VALUE vplain, VALUE vsig,
1285
+ VALUE vmode)
1286
+ {
1287
+ gpgme_ctx_t ctx;
1288
+ gpgme_data_t plain, sig;
1289
+ gpgme_error_t err;
1290
+
1291
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1292
+
1293
+ UNWRAP_GPGME_CTX(vctx, ctx);
1294
+ UNWRAP_GPGME_DATA(vplain, plain);
1295
+ UNWRAP_GPGME_DATA(vsig, sig);
1296
+
1297
+ err = gpgme_op_sign_start (ctx, plain, sig, NUM2INT(vmode));
1298
+ return LONG2NUM(err);
1299
+ }
1300
+
1301
+ static VALUE
1302
+ rb_s_gpgme_op_sign_result (VALUE dummy, VALUE vctx)
1303
+ {
1304
+ gpgme_ctx_t ctx;
1305
+ gpgme_sign_result_t result;
1306
+ gpgme_invalid_key_t invalid_key;
1307
+ gpgme_new_signature_t new_signature;
1308
+ VALUE vresult, vinvalid_signers, vsignatures;
1309
+
1310
+ UNWRAP_GPGME_CTX(vctx, ctx);
1311
+
1312
+ result = gpgme_op_sign_result (ctx);
1313
+ vresult = rb_class_new_instance (0, NULL, cSignResult);
1314
+ vinvalid_signers = rb_ary_new ();
1315
+ rb_iv_set (vresult, "@invalid_signers", vinvalid_signers);
1316
+ for (invalid_key = result->invalid_signers; invalid_key;
1317
+ invalid_key = invalid_key->next)
1318
+ {
1319
+ VALUE vinvalid_key =
1320
+ rb_class_new_instance (0, NULL, cInvalidKey);
1321
+ rb_iv_set (vinvalid_key, "@fpr", rb_str_new2 (invalid_key->fpr));
1322
+ rb_iv_set (vinvalid_key, "@reason", LONG2NUM(invalid_key->reason));
1323
+ rb_ary_push (vinvalid_signers, vinvalid_key);
1324
+ }
1325
+ vsignatures = rb_ary_new ();
1326
+ rb_iv_set (vresult, "@signatures", vsignatures);
1327
+ for (new_signature = result->signatures; new_signature;
1328
+ new_signature = new_signature->next)
1329
+ {
1330
+ VALUE vnew_signature =
1331
+ rb_class_new_instance (0, NULL, cNewSignature);
1332
+ rb_iv_set (vnew_signature, "@type", INT2FIX(new_signature->type));
1333
+ rb_iv_set (vnew_signature, "@pubkey_algo",
1334
+ INT2FIX(new_signature->pubkey_algo));
1335
+ rb_iv_set (vnew_signature, "@hash_algo",
1336
+ INT2FIX(new_signature->hash_algo));
1337
+ rb_iv_set (vnew_signature, "@sig_class",
1338
+ UINT2NUM(new_signature->sig_class));
1339
+ rb_iv_set (vnew_signature, "@timestamp",
1340
+ LONG2NUM(new_signature->timestamp));
1341
+ rb_iv_set (vnew_signature, "@fpr", rb_str_new2 (new_signature->fpr));
1342
+ rb_ary_push (vsignatures, vnew_signature);
1343
+ }
1344
+ return vresult;
1345
+ }
1346
+
1347
+ static VALUE
1348
+ rb_s_gpgme_op_encrypt (VALUE dummy, VALUE vctx, VALUE vrecp, VALUE vflags,
1349
+ VALUE vplain, VALUE vcipher)
1350
+ {
1351
+ gpgme_ctx_t ctx;
1352
+ gpgme_key_t *recp = NULL;
1353
+ gpgme_data_t plain, cipher;
1354
+ gpgme_error_t err;
1355
+
1356
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1357
+
1358
+ UNWRAP_GPGME_CTX(vctx, ctx);
1359
+ /* If RECP is `NULL', symmetric rather than public key encryption is
1360
+ performed. */
1361
+ if (!NIL_P(vrecp))
1362
+ {
1363
+ int i;
1364
+ recp = ALLOC_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
1365
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
1366
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
1367
+ recp[i] = NULL;
1368
+ }
1369
+ UNWRAP_GPGME_DATA(vplain, plain);
1370
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1371
+
1372
+ err = gpgme_op_encrypt (ctx, recp, NUM2INT(vflags), plain, cipher);
1373
+ if (recp)
1374
+ xfree (recp);
1375
+ return LONG2NUM(err);
1376
+ }
1377
+
1378
+ static VALUE
1379
+ rb_s_gpgme_op_encrypt_start (VALUE dummy, VALUE vctx, VALUE vrecp,
1380
+ VALUE vflags, VALUE vplain, VALUE vcipher)
1381
+ {
1382
+ gpgme_ctx_t ctx;
1383
+ gpgme_key_t *recp = NULL;
1384
+ gpgme_data_t plain, cipher;
1385
+ gpgme_error_t err;
1386
+
1387
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1388
+
1389
+ UNWRAP_GPGME_CTX(vctx, ctx);
1390
+ /* If RECP is `NULL', symmetric rather than public key encryption is
1391
+ performed. */
1392
+ if (!NIL_P(vrecp))
1393
+ {
1394
+ int i;
1395
+ recp = ALLOC_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
1396
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
1397
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
1398
+ recp[i] = NULL;
1399
+ }
1400
+ UNWRAP_GPGME_DATA(vplain, plain);
1401
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1402
+
1403
+ err = gpgme_op_encrypt_start (ctx, recp, NUM2INT(vflags), plain, cipher);
1404
+ if (recp)
1405
+ xfree (recp);
1406
+ return LONG2NUM(err);
1407
+ }
1408
+
1409
+ static VALUE
1410
+ rb_s_gpgme_op_encrypt_result (VALUE dummy, VALUE vctx)
1411
+ {
1412
+ gpgme_ctx_t ctx;
1413
+ gpgme_encrypt_result_t result;
1414
+ gpgme_invalid_key_t invalid_key;
1415
+ VALUE vresult, vinvalid_recipients;
1416
+
1417
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1418
+
1419
+ UNWRAP_GPGME_CTX(vctx, ctx);
1420
+
1421
+ result = gpgme_op_encrypt_result (ctx);
1422
+ vresult = rb_class_new_instance (0, NULL, cEncryptResult);
1423
+ vinvalid_recipients = rb_ary_new ();
1424
+ rb_iv_set (vresult, "@invalid_recipients", vinvalid_recipients);
1425
+ for (invalid_key = result->invalid_recipients; invalid_key;
1426
+ invalid_key = invalid_key->next)
1427
+ {
1428
+ VALUE vinvalid_key =
1429
+ rb_class_new_instance (0, NULL, cInvalidKey);
1430
+ rb_iv_set (vinvalid_key, "@fpr", rb_str_new2 (invalid_key->fpr));
1431
+ rb_iv_set (vinvalid_key, "@reason", LONG2NUM(invalid_key->reason));
1432
+ rb_ary_push (vinvalid_recipients, vinvalid_key);
1433
+ }
1434
+ return vresult;
1435
+ }
1436
+
1437
+ static VALUE
1438
+ rb_s_gpgme_op_encrypt_sign (VALUE dummy, VALUE vctx, VALUE vrecp, VALUE vflags,
1439
+ VALUE vplain, VALUE vcipher)
1440
+ {
1441
+ gpgme_ctx_t ctx;
1442
+ gpgme_key_t *recp = NULL;
1443
+ gpgme_data_t plain, cipher;
1444
+ gpgme_error_t err;
1445
+
1446
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1447
+
1448
+ UNWRAP_GPGME_CTX(vctx, ctx);
1449
+ /* If RECP is `NULL', symmetric rather than public key encryption is
1450
+ performed. */
1451
+ if (!NIL_P(vrecp))
1452
+ {
1453
+ int i;
1454
+ recp = ALLOC_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
1455
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
1456
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
1457
+ recp[i] = NULL;
1458
+ }
1459
+ UNWRAP_GPGME_DATA(vplain, plain);
1460
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1461
+
1462
+ err = gpgme_op_encrypt_sign (ctx, recp, NUM2INT(vflags), plain, cipher);
1463
+ if (recp)
1464
+ xfree (recp);
1465
+ return LONG2NUM(err);
1466
+ }
1467
+
1468
+ static VALUE
1469
+ rb_s_gpgme_op_encrypt_sign_start (VALUE dummy, VALUE vctx, VALUE vrecp,
1470
+ VALUE vflags, VALUE vplain, VALUE vcipher)
1471
+ {
1472
+ gpgme_ctx_t ctx;
1473
+ gpgme_key_t *recp = NULL;
1474
+ gpgme_data_t plain, cipher;
1475
+ gpgme_error_t err;
1476
+
1477
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1478
+
1479
+ UNWRAP_GPGME_CTX(vctx, ctx);
1480
+ /* If RECP is `NULL', symmetric rather than public key encryption is
1481
+ performed. */
1482
+ if (!NIL_P(vrecp))
1483
+ {
1484
+ int i;
1485
+ recp = ALLOC_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
1486
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
1487
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
1488
+ recp[i] = NULL;
1489
+ }
1490
+ UNWRAP_GPGME_DATA(vplain, plain);
1491
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1492
+
1493
+ err = gpgme_op_encrypt_sign_start (ctx, recp, NUM2INT(vflags), plain,
1494
+ cipher);
1495
+ if (recp)
1496
+ xfree (recp);
1497
+ return LONG2NUM(err);
1498
+ }
1499
+
1500
+ static VALUE
1501
+ rb_s_gpgme_wait (VALUE dummy, VALUE vctx, VALUE rstatus, VALUE vhang)
1502
+ {
1503
+ gpgme_ctx_t ctx = NULL, ret;
1504
+ gpgme_error_t status;
1505
+
1506
+ /* The CTX argument can be `NULL'. In that case, `gpgme_wait' waits
1507
+ for any context to complete its operation. */
1508
+ if (!NIL_P(vctx))
1509
+ UNWRAP_GPGME_CTX(vctx, ctx);
1510
+
1511
+ ret = gpgme_wait (ctx, &status, NUM2INT(vhang));
1512
+ if (ret)
1513
+ {
1514
+ rb_ary_store (rstatus, 0, INT2NUM(status));
1515
+ if (ret != ctx)
1516
+ vctx = WRAP_GPGME_CTX(ret);
1517
+ return vctx;
1518
+ }
1519
+ return Qnil;
1520
+ }
1521
+
1522
+ void
1523
+ Init_gpgme_n (void)
1524
+ {
1525
+ VALUE mGPGME;
1526
+
1527
+ mGPGME = rb_define_module ("GPGME");
1528
+
1529
+ rb_define_module_function (mGPGME, "gpgme_check_version",
1530
+ rb_s_gpgme_check_version, 1);
1531
+ rb_define_module_function (mGPGME, "gpgme_engine_check_version",
1532
+ rb_s_gpgme_engine_check_version, 1);
1533
+ rb_define_module_function (mGPGME, "gpgme_get_engine_info",
1534
+ rb_s_gpgme_get_engine_info, 1);
1535
+
1536
+ rb_define_module_function (mGPGME, "gpgme_pubkey_algo_name",
1537
+ rb_s_gpgme_pubkey_algo_name, 1);
1538
+ rb_define_module_function (mGPGME, "gpgme_hash_algo_name",
1539
+ rb_s_gpgme_hash_algo_name, 1);
1540
+
1541
+ rb_define_module_function (mGPGME, "gpgme_err_code",
1542
+ rb_s_gpgme_err_code, 1);
1543
+ rb_define_module_function (mGPGME, "gpgme_err_source",
1544
+ rb_s_gpgme_err_source, 1);
1545
+ rb_define_module_function (mGPGME, "gpgme_strerror",
1546
+ rb_s_gpgme_strerror, 1);
1547
+
1548
+ cEngineInfo =
1549
+ rb_define_class_under (mGPGME, "EngineInfo", rb_cObject);
1550
+ cCtx =
1551
+ rb_define_class_under (mGPGME, "Ctx", rb_cObject);
1552
+ cData =
1553
+ rb_define_class_under (mGPGME, "Data", rb_cObject);
1554
+ cKey =
1555
+ rb_define_class_under (mGPGME, "Key", rb_cObject);
1556
+ cSubKey =
1557
+ rb_define_class_under (mGPGME, "SubKey", rb_cObject);
1558
+ cUserID =
1559
+ rb_define_class_under (mGPGME, "UserID", rb_cObject);
1560
+ cKeySig =
1561
+ rb_define_class_under (mGPGME, "KeySig", rb_cObject);
1562
+ cDecryptResult =
1563
+ rb_define_class_under (mGPGME, "DecryptResult", rb_cObject);
1564
+ cVerifyResult =
1565
+ rb_define_class_under (mGPGME, "VerifyResult", rb_cObject);
1566
+ cSignResult =
1567
+ rb_define_class_under (mGPGME, "SignResult", rb_cObject);
1568
+ cEncryptResult =
1569
+ rb_define_class_under (mGPGME, "EncryptResult", rb_cObject);
1570
+ cSignature =
1571
+ rb_define_class_under (mGPGME, "Signature", rb_cObject);
1572
+ cSigNotation =
1573
+ rb_define_class_under (mGPGME, "SigNotation", rb_cObject);
1574
+ cTrustItem =
1575
+ rb_define_class_under (mGPGME, "TrustItem", rb_cObject);
1576
+ cInvalidKey =
1577
+ rb_define_class_under (mGPGME, "InvalidKey", rb_cObject);
1578
+ cNewSignature =
1579
+ rb_define_class_under (mGPGME, "NewSignature", rb_cObject);
1580
+ cImportResult =
1581
+ rb_define_class_under (mGPGME, "ImportResult", rb_cObject);
1582
+ cImportStatus =
1583
+ rb_define_class_under (mGPGME, "ImportStatus", rb_cObject);
1584
+
1585
+ /* Creating Data Buffers
1586
+ *
1587
+ * gpgme_data_new_from_filepart is not currently supported.
1588
+ */
1589
+ rb_define_module_function (mGPGME, "gpgme_data_new",
1590
+ rb_s_gpgme_data_new, 1);
1591
+ rb_define_module_function (mGPGME, "gpgme_data_new_from_mem",
1592
+ rb_s_gpgme_data_new_from_mem, 3);
1593
+ rb_define_module_function (mGPGME, "gpgme_data_new_from_fd",
1594
+ rb_s_gpgme_data_new_from_fd, 2);
1595
+ rb_define_module_function (mGPGME, "gpgme_data_new_from_cbs",
1596
+ rb_s_gpgme_data_new_from_cbs, 3);
1597
+
1598
+ /* Manipulating Data Buffers */
1599
+ rb_define_module_function (mGPGME, "gpgme_data_read",
1600
+ rb_s_gpgme_data_read, 2);
1601
+ rb_define_module_function (mGPGME, "gpgme_data_seek",
1602
+ rb_s_gpgme_data_seek, 3);
1603
+ rb_define_module_function (mGPGME, "gpgme_data_write",
1604
+ rb_s_gpgme_data_write, 3);
1605
+ rb_define_module_function (mGPGME, "gpgme_data_get_encoding",
1606
+ rb_s_gpgme_data_get_encoding, 1);
1607
+ rb_define_module_function (mGPGME, "gpgme_data_set_encoding",
1608
+ rb_s_gpgme_data_set_encoding, 2);
1609
+
1610
+ /* Creating Contexts */
1611
+ rb_define_module_function (mGPGME, "gpgme_new",
1612
+ rb_s_gpgme_new, 1);
1613
+
1614
+ /* Context Attributes */
1615
+ rb_define_module_function (mGPGME, "gpgme_set_protocol",
1616
+ rb_s_gpgme_set_protocol, 2);
1617
+ rb_define_module_function (mGPGME, "gpgme_get_protocol",
1618
+ rb_s_gpgme_get_protocol, 1);
1619
+ rb_define_module_function (mGPGME, "gpgme_set_armor",
1620
+ rb_s_gpgme_set_armor, 2);
1621
+ rb_define_module_function (mGPGME, "gpgme_get_armor",
1622
+ rb_s_gpgme_get_armor, 1);
1623
+ rb_define_module_function (mGPGME, "gpgme_set_textmode",
1624
+ rb_s_gpgme_set_textmode, 2);
1625
+ rb_define_module_function (mGPGME, "gpgme_get_textmode",
1626
+ rb_s_gpgme_get_textmode, 1);
1627
+ rb_define_module_function (mGPGME, "gpgme_set_include_certs",
1628
+ rb_s_gpgme_set_include_certs, 2);
1629
+ rb_define_module_function (mGPGME, "gpgme_get_include_certs",
1630
+ rb_s_gpgme_get_include_certs, 1);
1631
+ rb_define_module_function (mGPGME, "gpgme_set_keylist_mode",
1632
+ rb_s_gpgme_set_keylist_mode, 2);
1633
+ rb_define_module_function (mGPGME, "gpgme_get_keylist_mode",
1634
+ rb_s_gpgme_get_keylist_mode, 1);
1635
+ rb_define_module_function (mGPGME, "gpgme_set_passphrase_cb",
1636
+ rb_s_gpgme_set_passphrase_cb, 3);
1637
+ rb_define_module_function (mGPGME, "gpgme_get_passphrase_cb",
1638
+ rb_s_gpgme_get_passphrase_cb, 3);
1639
+ rb_define_module_function (mGPGME, "gpgme_set_progress_cb",
1640
+ rb_s_gpgme_set_progress_cb, 3);
1641
+ rb_define_module_function (mGPGME, "gpgme_get_progress_cb",
1642
+ rb_s_gpgme_get_progress_cb, 3);
1643
+ rb_define_module_function (mGPGME, "gpgme_set_locale",
1644
+ rb_s_gpgme_set_locale, 3);
1645
+
1646
+ /* Key Management */
1647
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_start",
1648
+ rb_s_gpgme_op_keylist_start, 3);
1649
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_ext_start",
1650
+ rb_s_gpgme_op_keylist_ext_start, 4);
1651
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_next",
1652
+ rb_s_gpgme_op_keylist_next, 2);
1653
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_end",
1654
+ rb_s_gpgme_op_keylist_end, 1);
1655
+ rb_define_module_function (mGPGME, "gpgme_get_key",
1656
+ rb_s_gpgme_get_key, 4);
1657
+ rb_define_module_function (mGPGME, "gpgme_key_ref",
1658
+ rb_s_gpgme_key_ref, 1);
1659
+ rb_define_module_function (mGPGME, "gpgme_key_unref",
1660
+ rb_s_gpgme_key_unref, 1);
1661
+ rb_define_module_function (mGPGME, "gpgme_op_genkey",
1662
+ rb_s_gpgme_op_genkey, 4);
1663
+ rb_define_module_function (mGPGME, "gpgme_op_genkey_start",
1664
+ rb_s_gpgme_op_genkey_start, 4);
1665
+ rb_define_module_function (mGPGME, "gpgme_op_export",
1666
+ rb_s_gpgme_op_export, 4);
1667
+ rb_define_module_function (mGPGME, "gpgme_op_export_start",
1668
+ rb_s_gpgme_op_export_start, 3);
1669
+ rb_define_module_function (mGPGME, "gpgme_op_import",
1670
+ rb_s_gpgme_op_import, 2);
1671
+ rb_define_module_function (mGPGME, "gpgme_op_import_start",
1672
+ rb_s_gpgme_op_import_start, 2);
1673
+ rb_define_module_function (mGPGME, "gpgme_op_import_result",
1674
+ rb_s_gpgme_op_import_result, 1);
1675
+ rb_define_module_function (mGPGME, "gpgme_op_delete",
1676
+ rb_s_gpgme_op_delete, 3);
1677
+ rb_define_module_function (mGPGME, "gpgme_op_delete_start",
1678
+ rb_s_gpgme_op_delete_start, 3);
1679
+
1680
+ /* Trust Item Management */
1681
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_start",
1682
+ rb_s_gpgme_op_trustlist_start, 3);
1683
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_next",
1684
+ rb_s_gpgme_op_trustlist_next, 2);
1685
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_end",
1686
+ rb_s_gpgme_op_trustlist_end, 1);
1687
+
1688
+ /* Decrypt */
1689
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt",
1690
+ rb_s_gpgme_op_decrypt, 3);
1691
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_start",
1692
+ rb_s_gpgme_op_decrypt_start, 3);
1693
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_result",
1694
+ rb_s_gpgme_op_decrypt_result, 1);
1695
+
1696
+ /* Verify */
1697
+ rb_define_module_function (mGPGME, "gpgme_op_verify",
1698
+ rb_s_gpgme_op_verify, 4);
1699
+ rb_define_module_function (mGPGME, "gpgme_op_verify_start",
1700
+ rb_s_gpgme_op_verify_start, 4);
1701
+ rb_define_module_function (mGPGME, "gpgme_op_verify_result",
1702
+ rb_s_gpgme_op_verify_result, 1);
1703
+
1704
+ /* Decrypt and Verify */
1705
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_verify",
1706
+ rb_s_gpgme_op_decrypt_verify, 3);
1707
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_verify_start",
1708
+ rb_s_gpgme_op_decrypt_verify_start, 3);
1709
+
1710
+ /* Sign */
1711
+ rb_define_module_function (mGPGME, "gpgme_signers_clear",
1712
+ rb_s_gpgme_signers_clear, 1);
1713
+ rb_define_module_function (mGPGME, "gpgme_signers_add",
1714
+ rb_s_gpgme_signers_add, 2);
1715
+ rb_define_module_function (mGPGME, "gpgme_signers_enum",
1716
+ rb_s_gpgme_signers_enum, 2);
1717
+ rb_define_module_function (mGPGME, "gpgme_op_sign",
1718
+ rb_s_gpgme_op_sign, 4);
1719
+ rb_define_module_function (mGPGME, "gpgme_op_sign_start",
1720
+ rb_s_gpgme_op_sign_start, 4);
1721
+ rb_define_module_function (mGPGME, "gpgme_op_sign_result",
1722
+ rb_s_gpgme_op_sign_result, 1);
1723
+
1724
+ /* Encrypt */
1725
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt",
1726
+ rb_s_gpgme_op_encrypt, 5);
1727
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_start",
1728
+ rb_s_gpgme_op_encrypt_start, 5);
1729
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_result",
1730
+ rb_s_gpgme_op_encrypt_result, 1);
1731
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_sign",
1732
+ rb_s_gpgme_op_encrypt_sign, 5);
1733
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_sign_start",
1734
+ rb_s_gpgme_op_encrypt_sign_start, 5);
1735
+
1736
+ /* Run Control */
1737
+ rb_define_module_function (mGPGME, "gpgme_wait",
1738
+ rb_s_gpgme_wait, 3);
1739
+
1740
+ /* gpgme_pubkey_algo_t */
1741
+ rb_define_const (mGPGME, "GPGME_PK_RSA", INT2FIX(GPGME_PK_RSA));
1742
+ rb_define_const (mGPGME, "GPGME_PK_DSA", INT2FIX(GPGME_PK_DSA));
1743
+ rb_define_const (mGPGME, "GPGME_PK_ELG", INT2FIX(GPGME_PK_ELG));
1744
+ rb_define_const (mGPGME, "GPGME_PK_ELG_E", INT2FIX(GPGME_PK_ELG_E));
1745
+
1746
+ /* gpgme_hash_algo_t */
1747
+ rb_define_const (mGPGME, "GPGME_MD_MD5", INT2FIX(GPGME_MD_MD5));
1748
+ rb_define_const (mGPGME, "GPGME_MD_SHA1", INT2FIX(GPGME_MD_SHA1));
1749
+ rb_define_const (mGPGME, "GPGME_MD_RMD160", INT2FIX(GPGME_MD_RMD160));
1750
+ rb_define_const (mGPGME, "GPGME_MD_MD2", INT2FIX(GPGME_MD_MD2));
1751
+ rb_define_const (mGPGME, "GPGME_MD_TIGER", INT2FIX(GPGME_MD_TIGER));
1752
+ rb_define_const (mGPGME, "GPGME_MD_HAVAL", INT2FIX(GPGME_MD_HAVAL));
1753
+ rb_define_const (mGPGME, "GPGME_MD_SHA256", INT2FIX(GPGME_MD_SHA256));
1754
+ rb_define_const (mGPGME, "GPGME_MD_SHA384", INT2FIX(GPGME_MD_SHA384));
1755
+ rb_define_const (mGPGME, "GPGME_MD_SHA512", INT2FIX(GPGME_MD_SHA512));
1756
+ rb_define_const (mGPGME, "GPGME_MD_MD4", INT2FIX(GPGME_MD_MD4));
1757
+ rb_define_const (mGPGME, "GPGME_MD_CRC32", INT2FIX(GPGME_MD_CRC32));
1758
+ rb_define_const (mGPGME, "GPGME_MD_CRC32_RFC1510",
1759
+ INT2FIX(GPGME_MD_CRC32_RFC1510));
1760
+ rb_define_const (mGPGME, "GPGME_MD_CRC24_RFC2440",
1761
+ INT2FIX(GPGME_MD_CRC24_RFC2440));
1762
+
1763
+ /* gpgme_err_code_t */
1764
+ rb_define_const (mGPGME, "GPG_ERR_EOF",
1765
+ INT2FIX(GPG_ERR_EOF));
1766
+ rb_define_const (mGPGME, "GPG_ERR_NO_ERROR",
1767
+ INT2FIX(GPG_ERR_NO_ERROR));
1768
+ rb_define_const (mGPGME, "GPG_ERR_GENERAL",
1769
+ INT2FIX(GPG_ERR_GENERAL));
1770
+ rb_define_const (mGPGME, "GPG_ERR_ENOMEM",
1771
+ INT2FIX(GPG_ERR_ENOMEM));
1772
+ rb_define_const (mGPGME, "GPG_ERR_INV_VALUE",
1773
+ INT2FIX(GPG_ERR_INV_VALUE));
1774
+ rb_define_const (mGPGME, "GPG_ERR_UNUSABLE_PUBKEY",
1775
+ INT2FIX(GPG_ERR_UNUSABLE_PUBKEY));
1776
+ rb_define_const (mGPGME, "GPG_ERR_UNUSABLE_SECKEY",
1777
+ INT2FIX(GPG_ERR_UNUSABLE_SECKEY));
1778
+ rb_define_const (mGPGME, "GPG_ERR_NO_DATA",
1779
+ INT2FIX(GPG_ERR_NO_DATA));
1780
+ rb_define_const (mGPGME, "GPG_ERR_CONFLICT",
1781
+ INT2FIX(GPG_ERR_CONFLICT));
1782
+ rb_define_const (mGPGME, "GPG_ERR_NOT_IMPLEMENTED",
1783
+ INT2FIX(GPG_ERR_NOT_IMPLEMENTED));
1784
+ rb_define_const (mGPGME, "GPG_ERR_DECRYPT_FAILED",
1785
+ INT2FIX(GPG_ERR_DECRYPT_FAILED));
1786
+ rb_define_const (mGPGME, "GPG_ERR_BAD_PASSPHRASE",
1787
+ INT2FIX(GPG_ERR_BAD_PASSPHRASE));
1788
+ rb_define_const (mGPGME, "GPG_ERR_KEY_EXPIRED",
1789
+ INT2FIX(GPG_ERR_KEY_EXPIRED));
1790
+ rb_define_const (mGPGME, "GPG_ERR_SIG_EXPIRED",
1791
+ INT2FIX(GPG_ERR_SIG_EXPIRED));
1792
+ rb_define_const (mGPGME, "GPG_ERR_CANCELED",
1793
+ INT2FIX(GPG_ERR_CANCELED));
1794
+ rb_define_const (mGPGME, "GPG_ERR_INV_ENGINE",
1795
+ INT2FIX(GPG_ERR_INV_ENGINE));
1796
+ rb_define_const (mGPGME, "GPG_ERR_AMBIGUOUS_NAME",
1797
+ INT2FIX(GPG_ERR_AMBIGUOUS_NAME));
1798
+ rb_define_const (mGPGME, "GPG_ERR_WRONG_KEY_USAGE",
1799
+ INT2FIX(GPG_ERR_WRONG_KEY_USAGE));
1800
+ rb_define_const (mGPGME, "GPG_ERR_CERT_REVOKED",
1801
+ INT2FIX(GPG_ERR_CERT_REVOKED));
1802
+ rb_define_const (mGPGME, "GPG_ERR_CERT_EXPIRED",
1803
+ INT2FIX(GPG_ERR_CERT_EXPIRED));
1804
+ rb_define_const (mGPGME, "GPG_ERR_NO_CRL_KNOWN",
1805
+ INT2FIX(GPG_ERR_NO_CRL_KNOWN));
1806
+ rb_define_const (mGPGME, "GPG_ERR_NO_POLICY_MATCH",
1807
+ INT2FIX(GPG_ERR_NO_POLICY_MATCH));
1808
+ rb_define_const (mGPGME, "GPG_ERR_NO_SECKEY",
1809
+ INT2FIX(GPG_ERR_NO_SECKEY));
1810
+ rb_define_const (mGPGME, "GPG_ERR_MISSING_CERT",
1811
+ INT2FIX(GPG_ERR_MISSING_CERT));
1812
+ rb_define_const (mGPGME, "GPG_ERR_BAD_CERT_CHAIN",
1813
+ INT2FIX(GPG_ERR_BAD_CERT_CHAIN));
1814
+ rb_define_const (mGPGME, "GPG_ERR_UNSUPPORTED_ALGORITHM",
1815
+ INT2FIX(GPG_ERR_UNSUPPORTED_ALGORITHM));
1816
+ rb_define_const (mGPGME, "GPG_ERR_BAD_SIGNATURE",
1817
+ INT2FIX(GPG_ERR_BAD_SIGNATURE));
1818
+ rb_define_const (mGPGME, "GPG_ERR_NO_PUBKEY",
1819
+ INT2FIX(GPG_ERR_NO_PUBKEY));
1820
+
1821
+ /* gpgme_err_source_t */
1822
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_UNKNOWN",
1823
+ INT2FIX(GPG_ERR_SOURCE_UNKNOWN));
1824
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGME",
1825
+ INT2FIX(GPG_ERR_SOURCE_GPGME));
1826
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPG",
1827
+ INT2FIX(GPG_ERR_SOURCE_GPG));
1828
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGSM",
1829
+ INT2FIX(GPG_ERR_SOURCE_GPGSM));
1830
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GCRYPT",
1831
+ INT2FIX(GPG_ERR_SOURCE_GCRYPT));
1832
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGAGENT",
1833
+ INT2FIX(GPG_ERR_SOURCE_GPGAGENT));
1834
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_PINENTRY",
1835
+ INT2FIX(GPG_ERR_SOURCE_PINENTRY));
1836
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_SCD",
1837
+ INT2FIX(GPG_ERR_SOURCE_SCD));
1838
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_KEYBOX",
1839
+ INT2FIX(GPG_ERR_SOURCE_KEYBOX));
1840
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_1",
1841
+ INT2FIX(GPG_ERR_SOURCE_USER_1));
1842
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_2",
1843
+ INT2FIX(GPG_ERR_SOURCE_USER_2));
1844
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_3",
1845
+ INT2FIX(GPG_ERR_SOURCE_USER_3));
1846
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_4",
1847
+ INT2FIX(GPG_ERR_SOURCE_USER_4));
1848
+
1849
+ /* gpgme_data_encoding_t */
1850
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_NONE",
1851
+ INT2FIX(GPGME_DATA_ENCODING_NONE));
1852
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_BINARY",
1853
+ INT2FIX(GPGME_DATA_ENCODING_BINARY));
1854
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_BASE64",
1855
+ INT2FIX(GPGME_DATA_ENCODING_BASE64));
1856
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_ARMOR",
1857
+ INT2FIX(GPGME_DATA_ENCODING_ARMOR));
1858
+
1859
+ /* gpgme_sig_stat_t */
1860
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NONE",
1861
+ INT2FIX(GPGME_SIG_STAT_NONE));
1862
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD",
1863
+ INT2FIX(GPGME_SIG_STAT_GOOD));
1864
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_BAD",
1865
+ INT2FIX(GPGME_SIG_STAT_BAD));
1866
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NOKEY",
1867
+ INT2FIX(GPGME_SIG_STAT_NOKEY));
1868
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NOSIG",
1869
+ INT2FIX(GPGME_SIG_STAT_NOSIG));
1870
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_ERROR",
1871
+ INT2FIX(GPGME_SIG_STAT_ERROR));
1872
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_DIFF",
1873
+ INT2FIX(GPGME_SIG_STAT_DIFF));
1874
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD_EXP",
1875
+ INT2FIX(GPGME_SIG_STAT_GOOD_EXP));
1876
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD_EXPKEY",
1877
+ INT2FIX(GPGME_SIG_STAT_GOOD_EXPKEY));
1878
+
1879
+ /* gpgme_sigsum_t */
1880
+ rb_define_const (mGPGME, "GPGME_SIGSUM_VALID",
1881
+ INT2FIX(GPGME_SIGSUM_VALID));
1882
+ rb_define_const (mGPGME, "GPGME_SIGSUM_GREEN",
1883
+ INT2FIX(GPGME_SIGSUM_GREEN));
1884
+ rb_define_const (mGPGME, "GPGME_SIGSUM_RED",
1885
+ INT2FIX(GPGME_SIGSUM_RED));
1886
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_REVOKED",
1887
+ INT2FIX(GPGME_SIGSUM_KEY_REVOKED));
1888
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_EXPIRED",
1889
+ INT2FIX(GPGME_SIGSUM_KEY_EXPIRED));
1890
+ rb_define_const (mGPGME, "GPGME_SIGSUM_SIG_EXPIRED",
1891
+ INT2FIX(GPGME_SIGSUM_SIG_EXPIRED));
1892
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_MISSING",
1893
+ INT2FIX(GPGME_SIGSUM_KEY_MISSING));
1894
+ rb_define_const (mGPGME, "GPGME_SIGSUM_CRL_MISSING",
1895
+ INT2FIX(GPGME_SIGSUM_CRL_MISSING));
1896
+ rb_define_const (mGPGME, "GPGME_SIGSUM_CRL_TOO_OLD",
1897
+ INT2FIX(GPGME_SIGSUM_CRL_TOO_OLD));
1898
+ rb_define_const (mGPGME, "GPGME_SIGSUM_BAD_POLICY",
1899
+ INT2FIX(GPGME_SIGSUM_BAD_POLICY));
1900
+ rb_define_const (mGPGME, "GPGME_SIGSUM_SYS_ERROR",
1901
+ INT2FIX(GPGME_SIGSUM_SYS_ERROR));
1902
+
1903
+ /* gpgme_sig_mode_t */
1904
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_NORMAL",
1905
+ INT2FIX(GPGME_SIG_MODE_NORMAL));
1906
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_DETACH",
1907
+ INT2FIX(GPGME_SIG_MODE_DETACH));
1908
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_CLEAR",
1909
+ INT2FIX(GPGME_SIG_MODE_CLEAR));
1910
+
1911
+ /* gpgme_attr_t */
1912
+ rb_define_const (mGPGME, "GPGME_ATTR_KEYID",
1913
+ INT2FIX(GPGME_ATTR_KEYID));
1914
+ rb_define_const (mGPGME, "GPGME_ATTR_FPR",
1915
+ INT2FIX(GPGME_ATTR_FPR));
1916
+ rb_define_const (mGPGME, "GPGME_ATTR_ALGO",
1917
+ INT2FIX(GPGME_ATTR_ALGO));
1918
+ rb_define_const (mGPGME, "GPGME_ATTR_LEN",
1919
+ INT2FIX(GPGME_ATTR_LEN));
1920
+ rb_define_const (mGPGME, "GPGME_ATTR_CREATED",
1921
+ INT2FIX(GPGME_ATTR_CREATED));
1922
+ rb_define_const (mGPGME, "GPGME_ATTR_EXPIRE",
1923
+ INT2FIX(GPGME_ATTR_EXPIRE));
1924
+ rb_define_const (mGPGME, "GPGME_ATTR_OTRUST",
1925
+ INT2FIX(GPGME_ATTR_OTRUST));
1926
+ rb_define_const (mGPGME, "GPGME_ATTR_USERID",
1927
+ INT2FIX(GPGME_ATTR_USERID));
1928
+ rb_define_const (mGPGME, "GPGME_ATTR_NAME",
1929
+ INT2FIX(GPGME_ATTR_NAME));
1930
+ rb_define_const (mGPGME, "GPGME_ATTR_EMAIL",
1931
+ INT2FIX(GPGME_ATTR_EMAIL));
1932
+ rb_define_const (mGPGME, "GPGME_ATTR_COMMENT",
1933
+ INT2FIX(GPGME_ATTR_COMMENT));
1934
+ rb_define_const (mGPGME, "GPGME_ATTR_VALIDITY",
1935
+ INT2FIX(GPGME_ATTR_VALIDITY));
1936
+ rb_define_const (mGPGME, "GPGME_ATTR_LEVEL",
1937
+ INT2FIX(GPGME_ATTR_LEVEL));
1938
+ rb_define_const (mGPGME, "GPGME_ATTR_TYPE",
1939
+ INT2FIX(GPGME_ATTR_TYPE));
1940
+ rb_define_const (mGPGME, "GPGME_ATTR_IS_SECRET",
1941
+ INT2FIX(GPGME_ATTR_IS_SECRET));
1942
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_REVOKED",
1943
+ INT2FIX(GPGME_ATTR_KEY_REVOKED));
1944
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_INVALID",
1945
+ INT2FIX(GPGME_ATTR_KEY_INVALID));
1946
+ rb_define_const (mGPGME, "GPGME_ATTR_UID_REVOKED",
1947
+ INT2FIX(GPGME_ATTR_UID_REVOKED));
1948
+ rb_define_const (mGPGME, "GPGME_ATTR_UID_INVALID",
1949
+ INT2FIX(GPGME_ATTR_UID_INVALID));
1950
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_CAPS",
1951
+ INT2FIX(GPGME_ATTR_KEY_CAPS));
1952
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_ENCRYPT",
1953
+ INT2FIX(GPGME_ATTR_CAN_ENCRYPT));
1954
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_SIGN",
1955
+ INT2FIX(GPGME_ATTR_CAN_SIGN));
1956
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_CERTIFY",
1957
+ INT2FIX(GPGME_ATTR_CAN_CERTIFY));
1958
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_EXPIRED",
1959
+ INT2FIX(GPGME_ATTR_KEY_EXPIRED));
1960
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_DISABLED",
1961
+ INT2FIX(GPGME_ATTR_KEY_DISABLED));
1962
+ rb_define_const (mGPGME, "GPGME_ATTR_SERIAL",
1963
+ INT2FIX(GPGME_ATTR_SERIAL));
1964
+ rb_define_const (mGPGME, "GPGME_ATTR_ISSUER",
1965
+ INT2FIX(GPGME_ATTR_ISSUER));
1966
+ rb_define_const (mGPGME, "GPGME_ATTR_CHAINID",
1967
+ INT2FIX(GPGME_ATTR_CHAINID));
1968
+ rb_define_const (mGPGME, "GPGME_ATTR_SIG_STATUS",
1969
+ INT2FIX(GPGME_ATTR_SIG_STATUS));
1970
+ rb_define_const (mGPGME, "GPGME_ATTR_ERRTOK",
1971
+ INT2FIX(GPGME_ATTR_ERRTOK));
1972
+ rb_define_const (mGPGME, "GPGME_ATTR_SIG_SUMMARY",
1973
+ INT2FIX(GPGME_ATTR_SIG_SUMMARY));
1974
+
1975
+ /* gpgme_validity_t */
1976
+ rb_define_const (mGPGME, "GPGME_VALIDITY_UNKNOWN",
1977
+ INT2FIX(GPGME_VALIDITY_UNKNOWN));
1978
+ rb_define_const (mGPGME, "GPGME_VALIDITY_UNDEFINED",
1979
+ INT2FIX(GPGME_VALIDITY_UNDEFINED));
1980
+ rb_define_const (mGPGME, "GPGME_VALIDITY_NEVER",
1981
+ INT2FIX(GPGME_VALIDITY_NEVER));
1982
+ rb_define_const (mGPGME, "GPGME_VALIDITY_MARGINAL",
1983
+ INT2FIX(GPGME_VALIDITY_MARGINAL));
1984
+ rb_define_const (mGPGME, "GPGME_VALIDITY_FULL",
1985
+ INT2FIX(GPGME_VALIDITY_FULL));
1986
+ rb_define_const (mGPGME, "GPGME_VALIDITY_ULTIMATE",
1987
+ INT2FIX(GPGME_VALIDITY_ULTIMATE));
1988
+
1989
+ /* gpgme_protocol_t */
1990
+ rb_define_const (mGPGME, "GPGME_PROTOCOL_OpenPGP",
1991
+ INT2FIX(GPGME_PROTOCOL_OpenPGP));
1992
+ rb_define_const (mGPGME, "GPGME_PROTOCOL_CMS",
1993
+ INT2FIX(GPGME_PROTOCOL_CMS));
1994
+
1995
+ /* gpgme_status_code_t */
1996
+ rb_define_const (mGPGME, "GPGME_STATUS_EOF",
1997
+ INT2FIX(GPGME_STATUS_EOF));
1998
+ /* mkstatus starts here */
1999
+ rb_define_const (mGPGME, "GPGME_STATUS_ENTER",
2000
+ INT2FIX(GPGME_STATUS_ENTER));
2001
+ rb_define_const (mGPGME, "GPGME_STATUS_LEAVE",
2002
+ INT2FIX(GPGME_STATUS_LEAVE));
2003
+ rb_define_const (mGPGME, "GPGME_STATUS_ABORT",
2004
+ INT2FIX(GPGME_STATUS_ABORT));
2005
+
2006
+ rb_define_const (mGPGME, "GPGME_STATUS_GOODSIG",
2007
+ INT2FIX(GPGME_STATUS_GOODSIG));
2008
+ rb_define_const (mGPGME, "GPGME_STATUS_BADSIG",
2009
+ INT2FIX(GPGME_STATUS_BADSIG));
2010
+ rb_define_const (mGPGME, "GPGME_STATUS_ERRSIG",
2011
+ INT2FIX(GPGME_STATUS_ERRSIG));
2012
+
2013
+ rb_define_const (mGPGME, "GPGME_STATUS_BADARMOR",
2014
+ INT2FIX(GPGME_STATUS_BADARMOR));
2015
+
2016
+ rb_define_const (mGPGME, "GPGME_STATUS_RSA_OR_IDEA",
2017
+ INT2FIX(GPGME_STATUS_RSA_OR_IDEA));
2018
+ rb_define_const (mGPGME, "GPGME_STATUS_KEYEXPIRED",
2019
+ INT2FIX(GPGME_STATUS_KEYEXPIRED));
2020
+ rb_define_const (mGPGME, "GPGME_STATUS_KEYREVOKED",
2021
+ INT2FIX(GPGME_STATUS_KEYREVOKED));
2022
+
2023
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_UNDEFINED",
2024
+ INT2FIX(GPGME_STATUS_TRUST_UNDEFINED));
2025
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_NEVER",
2026
+ INT2FIX(GPGME_STATUS_TRUST_NEVER));
2027
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_MARGINAL",
2028
+ INT2FIX(GPGME_STATUS_TRUST_MARGINAL));
2029
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_FULLY",
2030
+ INT2FIX(GPGME_STATUS_TRUST_FULLY));
2031
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_ULTIMATE",
2032
+ INT2FIX(GPGME_STATUS_TRUST_ULTIMATE));
2033
+
2034
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_INFO",
2035
+ INT2FIX(GPGME_STATUS_SHM_INFO));
2036
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET",
2037
+ INT2FIX(GPGME_STATUS_SHM_GET));
2038
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET_BOOL",
2039
+ INT2FIX(GPGME_STATUS_SHM_GET_BOOL));
2040
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET_HIDDEN",
2041
+ INT2FIX(GPGME_STATUS_SHM_GET_HIDDEN));
2042
+
2043
+ rb_define_const (mGPGME, "GPGME_STATUS_NEED_PASSPHRASE",
2044
+ INT2FIX(GPGME_STATUS_NEED_PASSPHRASE));
2045
+ rb_define_const (mGPGME, "GPGME_STATUS_VALIDSIG",
2046
+ INT2FIX(GPGME_STATUS_VALIDSIG));
2047
+ rb_define_const (mGPGME, "GPGME_STATUS_SIG_ID",
2048
+ INT2FIX(GPGME_STATUS_SIG_ID));
2049
+ rb_define_const (mGPGME, "GPGME_STATUS_ENC_TO",
2050
+ INT2FIX(GPGME_STATUS_ENC_TO));
2051
+ rb_define_const (mGPGME, "GPGME_STATUS_NODATA",
2052
+ INT2FIX(GPGME_STATUS_NODATA));
2053
+ rb_define_const (mGPGME, "GPGME_STATUS_BAD_PASSPHRASE",
2054
+ INT2FIX(GPGME_STATUS_BAD_PASSPHRASE));
2055
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_PUBKEY",
2056
+ INT2FIX(GPGME_STATUS_NO_PUBKEY));
2057
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_SECKEY",
2058
+ INT2FIX(GPGME_STATUS_NO_SECKEY));
2059
+ rb_define_const (mGPGME, "GPGME_STATUS_NEED_PASSPHRASE_SYM",
2060
+ INT2FIX(GPGME_STATUS_NEED_PASSPHRASE_SYM));
2061
+ rb_define_const (mGPGME, "GPGME_STATUS_DECRYPTION_FAILED",
2062
+ INT2FIX(GPGME_STATUS_DECRYPTION_FAILED));
2063
+ rb_define_const (mGPGME, "GPGME_STATUS_DECRYPTION_OKAY",
2064
+ INT2FIX(GPGME_STATUS_DECRYPTION_OKAY));
2065
+ rb_define_const (mGPGME, "GPGME_STATUS_MISSING_PASSPHRASE",
2066
+ INT2FIX(GPGME_STATUS_MISSING_PASSPHRASE));
2067
+ rb_define_const (mGPGME, "GPGME_STATUS_GOOD_PASSPHRASE",
2068
+ INT2FIX(GPGME_STATUS_GOOD_PASSPHRASE));
2069
+ rb_define_const (mGPGME, "GPGME_STATUS_GOODMDC",
2070
+ INT2FIX(GPGME_STATUS_GOODMDC));
2071
+ rb_define_const (mGPGME, "GPGME_STATUS_BADMDC",
2072
+ INT2FIX(GPGME_STATUS_BADMDC));
2073
+ rb_define_const (mGPGME, "GPGME_STATUS_ERRMDC",
2074
+ INT2FIX(GPGME_STATUS_ERRMDC));
2075
+ rb_define_const (mGPGME, "GPGME_STATUS_IMPORTED",
2076
+ INT2FIX(GPGME_STATUS_IMPORTED));
2077
+ rb_define_const (mGPGME, "GPGME_STATUS_IMPORT_RES",
2078
+ INT2FIX(GPGME_STATUS_IMPORT_RES));
2079
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_START",
2080
+ INT2FIX(GPGME_STATUS_FILE_START));
2081
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_DONE",
2082
+ INT2FIX(GPGME_STATUS_FILE_DONE));
2083
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_ERROR",
2084
+ INT2FIX(GPGME_STATUS_FILE_ERROR));
2085
+
2086
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_DECRYPTION",
2087
+ INT2FIX(GPGME_STATUS_BEGIN_DECRYPTION));
2088
+ rb_define_const (mGPGME, "GPGME_STATUS_END_DECRYPTION",
2089
+ INT2FIX(GPGME_STATUS_END_DECRYPTION));
2090
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_ENCRYPTION",
2091
+ INT2FIX(GPGME_STATUS_BEGIN_ENCRYPTION));
2092
+ rb_define_const (mGPGME, "GPGME_STATUS_END_ENCRYPTION",
2093
+ INT2FIX(GPGME_STATUS_END_ENCRYPTION));
2094
+
2095
+ rb_define_const (mGPGME, "GPGME_STATUS_DELETE_PROBLEM",
2096
+ INT2FIX(GPGME_STATUS_DELETE_PROBLEM));
2097
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_BOOL",
2098
+ INT2FIX(GPGME_STATUS_GET_BOOL));
2099
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_LINE",
2100
+ INT2FIX(GPGME_STATUS_GET_LINE));
2101
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_HIDDEN",
2102
+ INT2FIX(GPGME_STATUS_GET_HIDDEN));
2103
+ rb_define_const (mGPGME, "GPGME_STATUS_GOT_IT",
2104
+ INT2FIX(GPGME_STATUS_GOT_IT));
2105
+ rb_define_const (mGPGME, "GPGME_STATUS_PROGRESS",
2106
+ INT2FIX(GPGME_STATUS_PROGRESS));
2107
+ rb_define_const (mGPGME, "GPGME_STATUS_SIG_CREATED",
2108
+ INT2FIX(GPGME_STATUS_SIG_CREATED));
2109
+ rb_define_const (mGPGME, "GPGME_STATUS_SESSION_KEY",
2110
+ INT2FIX(GPGME_STATUS_SESSION_KEY));
2111
+ rb_define_const (mGPGME, "GPGME_STATUS_NOTATION_NAME",
2112
+ INT2FIX(GPGME_STATUS_NOTATION_NAME));
2113
+ rb_define_const (mGPGME, "GPGME_STATUS_NOTATION_DATA",
2114
+ INT2FIX(GPGME_STATUS_NOTATION_DATA));
2115
+ rb_define_const (mGPGME, "GPGME_STATUS_POLICY_URL",
2116
+ INT2FIX(GPGME_STATUS_POLICY_URL));
2117
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_STREAM",
2118
+ INT2FIX(GPGME_STATUS_BEGIN_STREAM));
2119
+ rb_define_const (mGPGME, "GPGME_STATUS_END_STREAM",
2120
+ INT2FIX(GPGME_STATUS_END_STREAM));
2121
+ rb_define_const (mGPGME, "GPGME_STATUS_KEY_CREATED",
2122
+ INT2FIX(GPGME_STATUS_KEY_CREATED));
2123
+ rb_define_const (mGPGME, "GPGME_STATUS_USERID_HINT",
2124
+ INT2FIX(GPGME_STATUS_USERID_HINT));
2125
+ rb_define_const (mGPGME, "GPGME_STATUS_UNEXPECTED",
2126
+ INT2FIX(GPGME_STATUS_UNEXPECTED));
2127
+ rb_define_const (mGPGME, "GPGME_STATUS_INV_RECP",
2128
+ INT2FIX(GPGME_STATUS_INV_RECP));
2129
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_RECP",
2130
+ INT2FIX(GPGME_STATUS_NO_RECP));
2131
+ rb_define_const (mGPGME, "GPGME_STATUS_ALREADY_SIGNED",
2132
+ INT2FIX(GPGME_STATUS_ALREADY_SIGNED));
2133
+ rb_define_const (mGPGME, "GPGME_STATUS_SIGEXPIRED",
2134
+ INT2FIX(GPGME_STATUS_SIGEXPIRED));
2135
+ rb_define_const (mGPGME, "GPGME_STATUS_EXPSIG",
2136
+ INT2FIX(GPGME_STATUS_EXPSIG));
2137
+ rb_define_const (mGPGME, "GPGME_STATUS_EXPKEYSIG",
2138
+ INT2FIX(GPGME_STATUS_EXPKEYSIG));
2139
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUNCATED",
2140
+ INT2FIX(GPGME_STATUS_TRUNCATED));
2141
+ rb_define_const (mGPGME, "GPGME_STATUS_ERROR",
2142
+ INT2FIX(GPGME_STATUS_ERROR));
2143
+
2144
+ /* The available keylist mode flags. */
2145
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_LOCAL",
2146
+ INT2FIX(GPGME_KEYLIST_MODE_LOCAL));
2147
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_EXTERN",
2148
+ INT2FIX(GPGME_KEYLIST_MODE_EXTERN));
2149
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_SIGS",
2150
+ INT2FIX(GPGME_KEYLIST_MODE_SIGS));
2151
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_VALIDATE",
2152
+ INT2FIX(GPGME_KEYLIST_MODE_VALIDATE));
2153
+
2154
+ /* The available flags for status field of gpgme_import_status_t. */
2155
+ rb_define_const (mGPGME, "GPGME_IMPORT_NEW", INT2FIX(GPGME_IMPORT_NEW));
2156
+ rb_define_const (mGPGME, "GPGME_IMPORT_UID", INT2FIX(GPGME_IMPORT_UID));
2157
+ rb_define_const (mGPGME, "GPGME_IMPORT_SIG", INT2FIX(GPGME_IMPORT_SIG));
2158
+ rb_define_const (mGPGME, "GPGME_IMPORT_SUBKEY",
2159
+ INT2FIX(GPGME_IMPORT_SUBKEY));
2160
+ rb_define_const (mGPGME, "GPGME_IMPORT_SECRET",
2161
+ INT2FIX(GPGME_IMPORT_SECRET));
2162
+
2163
+ /* The available flags for gpgme_op_encrypt. */
2164
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_ALWAYS_TRUST",
2165
+ INT2FIX(GPGME_ENCRYPT_ALWAYS_TRUST));
2166
+ }