gpgme-loongson 2.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3071 @@
1
+ /* gpgme_n.c -- low level interface to GPGME
2
+ Copyright (C) 2003,2006,2007,2008,2009 Daiki Ueno
3
+
4
+ This file is a part of Ruby-GPGME.
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library 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 GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
+ 02110-1301 USA */
20
+
21
+ /* While this file was written by hand, it is (semi) automatically
22
+ generated. High-level functions are written in Ruby instead of C
23
+ (See "lib/gpgme.rb"). If you are about to edit this file, you may
24
+ want to check out the translation rules:
25
+
26
+ 1. Each symbol defined in this file is either a class, a module
27
+ function, or a constant. _No instance methods are defined here_.
28
+
29
+ 2. Each symbol defined in this file follows the same naming convention
30
+ as the GPGME API. That is, symbol names are followed by `gpgme_'
31
+ for functions, and `GPGME_' or `GPG_' for constants.
32
+
33
+ 3. Output arguments are wrapped in arrays. For example, the first
34
+ argument of `gpgme_data_new' has the type `gpgme_data_t *', and to
35
+ be used to hold a newly created gpgme_data_t object. The
36
+ corresponding Ruby interface expects an array (empty for typical
37
+ cases) for that. */
38
+
39
+ #include "ruby.h"
40
+ #ifdef HAVE_RUBY_ENCODING_H
41
+ #include "ruby/encoding.h"
42
+ #endif
43
+ #include "gpgme.h"
44
+ #include <errno.h>
45
+
46
+ /* Define this if you use GPGME 1.1.2 and earlier.
47
+ https://bugs.g10code.com/gnupg/issue715 */
48
+ #ifdef RUBY_GPGME_NEED_WORKAROUND_KEYLIST_NEXT
49
+ #define CHECK_KEYLIST_IN_PROGRESS(vctx) \
50
+ if (rb_iv_get (vctx, "ruby_gpgme_keylist_in_progress") != Qtrue) \
51
+ return LONG2NUM(gpgme_error (GPG_ERR_INV_STATE))
52
+ #define CHECK_KEYLIST_NOT_IN_PROGRESS(vctx) \
53
+ if (rb_iv_get (vctx, "ruby_gpgme_keylist_in_progress") == Qtrue) \
54
+ return LONG2NUM(gpgme_error (GPG_ERR_INV_STATE))
55
+ #define SET_KEYLIST_IN_PROGRESS(vctx) \
56
+ rb_iv_set (vctx, "ruby_gpgme_keylist_in_progress", Qtrue)
57
+ #define RESET_KEYLIST_IN_PROGRESS(vctx) \
58
+ rb_iv_set (vctx, "ruby_gpgme_keylist_in_progress", Qfalse)
59
+ #else
60
+ #define CHECK_KEYLIST_IN_PROGRESS(vctx)
61
+ #define CHECK_KEYLIST_NOT_IN_PROGRESS(vctx)
62
+ #define SET_KEYLIST_IN_PROGRESS(vctx)
63
+ #define RESET_KEYLIST_IN_PROGRESS(vctx)
64
+ #endif
65
+
66
+ /* StringValuePtr is not available in 1.6. */
67
+ #ifndef StringValuePtr
68
+ #define StringValuePtr(str) RSTRING(str)->ptr
69
+ #endif
70
+
71
+ /* STR2CSTR is obsoleted in 1.8. */
72
+ #ifndef StringValueCStr
73
+ #define StringValueCStr STR2CSTR
74
+ #endif
75
+
76
+ /* RARRAY_LEN is not available in 1.8. */
77
+ #ifndef RARRAY_LEN
78
+ #define RARRAY_LEN(a) RARRAY(a)->len
79
+ #endif
80
+
81
+ /* RARRAY_PTR is not available in 1.8. */
82
+ #ifndef RARRAY_PTR
83
+ #define RARRAY_PTR(a) RARRAY(a)->ptr
84
+ #endif
85
+
86
+ /* RSTRING_LEN is not available in 1.8.5. */
87
+ #ifndef RSTRING_LEN
88
+ #define RSTRING_LEN(a) RSTRING(a)->len
89
+ #endif
90
+
91
+ #define WRAP_GPGME_DATA(dh) \
92
+ Data_Wrap_Struct(cData, 0, gpgme_data_release, dh)
93
+ /* `gpgme_data_t' is typedef'ed as `struct gpgme_data *'. */
94
+ #define UNWRAP_GPGME_DATA(vdh, dh) \
95
+ Data_Get_Struct(vdh, struct gpgme_data, dh);
96
+
97
+ #define WRAP_GPGME_CTX(ctx) \
98
+ Data_Wrap_Struct(cCtx, 0, gpgme_release, ctx)
99
+ /* `gpgme_ctx_t' is typedef'ed as `struct gpgme_context *'. */
100
+ #define UNWRAP_GPGME_CTX(vctx, ctx) \
101
+ Data_Get_Struct(vctx, struct gpgme_context, ctx)
102
+
103
+ #define WRAP_GPGME_KEY(key) \
104
+ Data_Wrap_Struct(cKey, 0, gpgme_key_unref, key)
105
+ /* `gpgme_key_t' is typedef'ed as `struct _gpgme_key *'. */
106
+ #define UNWRAP_GPGME_KEY(vkey, key) \
107
+ Data_Get_Struct(vkey, struct _gpgme_key, key)
108
+
109
+ #define WRAP_GPGME_TRUST_ITEM(item) \
110
+ Data_Wrap_Struct(cTrustItem, 0, gpgme_trust_item_unref, item)
111
+ /* `gpgme_trust_item_t' is typedef'ed as `struct _gpgme_trust_item *'. */
112
+ #define UNWRAP_GPGME_TRUST_ITEM(vitem, item) \
113
+ Data_Get_Struct(vitem, struct _gpgme_trust_item, item)
114
+
115
+ static VALUE cEngineInfo,
116
+ cCtx,
117
+ cData,
118
+ cKey,
119
+ cSubKey,
120
+ cUserID,
121
+ cKeySig,
122
+ cInvalidKey,
123
+ cNewSignature,
124
+ cSignature,
125
+ cSigNotation,
126
+ cTrustItem,
127
+ cRecipient,
128
+ cDecryptResult,
129
+ cVerifyResult,
130
+ cSignResult,
131
+ cEncryptResult,
132
+ cImportStatus,
133
+ cImportResult;
134
+
135
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010500
136
+ static VALUE
137
+ rb_s_gpgme_get_dirinfo (VALUE dummy, VALUE vwhat)
138
+ {
139
+ const char *result = gpgme_get_dirinfo (StringValueCStr(vwhat));
140
+ return result ? rb_str_new2 (result) : Qnil;
141
+ }
142
+ #endif
143
+
144
+ static VALUE
145
+ rb_s_gpgme_check_version (VALUE dummy, VALUE vreq)
146
+ {
147
+ const char *result = gpgme_check_version (NIL_P(vreq) ? NULL :
148
+ StringValueCStr(vreq));
149
+ return result ? rb_str_new2 (result) : Qnil;
150
+ }
151
+
152
+ static VALUE
153
+ rb_s_gpgme_engine_check_version (VALUE dummy, VALUE vproto)
154
+ {
155
+ gpgme_error_t err = gpgme_engine_check_version (NUM2INT(vproto));
156
+ return LONG2NUM(err);
157
+ }
158
+
159
+ static VALUE
160
+ rb_s_gpgme_get_engine_info (VALUE dummy, VALUE rinfo)
161
+ {
162
+ gpgme_engine_info_t info;
163
+ gpgme_error_t err;
164
+ long idx;
165
+
166
+ err = gpgme_get_engine_info (&info);
167
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
168
+ {
169
+ for (idx = 0; info; info = info->next, idx++)
170
+ {
171
+ VALUE vinfo = rb_class_new_instance (0, NULL, cEngineInfo);
172
+ rb_iv_set (vinfo, "@protocol", INT2FIX(info->protocol));
173
+ if (info->file_name)
174
+ rb_iv_set (vinfo, "@file_name", rb_str_new2 (info->file_name));
175
+ if (info->version)
176
+ rb_iv_set (vinfo, "@version", rb_str_new2 (info->version));
177
+ if (info->req_version)
178
+ rb_iv_set (vinfo, "@req_version", rb_str_new2 (info->req_version));
179
+ if (info->home_dir)
180
+ rb_iv_set (vinfo, "@home_dir", rb_str_new2 (info->home_dir));
181
+ rb_ary_store (rinfo, idx, vinfo);
182
+ }
183
+ }
184
+ return LONG2NUM(err);
185
+ }
186
+
187
+ static VALUE
188
+ rb_s_gpgme_set_engine_info (VALUE dummy, VALUE vproto, VALUE vfile_name,
189
+ VALUE vhome_dir)
190
+ {
191
+ gpgme_error_t err = gpgme_set_engine_info (NUM2INT(vproto),
192
+ NIL_P(vfile_name) ? NULL :
193
+ StringValueCStr(vfile_name),
194
+ NIL_P(vhome_dir) ? NULL :
195
+ StringValueCStr(vhome_dir));
196
+ return LONG2NUM(err);
197
+ }
198
+
199
+ static VALUE
200
+ rb_s_gpgme_ctx_get_engine_info (VALUE dummy, VALUE vctx, VALUE rinfo)
201
+ {
202
+ long idx;
203
+
204
+ gpgme_ctx_t ctx;
205
+
206
+ UNWRAP_GPGME_CTX(vctx, ctx);
207
+ if (!ctx)
208
+ rb_raise (rb_eArgError, "released ctx");
209
+
210
+ gpgme_engine_info_t info = gpgme_ctx_get_engine_info (ctx);
211
+ for (idx = 0; info; info = info->next, idx++)
212
+ {
213
+ VALUE vinfo = rb_class_new_instance (0, NULL, cEngineInfo);
214
+ rb_iv_set (vinfo, "@protocol", INT2FIX(info->protocol));
215
+ if (info->file_name)
216
+ rb_iv_set (vinfo, "@file_name", rb_str_new2 (info->file_name));
217
+ if (info->version)
218
+ rb_iv_set (vinfo, "@version", rb_str_new2 (info->version));
219
+ if (info->req_version)
220
+ rb_iv_set (vinfo, "@req_version", rb_str_new2 (info->req_version));
221
+ if (info->home_dir)
222
+ rb_iv_set (vinfo, "@home_dir", rb_str_new2 (info->home_dir));
223
+ rb_ary_store (rinfo, idx, vinfo);
224
+ }
225
+ return Qnil;
226
+ }
227
+
228
+ static VALUE
229
+ rb_s_gpgme_ctx_set_engine_info (VALUE dummy, VALUE vctx, VALUE vproto, VALUE vfile_name,
230
+ VALUE vhome_dir)
231
+ {
232
+ gpgme_ctx_t ctx;
233
+
234
+ UNWRAP_GPGME_CTX(vctx, ctx);
235
+ if (!ctx)
236
+ rb_raise (rb_eArgError, "released ctx");
237
+ gpgme_error_t err = gpgme_ctx_set_engine_info (ctx,
238
+ NUM2INT(vproto),
239
+ NIL_P(vfile_name) ? NULL :
240
+ StringValueCStr(vfile_name),
241
+ NIL_P(vhome_dir) ? NULL :
242
+ StringValueCStr(vhome_dir));
243
+ return LONG2NUM(err);
244
+ }
245
+
246
+ static VALUE
247
+ rb_s_gpgme_pubkey_algo_name (VALUE dummy, VALUE valgo)
248
+ {
249
+ const char *name = gpgme_pubkey_algo_name (NUM2INT(valgo));
250
+ if (name)
251
+ return rb_str_new2 (name);
252
+ return Qnil;
253
+ }
254
+
255
+ static VALUE
256
+ rb_s_gpgme_hash_algo_name (VALUE dummy, VALUE valgo)
257
+ {
258
+ const char *name = gpgme_hash_algo_name (NUM2INT(valgo));
259
+ if (name)
260
+ return rb_str_new2 (name);
261
+ return Qnil;
262
+ }
263
+
264
+ static VALUE
265
+ rb_s_gpgme_err_code (VALUE dummy, VALUE verr)
266
+ {
267
+ return INT2FIX(gpgme_err_code (NUM2LONG(verr)));
268
+ }
269
+
270
+ static VALUE
271
+ rb_s_gpgme_err_source (VALUE dummy, VALUE verr)
272
+ {
273
+ return INT2FIX(gpgme_err_source (NUM2LONG(verr)));
274
+ }
275
+
276
+ static VALUE
277
+ rb_s_gpgme_strerror (VALUE dummy, VALUE verr)
278
+ {
279
+ return rb_str_new2 (gpgme_strerror (NUM2LONG(verr)));
280
+ }
281
+
282
+ static VALUE
283
+ rb_s_gpgme_data_new (VALUE dummy, VALUE rdh)
284
+ {
285
+ gpgme_data_t dh;
286
+ gpgme_error_t err = gpgme_data_new (&dh);
287
+
288
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
289
+ rb_ary_store (rdh, 0, WRAP_GPGME_DATA(dh));
290
+ return LONG2NUM(err);
291
+ }
292
+
293
+ static VALUE
294
+ rb_s_gpgme_data_new_from_mem (VALUE dummy, VALUE rdh, VALUE vbuffer,
295
+ VALUE vsize)
296
+ {
297
+ gpgme_data_t dh;
298
+ VALUE vdh;
299
+ size_t size = NUM2UINT(vsize);
300
+ gpgme_error_t err;
301
+
302
+ if (RSTRING_LEN(vbuffer) < size)
303
+ rb_raise (rb_eArgError, "argument out of range");
304
+
305
+ err = gpgme_data_new_from_mem (&dh, StringValuePtr(vbuffer), size, 1);
306
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
307
+ {
308
+ vdh = WRAP_GPGME_DATA(dh);
309
+ rb_ary_store (rdh, 0, vdh);
310
+ }
311
+ return LONG2NUM(err);
312
+ }
313
+
314
+ static VALUE
315
+ rb_s_gpgme_data_new_from_fd (VALUE dummy, VALUE rdh, VALUE vfd)
316
+ {
317
+ gpgme_data_t dh;
318
+ gpgme_error_t err = gpgme_data_new_from_fd (&dh, NUM2INT(vfd));
319
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
320
+ rb_ary_store (rdh, 0, WRAP_GPGME_DATA(dh));
321
+ return LONG2NUM(err);
322
+ }
323
+
324
+ static ssize_t
325
+ read_cb (void *handle, void *buffer, size_t size)
326
+ {
327
+ VALUE vcb = (VALUE)handle, vcbs, vhook_value, vbuffer;
328
+
329
+ vcbs = RARRAY_PTR(vcb)[0];
330
+ vhook_value = RARRAY_PTR(vcb)[1];
331
+
332
+ vbuffer = rb_funcall (vcbs, rb_intern ("read"), 2, vhook_value,
333
+ LONG2NUM(size));
334
+ if (NIL_P(vbuffer))
335
+ return 0;
336
+ memcpy (buffer, StringValuePtr(vbuffer), RSTRING_LEN(vbuffer));
337
+ return RSTRING_LEN(vbuffer);
338
+ }
339
+
340
+ static ssize_t
341
+ write_cb (void *handle, const void *buffer, size_t size)
342
+ {
343
+ VALUE vcb = (VALUE)handle, vcbs, vhook_value, vbuffer, vnwrite;
344
+
345
+ vcbs = RARRAY_PTR(vcb)[0];
346
+ vhook_value = RARRAY_PTR(vcb)[1];
347
+ vbuffer = rb_str_new (buffer, size);
348
+
349
+ vnwrite = rb_funcall (vcbs, rb_intern ("write"), 3,
350
+ vhook_value, vbuffer, LONG2NUM(size));
351
+ return NUM2LONG(vnwrite);
352
+ }
353
+
354
+ static off_t
355
+ seek_cb (void *handle, off_t offset, int whence)
356
+ {
357
+ VALUE vcb = (VALUE)handle, vcbs, vhook_value, vpos;
358
+ ID id_seek = rb_intern ("seek");
359
+
360
+ vcbs = RARRAY_PTR(vcb)[0];
361
+ vhook_value = RARRAY_PTR(vcb)[1];
362
+
363
+ if (rb_respond_to (vcbs, id_seek))
364
+ {
365
+ vpos = rb_funcall (vcbs, id_seek, 3,
366
+ vhook_value, LONG2NUM(offset), INT2FIX(whence));
367
+ return NUM2LONG(vpos);
368
+ }
369
+ errno = ENOSYS;
370
+ return -1;
371
+ }
372
+
373
+ static struct gpgme_data_cbs cbs =
374
+ {
375
+ .read = read_cb,
376
+ .write = write_cb,
377
+ .seek = seek_cb,
378
+ .release = NULL
379
+ };
380
+
381
+ static VALUE
382
+ rb_s_gpgme_data_new_from_cbs (VALUE dummy, VALUE rdh, VALUE vcbs,
383
+ VALUE vhandle)
384
+ {
385
+ gpgme_data_t dh;
386
+ gpgme_error_t err;
387
+ VALUE vcbs_handle = rb_ary_new ();
388
+
389
+ rb_ary_push (vcbs_handle, vcbs);
390
+ rb_ary_push (vcbs_handle, vhandle);
391
+
392
+ err = gpgme_data_new_from_cbs (&dh, &cbs, (void*)vcbs_handle);
393
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
394
+ {
395
+ VALUE vdh = WRAP_GPGME_DATA(dh);
396
+ /* Keep a reference to avoid GC. */
397
+ rb_iv_set (vdh, "@cbs_handle", vcbs_handle);
398
+ rb_ary_store (rdh, 0, vdh);
399
+ }
400
+ return LONG2NUM(err);
401
+ }
402
+
403
+ static VALUE
404
+ rb_s_gpgme_data_read (VALUE dummy, VALUE vdh, VALUE vlength)
405
+ {
406
+ gpgme_data_t dh;
407
+ ssize_t length = NUM2LONG(vlength), nread;
408
+ void *buffer;
409
+ VALUE vbuffer = Qnil;
410
+
411
+ UNWRAP_GPGME_DATA(vdh, dh);
412
+
413
+ buffer = ALLOC_N (char, length);
414
+ nread = gpgme_data_read (dh, buffer, length);
415
+ if (nread > 0)
416
+ vbuffer = rb_str_new (buffer, nread);
417
+ xfree (buffer);
418
+ if (nread < 0)
419
+ rb_sys_fail ("rb_s_gpgme_data_read");
420
+ return vbuffer;
421
+ }
422
+
423
+ static VALUE
424
+ rb_s_gpgme_data_seek (VALUE dummy, VALUE vdh, VALUE voffset, VALUE vwhence)
425
+ {
426
+ gpgme_data_t dh;
427
+ off_t pos;
428
+
429
+ UNWRAP_GPGME_DATA(vdh, dh);
430
+ pos = gpgme_data_seek (dh, NUM2LONG(voffset), NUM2INT(vwhence));
431
+ if (pos < 0)
432
+ rb_sys_fail ("rb_s_gpgme_data_seek");
433
+ return LONG2NUM(pos);
434
+ }
435
+
436
+ static VALUE
437
+ rb_s_gpgme_data_write (VALUE dummy, VALUE vdh, VALUE vbuf, VALUE vlen)
438
+ {
439
+ gpgme_data_t dh;
440
+ ssize_t nwrite;
441
+
442
+ UNWRAP_GPGME_DATA(vdh, dh);
443
+ nwrite = gpgme_data_write (dh, StringValuePtr(vbuf), NUM2UINT(vlen));
444
+ if (nwrite < 0)
445
+ rb_sys_fail ("rb_s_gpgme_data_write");
446
+ return LONG2NUM(nwrite);
447
+ }
448
+
449
+ static VALUE
450
+ rb_s_gpgme_data_get_encoding (VALUE dummy, VALUE vdh)
451
+ {
452
+ gpgme_data_t dh;
453
+ gpgme_error_t err;
454
+
455
+ UNWRAP_GPGME_DATA(vdh, dh);
456
+ err = gpgme_data_get_encoding (dh);
457
+ return LONG2NUM(err);
458
+ }
459
+
460
+ static VALUE
461
+ rb_s_gpgme_data_set_encoding (VALUE dummy, VALUE vdh, VALUE venc)
462
+ {
463
+ gpgme_data_t dh;
464
+ gpgme_error_t err;
465
+
466
+ UNWRAP_GPGME_DATA(vdh, dh);
467
+ err = gpgme_data_set_encoding (dh, NUM2INT(venc));
468
+ return LONG2NUM(err);
469
+ }
470
+
471
+ static VALUE
472
+ rb_s_gpgme_data_get_file_name (VALUE dummy, VALUE vdh)
473
+ {
474
+ gpgme_data_t dh;
475
+
476
+ UNWRAP_GPGME_DATA(vdh, dh);
477
+ const char *result = gpgme_data_get_file_name (dh);
478
+ return result ? rb_str_new2 (result) : Qnil;
479
+ }
480
+
481
+ static VALUE
482
+ rb_s_gpgme_data_set_file_name (VALUE dummy, VALUE vdh, VALUE vfile_name)
483
+ {
484
+ gpgme_data_t dh;
485
+ gpgme_error_t err;
486
+
487
+ UNWRAP_GPGME_DATA(vdh, dh);
488
+ err = gpgme_data_set_file_name (dh,
489
+ NIL_P(vfile_name) ? NULL : StringValueCStr(vfile_name));
490
+ return LONG2NUM(err);
491
+ }
492
+
493
+ static VALUE
494
+ rb_s_gpgme_new (VALUE dummy, VALUE rctx)
495
+ {
496
+ gpgme_ctx_t ctx;
497
+ gpgme_error_t err = gpgme_new (&ctx);
498
+
499
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
500
+ rb_ary_store (rctx, 0, WRAP_GPGME_CTX(ctx));
501
+ return LONG2NUM(err);
502
+ }
503
+
504
+ static VALUE
505
+ rb_s_gpgme_release (VALUE dummy, VALUE vctx)
506
+ {
507
+ gpgme_ctx_t ctx;
508
+
509
+ UNWRAP_GPGME_CTX(vctx, ctx);
510
+ if (!ctx)
511
+ rb_raise (rb_eArgError, "released ctx");
512
+ gpgme_release (ctx);
513
+ DATA_PTR(vctx) = NULL;
514
+ return Qnil;
515
+ }
516
+
517
+ static VALUE
518
+ rb_s_gpgme_set_protocol (VALUE dummy, VALUE vctx, VALUE vproto)
519
+ {
520
+ gpgme_ctx_t ctx;
521
+ gpgme_error_t err;
522
+
523
+ UNWRAP_GPGME_CTX(vctx, ctx);
524
+ if (!ctx)
525
+ rb_raise (rb_eArgError, "released ctx");
526
+ err = gpgme_set_protocol (ctx, NUM2INT(vproto));
527
+ return LONG2NUM(err);
528
+ }
529
+
530
+ static VALUE
531
+ rb_s_gpgme_get_protocol (VALUE dummy, VALUE vctx)
532
+ {
533
+ gpgme_ctx_t ctx;
534
+ gpgme_protocol_t proto;
535
+
536
+ UNWRAP_GPGME_CTX(vctx, ctx);
537
+ if (!ctx)
538
+ rb_raise (rb_eArgError, "released ctx");
539
+ proto = gpgme_get_protocol (ctx);
540
+ return INT2FIX(proto);
541
+ }
542
+
543
+ static VALUE
544
+ rb_s_gpgme_set_armor (VALUE dummy, VALUE vctx, VALUE vyes)
545
+ {
546
+ gpgme_ctx_t ctx;
547
+
548
+ UNWRAP_GPGME_CTX(vctx, ctx);
549
+ if (!ctx)
550
+ rb_raise (rb_eArgError, "released ctx");
551
+ gpgme_set_armor (ctx, NUM2INT(vyes));
552
+
553
+ return Qnil;
554
+ }
555
+
556
+ static VALUE
557
+ rb_s_gpgme_get_armor (VALUE dummy, VALUE vctx)
558
+ {
559
+ gpgme_ctx_t ctx;
560
+ int yes;
561
+
562
+ UNWRAP_GPGME_CTX(vctx, ctx);
563
+ if (!ctx)
564
+ rb_raise (rb_eArgError, "released ctx");
565
+ yes = gpgme_get_armor (ctx);
566
+ return INT2FIX(yes);
567
+ }
568
+
569
+ static VALUE
570
+ rb_s_gpgme_set_textmode (VALUE dummy, VALUE vctx, VALUE vyes)
571
+ {
572
+ gpgme_ctx_t ctx;
573
+
574
+ UNWRAP_GPGME_CTX(vctx, ctx);
575
+ if (!ctx)
576
+ rb_raise (rb_eArgError, "released ctx");
577
+ gpgme_set_textmode (ctx, NUM2INT(vyes));
578
+ return Qnil;
579
+ }
580
+
581
+ static VALUE
582
+ rb_s_gpgme_get_textmode (VALUE dummy, VALUE vctx)
583
+ {
584
+ gpgme_ctx_t ctx;
585
+ int yes;
586
+
587
+ UNWRAP_GPGME_CTX(vctx, ctx);
588
+ if (!ctx)
589
+ rb_raise (rb_eArgError, "released ctx");
590
+ yes = gpgme_get_textmode (ctx);
591
+ return INT2FIX(yes);
592
+ }
593
+
594
+ static VALUE
595
+ rb_s_gpgme_set_include_certs (VALUE dummy, VALUE vctx, VALUE vnr_of_certs)
596
+ {
597
+ gpgme_ctx_t ctx;
598
+
599
+ UNWRAP_GPGME_CTX(vctx, ctx);
600
+ if (!ctx)
601
+ rb_raise (rb_eArgError, "released ctx");
602
+ gpgme_set_include_certs (ctx, NUM2INT(vnr_of_certs));
603
+ return Qnil;
604
+ }
605
+
606
+ static VALUE
607
+ rb_s_gpgme_get_include_certs (VALUE dummy, VALUE vctx)
608
+ {
609
+ gpgme_ctx_t ctx;
610
+ gpgme_error_t err;
611
+
612
+ UNWRAP_GPGME_CTX(vctx, ctx);
613
+ if (!ctx)
614
+ rb_raise (rb_eArgError, "released ctx");
615
+ err = gpgme_get_include_certs (ctx);
616
+ return LONG2NUM(err);
617
+ }
618
+
619
+ static VALUE
620
+ rb_s_gpgme_set_keylist_mode (VALUE dummy, VALUE vctx, VALUE vmode)
621
+ {
622
+ gpgme_ctx_t ctx;
623
+ gpgme_error_t err;
624
+
625
+ UNWRAP_GPGME_CTX(vctx, ctx);
626
+ if (!ctx)
627
+ rb_raise (rb_eArgError, "released ctx");
628
+ err = gpgme_set_keylist_mode (ctx, NUM2INT(vmode));
629
+ return LONG2NUM(err);
630
+ }
631
+
632
+ static VALUE
633
+ rb_s_gpgme_get_keylist_mode (VALUE dummy, VALUE vctx)
634
+ {
635
+ gpgme_ctx_t ctx;
636
+ int mode;
637
+
638
+ UNWRAP_GPGME_CTX(vctx, ctx);
639
+ if (!ctx)
640
+ rb_raise (rb_eArgError, "released ctx");
641
+ mode = gpgme_get_keylist_mode (ctx);
642
+ return INT2FIX(mode);
643
+ }
644
+
645
+ static gpgme_error_t
646
+ passphrase_cb (void *hook, const char *uid_hint, const char *passphrase_info,
647
+ int prev_was_bad, int fd)
648
+ {
649
+ VALUE vcb = (VALUE)hook, vpassfunc, vhook_value;
650
+
651
+ vpassfunc = RARRAY_PTR(vcb)[0];
652
+ vhook_value = RARRAY_PTR(vcb)[1];
653
+
654
+ rb_funcall (vpassfunc, rb_intern ("call"), 5,
655
+ vhook_value,
656
+ uid_hint ? rb_str_new2 (uid_hint) : Qnil,
657
+ passphrase_info ? rb_str_new2 (passphrase_info) : Qnil,
658
+ INT2FIX(prev_was_bad),
659
+ INT2NUM(fd));
660
+ return gpgme_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_NO_ERROR);
661
+ }
662
+
663
+ static VALUE
664
+ rb_s_gpgme_set_passphrase_cb (VALUE dummy, VALUE vctx, VALUE vpassfunc,
665
+ VALUE vhook_value)
666
+ {
667
+ gpgme_ctx_t ctx;
668
+ VALUE vcb = rb_ary_new ();
669
+
670
+ rb_ary_push (vcb, vpassfunc);
671
+ rb_ary_push (vcb, vhook_value);
672
+ /* Keep a reference to avoid GC. */
673
+ rb_iv_set (vctx, "@passphrase_cb", vcb);
674
+
675
+ UNWRAP_GPGME_CTX(vctx, ctx);
676
+ if (!ctx)
677
+ rb_raise (rb_eArgError, "released ctx");
678
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, (void*)vcb);
679
+ return Qnil;
680
+ }
681
+
682
+ static VALUE
683
+ rb_s_gpgme_get_passphrase_cb (VALUE dummy, VALUE vctx, VALUE rpassfunc,
684
+ VALUE rhook_value)
685
+ {
686
+ VALUE vcb = rb_iv_get (vctx, "@passphrase_cb");
687
+
688
+ /* No need to call gpgme_get_passphrase_cb. */
689
+ rb_ary_store (rpassfunc, 0, RARRAY_PTR(vcb)[0]);
690
+ rb_ary_store (rhook_value, 0, RARRAY_PTR(vcb)[1]);
691
+ return Qnil;
692
+ }
693
+
694
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010600
695
+ static gpgme_error_t
696
+ status_cb (void *hook, const char *keyword, const char *args)
697
+ {
698
+ VALUE vcb = (VALUE)hook, vstatusfunc, vhook_value;
699
+
700
+ vstatusfunc = RARRAY_PTR(vcb)[0];
701
+ vhook_value = RARRAY_PTR(vcb)[1];
702
+
703
+ rb_funcall (vstatusfunc, rb_intern ("call"), 3,
704
+ vhook_value,
705
+ keyword ? rb_str_new2 (keyword) : Qnil,
706
+ args ? rb_str_new2 (args) : Qnil);
707
+ return gpgme_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_NO_ERROR);
708
+ }
709
+
710
+ static VALUE
711
+ rb_s_gpgme_set_status_cb (VALUE dummy, VALUE vctx, VALUE vstatusfunc,
712
+ VALUE vhook_value)
713
+ {
714
+ gpgme_ctx_t ctx;
715
+ VALUE vcb = rb_ary_new ();
716
+
717
+ rb_ary_push (vcb, vstatusfunc);
718
+ rb_ary_push (vcb, vhook_value);
719
+ /* Keep a reference to avoid GC. */
720
+ rb_iv_set (vctx, "@status_cb", vcb);
721
+
722
+ UNWRAP_GPGME_CTX(vctx, ctx);
723
+ if (!ctx)
724
+ rb_raise (rb_eArgError, "released ctx");
725
+ gpgme_set_status_cb (ctx, status_cb, (void*)vcb);
726
+ return Qnil;
727
+ }
728
+
729
+ static VALUE
730
+ rb_s_gpgme_get_status_cb (VALUE dummy, VALUE vctx, VALUE rstatusfunc,
731
+ VALUE rhook_value)
732
+ {
733
+ VALUE vcb = rb_iv_get (vctx, "@status_cb");
734
+
735
+ /* No need to call gpgme_get_status_cb. */
736
+ rb_ary_store (rstatusfunc, 0, RARRAY_PTR(vcb)[0]);
737
+ rb_ary_store (rhook_value, 0, RARRAY_PTR(vcb)[1]);
738
+ return Qnil;
739
+ }
740
+ #endif
741
+
742
+ static void
743
+ progress_cb (void *hook, const char *what, int type, int current, int total)
744
+ {
745
+ VALUE vcb = (VALUE)hook, vprogfunc, vhook_value;
746
+
747
+ vprogfunc = RARRAY_PTR(vcb)[0];
748
+ vhook_value = RARRAY_PTR(vcb)[1];
749
+
750
+ rb_funcall (vprogfunc, rb_intern ("call"), 5, vhook_value,
751
+ rb_str_new2 (what), INT2NUM(type), INT2NUM(current),
752
+ INT2NUM(total));
753
+ }
754
+
755
+ static VALUE
756
+ rb_s_gpgme_set_progress_cb (VALUE dummy, VALUE vctx, VALUE vprogfunc,
757
+ VALUE vhook_value)
758
+ {
759
+ gpgme_ctx_t ctx;
760
+ VALUE vcb = rb_ary_new ();
761
+
762
+ rb_ary_push (vcb, vprogfunc);
763
+ rb_ary_push (vcb, vhook_value);
764
+ /* Keep a reference to avoid GC. */
765
+ rb_iv_set (vctx, "@progress_cb", vcb);
766
+
767
+ UNWRAP_GPGME_CTX(vctx, ctx);
768
+ if (!ctx)
769
+ rb_raise (rb_eArgError, "released ctx");
770
+ gpgme_set_progress_cb (ctx, progress_cb, (void*)vcb);
771
+
772
+ return Qnil;
773
+ }
774
+
775
+ static VALUE
776
+ rb_s_gpgme_get_progress_cb (VALUE dummy, VALUE vctx, VALUE rprogfunc,
777
+ VALUE rhook_value)
778
+ {
779
+ VALUE vcb = rb_iv_get (vctx, "@progress_cb");
780
+ rb_ary_store (rprogfunc, 0, RARRAY_PTR(vcb)[0]);
781
+ rb_ary_store (rhook_value, 0, RARRAY_PTR(vcb)[1]);
782
+ return Qnil;
783
+ }
784
+
785
+ static VALUE
786
+ rb_s_gpgme_set_locale (VALUE dummy, VALUE vctx, VALUE vcategory, VALUE vvalue)
787
+ {
788
+ gpgme_ctx_t ctx;
789
+ gpgme_error_t err;
790
+
791
+ UNWRAP_GPGME_CTX(vctx, ctx);
792
+ if (!ctx)
793
+ rb_raise (rb_eArgError, "released ctx");
794
+
795
+ err = gpgme_set_locale (ctx, NUM2INT(vcategory), StringValueCStr(vvalue));
796
+ return LONG2NUM(err);
797
+ }
798
+
799
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010400
800
+ static VALUE
801
+ rb_s_gpgme_set_pinentry_mode (VALUE dummy, VALUE vctx, VALUE vmode)
802
+ {
803
+ gpgme_ctx_t ctx;
804
+ gpgme_error_t err;
805
+
806
+ UNWRAP_GPGME_CTX(vctx, ctx);
807
+ if (!ctx)
808
+ rb_raise (rb_eArgError, "released ctx");
809
+
810
+ err = gpgme_set_pinentry_mode (ctx, NUM2INT(vmode));
811
+ return LONG2NUM(err);
812
+ }
813
+
814
+ static VALUE
815
+ rb_s_gpgme_get_pinentry_mode (VALUE dummy, VALUE vctx)
816
+ {
817
+ gpgme_ctx_t ctx;
818
+ gpgme_pinentry_mode_t mode;
819
+
820
+ UNWRAP_GPGME_CTX(vctx, ctx);
821
+ if (!ctx)
822
+ rb_raise (rb_eArgError, "released ctx");
823
+
824
+ mode = gpgme_get_pinentry_mode (ctx);
825
+ return INT2FIX(mode);
826
+ }
827
+ #endif
828
+
829
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010600
830
+ static VALUE
831
+ rb_s_gpgme_set_offline (VALUE dummy, VALUE vctx, VALUE vyes)
832
+ {
833
+ gpgme_ctx_t ctx;
834
+
835
+ UNWRAP_GPGME_CTX(vctx, ctx);
836
+ if (!ctx)
837
+ rb_raise (rb_eArgError, "released ctx");
838
+
839
+ gpgme_set_offline (ctx, vyes == Qtrue);
840
+ return Qnil;
841
+ }
842
+
843
+ static VALUE
844
+ rb_s_gpgme_get_offline (VALUE dummy, VALUE vctx)
845
+ {
846
+ gpgme_ctx_t ctx;
847
+ int yes;
848
+
849
+ UNWRAP_GPGME_CTX(vctx, ctx);
850
+ if (!ctx)
851
+ rb_raise (rb_eArgError, "released ctx");
852
+
853
+ yes = gpgme_get_offline (ctx);
854
+ return yes ? Qtrue : Qfalse;
855
+ }
856
+ #endif
857
+
858
+ static VALUE
859
+ rb_s_gpgme_op_keylist_start (VALUE dummy, VALUE vctx, VALUE vpattern,
860
+ VALUE vsecret_only)
861
+ {
862
+ gpgme_ctx_t ctx;
863
+ gpgme_error_t err;
864
+
865
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
866
+
867
+ UNWRAP_GPGME_CTX(vctx, ctx);
868
+ if (!ctx)
869
+ rb_raise (rb_eArgError, "released ctx");
870
+
871
+ err = gpgme_op_keylist_start (ctx, NIL_P(vpattern) ? NULL :
872
+ StringValueCStr(vpattern),
873
+ NUM2INT(vsecret_only));
874
+ if (gpgme_err_code (err) == GPG_ERR_NO_ERROR)
875
+ SET_KEYLIST_IN_PROGRESS(vctx);
876
+ return LONG2NUM(err);
877
+ }
878
+
879
+ static VALUE
880
+ rb_s_gpgme_op_keylist_ext_start (VALUE dummy, VALUE vctx, VALUE vpattern,
881
+ VALUE vsecret_only)
882
+ {
883
+ gpgme_ctx_t ctx;
884
+ const char **pattern = NULL;
885
+ int i, err;
886
+
887
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
888
+
889
+ UNWRAP_GPGME_CTX(vctx, ctx);
890
+ if (!ctx)
891
+ rb_raise (rb_eArgError, "released ctx");
892
+
893
+ if (!NIL_P(vpattern))
894
+ {
895
+ /* Convert RARRAY into `const char *' array. */
896
+ pattern = ALLOC_N(const char *, RARRAY_LEN(vpattern) + 1);
897
+ for (i = 0; i<RARRAY_LEN(vpattern); i++)
898
+ pattern[i] = StringValueCStr(RARRAY_PTR(vpattern)[i]);
899
+ pattern[RARRAY_LEN(vpattern)] = NULL;
900
+ }
901
+
902
+ err = gpgme_op_keylist_ext_start (ctx, pattern, NUM2INT(vsecret_only), 0);
903
+ if (gpgme_err_code (err) == GPG_ERR_NO_ERROR)
904
+ SET_KEYLIST_IN_PROGRESS(vctx);
905
+ if (pattern)
906
+ xfree (pattern);
907
+ return LONG2NUM(err);
908
+ }
909
+
910
+ static VALUE
911
+ utf8_str_new (const char *data)
912
+ {
913
+ VALUE string = rb_str_new2 (data);
914
+ #ifdef HAVE_RUBY_ENCODING_H
915
+ /* We assume all the C strings from GPGME are in UTF-8 encoding.
916
+ If there is any string which cannot be represented in UTF-8,
917
+ set the string's encoding to ASCII-8BIT and leave the caller to
918
+ detect the encoding. */
919
+ rb_enc_associate_index (string, rb_enc_find_index ("UTF-8"));
920
+ if (rb_enc_str_coderange (string) == ENC_CODERANGE_BROKEN)
921
+ rb_enc_associate_index (string, rb_enc_find_index ("ASCII-8BIT"));
922
+ #endif
923
+ return string;
924
+ }
925
+
926
+ static VALUE
927
+ save_gpgme_key_attrs (VALUE vkey, gpgme_key_t key)
928
+ {
929
+ VALUE vsubkeys, vuids;
930
+ gpgme_subkey_t subkey;
931
+ gpgme_user_id_t user_id;
932
+
933
+ rb_iv_set (vkey, "@keylist_mode", INT2FIX(key->keylist_mode));
934
+ rb_iv_set (vkey, "@revoked", INT2FIX(key->revoked));
935
+ rb_iv_set (vkey, "@expired", INT2FIX(key->expired));
936
+ rb_iv_set (vkey, "@disabled", INT2FIX(key->disabled));
937
+ rb_iv_set (vkey, "@invalid", INT2FIX(key->invalid));
938
+ rb_iv_set (vkey, "@can_encrypt", INT2FIX(key->can_encrypt));
939
+ rb_iv_set (vkey, "@can_sign", INT2FIX(key->can_sign));
940
+ rb_iv_set (vkey, "@can_certify", INT2FIX(key->can_certify));
941
+ rb_iv_set (vkey, "@can_authenticate", INT2FIX(key->can_authenticate));
942
+ rb_iv_set (vkey, "@secret", INT2FIX(key->secret));
943
+ rb_iv_set (vkey, "@protocol", INT2FIX(key->protocol));
944
+ if (key->issuer_serial)
945
+ rb_iv_set (vkey, "@issuer_serial", rb_str_new2 (key->issuer_serial));
946
+ if (key->issuer_name)
947
+ rb_iv_set (vkey, "@issuer_name", utf8_str_new (key->issuer_name));
948
+ if (key->chain_id)
949
+ rb_iv_set (vkey, "@chain_id", rb_str_new2 (key->chain_id));
950
+ rb_iv_set (vkey, "@owner_trust", INT2FIX(key->owner_trust));
951
+ vsubkeys = rb_ary_new ();
952
+ rb_iv_set (vkey, "@subkeys", vsubkeys);
953
+ for (subkey = key->subkeys; subkey; subkey = subkey->next)
954
+ {
955
+ VALUE vsubkey = rb_class_new_instance(0, NULL, cSubKey);
956
+ rb_iv_set (vsubkey, "@revoked", INT2FIX(subkey->revoked));
957
+ rb_iv_set (vsubkey, "@expired", INT2FIX(subkey->expired));
958
+ rb_iv_set (vsubkey, "@disabled", INT2FIX(subkey->disabled));
959
+ rb_iv_set (vsubkey, "@invalid", INT2FIX(subkey->invalid));
960
+ rb_iv_set (vsubkey, "@can_encrypt", INT2FIX(subkey->can_encrypt));
961
+ rb_iv_set (vsubkey, "@can_sign", INT2FIX(subkey->can_sign));
962
+ rb_iv_set (vsubkey, "@can_certify", INT2FIX(subkey->can_certify));
963
+ rb_iv_set (vsubkey, "@can_authenticate",
964
+ INT2FIX(subkey->can_authenticate));
965
+ rb_iv_set (vsubkey, "@secret", INT2FIX(subkey->secret));
966
+ rb_iv_set (vsubkey, "@pubkey_algo", INT2FIX(subkey->pubkey_algo));
967
+ rb_iv_set (vsubkey, "@length", UINT2NUM(subkey->length));
968
+ rb_iv_set (vsubkey, "@keyid", rb_str_new2 (subkey->keyid));
969
+ if (subkey->fpr)
970
+ rb_iv_set (vsubkey, "@fpr", rb_str_new2 (subkey->fpr));
971
+ rb_iv_set (vsubkey, "@timestamp", LONG2NUM(subkey->timestamp));
972
+ rb_iv_set (vsubkey, "@expires", LONG2NUM(subkey->expires));
973
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010500
974
+ if (subkey->curve)
975
+ rb_iv_set (vsubkey, "@curve", rb_str_new2 (subkey->curve));
976
+ #endif
977
+ rb_ary_push (vsubkeys, vsubkey);
978
+ }
979
+ vuids = rb_ary_new ();
980
+ rb_iv_set (vkey, "@uids", vuids);
981
+ for (user_id = key->uids; user_id; user_id = user_id->next)
982
+ {
983
+ VALUE vuser_id, vsignatures;
984
+ gpgme_key_sig_t key_sig;
985
+
986
+ vuser_id = rb_class_new_instance(0, NULL, cUserID);
987
+ rb_iv_set (vuser_id, "@revoked", INT2FIX(user_id->revoked));
988
+ rb_iv_set (vuser_id, "@invalid", INT2FIX(user_id->invalid));
989
+ rb_iv_set (vuser_id, "@validity", INT2FIX(user_id->validity));
990
+ rb_iv_set (vuser_id, "@name", utf8_str_new (user_id->name));
991
+ rb_iv_set (vuser_id, "@uid", utf8_str_new (user_id->uid));
992
+ rb_iv_set (vuser_id, "@comment", utf8_str_new (user_id->comment));
993
+ rb_iv_set (vuser_id, "@email", utf8_str_new (user_id->email));
994
+
995
+ vsignatures = rb_ary_new ();
996
+ rb_iv_set (vuser_id, "@signatures", vsignatures);
997
+ for (key_sig = user_id->signatures; key_sig; key_sig = key_sig->next)
998
+ {
999
+ VALUE vkey_sig = rb_class_new_instance(0, NULL, cKeySig);
1000
+ rb_iv_set (vkey_sig, "@revoked", INT2FIX(key_sig->revoked));
1001
+ rb_iv_set (vkey_sig, "@expired", INT2FIX(key_sig->expired));
1002
+ rb_iv_set (vkey_sig, "@invalid", INT2FIX(key_sig->invalid));
1003
+ rb_iv_set (vkey_sig, "@exportable", INT2FIX(key_sig->exportable));
1004
+ rb_iv_set (vkey_sig, "@pubkey_algo", INT2FIX(key_sig->pubkey_algo));
1005
+ rb_iv_set (vkey_sig, "@keyid", rb_str_new2 (key_sig->keyid));
1006
+ rb_iv_set (vkey_sig, "@timestamp", LONG2NUM(key_sig->timestamp));
1007
+ rb_iv_set (vkey_sig, "@expires", LONG2NUM(key_sig->expires));
1008
+ rb_ary_push (vsignatures, vkey_sig);
1009
+ }
1010
+ rb_ary_push (vuids, vuser_id);
1011
+ }
1012
+ return vkey;
1013
+ }
1014
+
1015
+ static VALUE
1016
+ rb_s_gpgme_op_keylist_next (VALUE dummy, VALUE vctx, VALUE rkey)
1017
+ {
1018
+ gpgme_ctx_t ctx;
1019
+ gpgme_key_t key;
1020
+ gpgme_error_t err;
1021
+
1022
+ CHECK_KEYLIST_IN_PROGRESS(vctx);
1023
+
1024
+ UNWRAP_GPGME_CTX(vctx, ctx);
1025
+ if (!ctx)
1026
+ rb_raise (rb_eArgError, "released ctx");
1027
+
1028
+ err = gpgme_op_keylist_next (ctx, &key);
1029
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
1030
+ {
1031
+ VALUE vkey = WRAP_GPGME_KEY(key);
1032
+ save_gpgme_key_attrs (vkey, key);
1033
+ rb_ary_store (rkey, 0, vkey);
1034
+ }
1035
+ return LONG2NUM(err);
1036
+ }
1037
+
1038
+ static VALUE
1039
+ rb_s_gpgme_op_keylist_end (VALUE dummy, VALUE vctx)
1040
+ {
1041
+ gpgme_ctx_t ctx;
1042
+ gpgme_error_t err;
1043
+
1044
+ CHECK_KEYLIST_IN_PROGRESS(vctx);
1045
+
1046
+ UNWRAP_GPGME_CTX(vctx, ctx);
1047
+ if (!ctx)
1048
+ rb_raise (rb_eArgError, "released ctx");
1049
+
1050
+ err = gpgme_op_keylist_end (ctx);
1051
+ RESET_KEYLIST_IN_PROGRESS(vctx);
1052
+ return LONG2NUM(err);
1053
+ }
1054
+
1055
+ static VALUE
1056
+ rb_s_gpgme_get_key (VALUE dummy, VALUE vctx, VALUE vfpr, VALUE rkey,
1057
+ VALUE vsecret)
1058
+ {
1059
+ gpgme_ctx_t ctx;
1060
+ gpgme_error_t err;
1061
+ gpgme_key_t key;
1062
+
1063
+ UNWRAP_GPGME_CTX(vctx, ctx);
1064
+ if (!ctx)
1065
+ rb_raise (rb_eArgError, "released ctx");
1066
+ err = gpgme_get_key (ctx, StringValueCStr(vfpr), &key, NUM2INT(vsecret));
1067
+
1068
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
1069
+ {
1070
+ VALUE vkey = WRAP_GPGME_KEY(key);
1071
+ save_gpgme_key_attrs (vkey, key);
1072
+ rb_ary_store (rkey, 0, vkey);
1073
+ }
1074
+ return LONG2NUM(err);
1075
+ }
1076
+
1077
+ static VALUE
1078
+ rb_s_gpgme_op_genkey (VALUE dummy, VALUE vctx, VALUE vparms, VALUE vpubkey,
1079
+ VALUE vseckey)
1080
+ {
1081
+ gpgme_ctx_t ctx;
1082
+ gpgme_data_t pubkey = NULL, seckey = NULL;
1083
+ gpgme_error_t err;
1084
+
1085
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1086
+
1087
+ UNWRAP_GPGME_CTX(vctx, ctx);
1088
+ if (!ctx)
1089
+ rb_raise (rb_eArgError, "released ctx");
1090
+ if (!NIL_P(vpubkey))
1091
+ UNWRAP_GPGME_DATA(vpubkey, pubkey);
1092
+ if (!NIL_P(vseckey))
1093
+ UNWRAP_GPGME_DATA(vseckey, seckey);
1094
+
1095
+ err = gpgme_op_genkey (ctx, StringValueCStr(vparms), pubkey, seckey);
1096
+ return LONG2NUM(err);
1097
+ }
1098
+
1099
+ static VALUE
1100
+ rb_s_gpgme_op_genkey_start (VALUE dummy, VALUE vctx, VALUE vparms,
1101
+ VALUE vpubkey, VALUE vseckey)
1102
+ {
1103
+ gpgme_ctx_t ctx;
1104
+ gpgme_data_t pubkey = NULL, seckey = NULL;
1105
+ gpgme_error_t err;
1106
+
1107
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1108
+
1109
+ UNWRAP_GPGME_CTX(vctx, ctx);
1110
+ if (!ctx)
1111
+ rb_raise (rb_eArgError, "released ctx");
1112
+ if (!NIL_P(vpubkey))
1113
+ UNWRAP_GPGME_DATA(vpubkey, pubkey);
1114
+ if (!NIL_P(vseckey))
1115
+ UNWRAP_GPGME_DATA(vseckey, seckey);
1116
+
1117
+ err = gpgme_op_genkey_start (ctx, StringValueCStr(vparms), pubkey, seckey);
1118
+ return LONG2NUM(err);
1119
+ }
1120
+
1121
+ static VALUE
1122
+ rb_s_gpgme_op_export (VALUE dummy, VALUE vctx, VALUE vpattern, VALUE vmode,
1123
+ VALUE vkeydata)
1124
+ {
1125
+ gpgme_ctx_t ctx;
1126
+ gpgme_data_t keydata;
1127
+ gpgme_error_t err;
1128
+
1129
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1130
+
1131
+ UNWRAP_GPGME_CTX(vctx, ctx);
1132
+ if (!ctx)
1133
+ rb_raise (rb_eArgError, "released ctx");
1134
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
1135
+
1136
+ err = gpgme_op_export (ctx, StringValueCStr(vpattern), NUM2UINT(vmode),
1137
+ keydata);
1138
+ return LONG2NUM(err);
1139
+ }
1140
+
1141
+ static VALUE
1142
+ rb_s_gpgme_op_export_start (VALUE dummy, VALUE vctx, VALUE vpattern,
1143
+ VALUE vmode, VALUE vkeydata)
1144
+ {
1145
+ gpgme_ctx_t ctx;
1146
+ gpgme_data_t keydata;
1147
+ gpgme_error_t err;
1148
+
1149
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1150
+
1151
+ UNWRAP_GPGME_CTX(vctx, ctx);
1152
+ if (!ctx)
1153
+ rb_raise (rb_eArgError, "released ctx");
1154
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
1155
+
1156
+ err = gpgme_op_export_start (ctx, StringValueCStr(vpattern),
1157
+ NUM2UINT(vmode), keydata);
1158
+ return LONG2NUM(err);
1159
+ }
1160
+
1161
+ static VALUE
1162
+ rb_s_gpgme_op_export_ext (VALUE dummy, VALUE vctx, VALUE vpattern, VALUE vmode,
1163
+ VALUE vkeydata)
1164
+ {
1165
+ gpgme_ctx_t ctx;
1166
+ gpgme_data_t keydata;
1167
+ gpgme_error_t err;
1168
+ const char **pattern;
1169
+ int i;
1170
+
1171
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1172
+
1173
+ UNWRAP_GPGME_CTX(vctx, ctx);
1174
+ if (!ctx)
1175
+ rb_raise (rb_eArgError, "released ctx");
1176
+ pattern = ALLOC_N(const char *, RARRAY_LEN(vpattern));
1177
+ for (i = 0; i < RARRAY_LEN(vpattern); i++)
1178
+ pattern[i] = StringValueCStr(RARRAY_PTR(vpattern)[i]);
1179
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
1180
+
1181
+ err = gpgme_op_export_ext (ctx, pattern, NUM2UINT(vmode), keydata);
1182
+ return LONG2NUM(err);
1183
+ }
1184
+
1185
+ static VALUE
1186
+ rb_s_gpgme_op_export_ext_start (VALUE dummy, VALUE vctx, VALUE vpattern,
1187
+ VALUE vmode, VALUE vkeydata)
1188
+ {
1189
+ gpgme_ctx_t ctx;
1190
+ gpgme_data_t keydata;
1191
+ gpgme_error_t err;
1192
+ const char **pattern;
1193
+ int i;
1194
+
1195
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1196
+
1197
+ UNWRAP_GPGME_CTX(vctx, ctx);
1198
+ if (!ctx)
1199
+ rb_raise (rb_eArgError, "released ctx");
1200
+ pattern = ALLOC_N(const char *, RARRAY_LEN(vpattern));
1201
+ for (i = 0; i < RARRAY_LEN(vpattern); i++)
1202
+ pattern[i] = StringValueCStr(RARRAY_PTR(vpattern)[i]);
1203
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
1204
+
1205
+ err = gpgme_op_export_ext_start (ctx, pattern, NUM2UINT(vmode), keydata);
1206
+ return LONG2NUM(err);
1207
+ }
1208
+
1209
+ #ifdef HAVE_GPGME_OP_EXPORT_KEYS
1210
+ static VALUE
1211
+ rb_s_gpgme_op_export_keys (VALUE dummy, VALUE vctx, VALUE vkeys,
1212
+ VALUE vmode, VALUE vkeydata)
1213
+ {
1214
+ gpgme_ctx_t ctx;
1215
+ gpgme_key_t *keys;
1216
+ gpgme_data_t keydata;
1217
+ gpgme_error_t err;
1218
+ int i;
1219
+
1220
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1221
+
1222
+ UNWRAP_GPGME_CTX(vctx, ctx);
1223
+ if (!ctx)
1224
+ rb_raise (rb_eArgError, "released ctx");
1225
+
1226
+ keys = ALLOC_N(gpgme_key_t, RARRAY_LEN(vkeys) + 1);
1227
+ for (i = 0; i < RARRAY_LEN(vkeys); i++)
1228
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vkeys)[i], keys[i]);
1229
+
1230
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
1231
+
1232
+ err = gpgme_op_export_keys (ctx, keys, NUM2UINT(vmode), keydata);
1233
+ return LONG2NUM(err);
1234
+ }
1235
+
1236
+ static VALUE
1237
+ rb_s_gpgme_op_export_keys_start (VALUE dummy, VALUE vctx, VALUE vkeys,
1238
+ VALUE vmode, VALUE vkeydata)
1239
+ {
1240
+ gpgme_ctx_t ctx;
1241
+ gpgme_key_t *keys;
1242
+ gpgme_data_t keydata;
1243
+ gpgme_error_t err;
1244
+ int i;
1245
+
1246
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1247
+
1248
+ UNWRAP_GPGME_CTX(vctx, ctx);
1249
+ if (!ctx)
1250
+ rb_raise (rb_eArgError, "released ctx");
1251
+
1252
+ keys = ALLOC_N(gpgme_key_t, RARRAY_LEN(vkeys) + 1);
1253
+ for (i = 0; i < RARRAY_LEN(vkeys); i++)
1254
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vkeys)[i], keys[i]);
1255
+
1256
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
1257
+
1258
+ err = gpgme_op_export_keys_start (ctx, keys, NUM2UINT(vmode), keydata);
1259
+ return LONG2NUM(err);
1260
+ }
1261
+ #endif /*HAVE_GPGME_OP_EXPORT_KEYS*/
1262
+
1263
+ static VALUE
1264
+ rb_s_gpgme_op_import (VALUE dummy, VALUE vctx, VALUE vkeydata)
1265
+ {
1266
+ gpgme_ctx_t ctx;
1267
+ gpgme_data_t keydata;
1268
+ gpgme_error_t err;
1269
+
1270
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1271
+
1272
+ UNWRAP_GPGME_CTX(vctx, ctx);
1273
+ if (!ctx)
1274
+ rb_raise (rb_eArgError, "released ctx");
1275
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
1276
+
1277
+ err = gpgme_op_import (ctx, keydata);
1278
+ return LONG2NUM(err);
1279
+ }
1280
+
1281
+ static VALUE
1282
+ rb_s_gpgme_op_import_start (VALUE dummy, VALUE vctx, VALUE vkeydata)
1283
+ {
1284
+ gpgme_ctx_t ctx;
1285
+ gpgme_data_t keydata;
1286
+ gpgme_error_t err;
1287
+
1288
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1289
+
1290
+ UNWRAP_GPGME_CTX(vctx, ctx);
1291
+ if (!ctx)
1292
+ rb_raise (rb_eArgError, "released ctx");
1293
+ UNWRAP_GPGME_DATA(vkeydata, keydata);
1294
+
1295
+ err = gpgme_op_import_start (ctx, keydata);
1296
+ return LONG2NUM(err);
1297
+ }
1298
+
1299
+ #ifdef HAVE_GPGME_OP_EXPORT_KEYS
1300
+ static VALUE
1301
+ rb_s_gpgme_op_import_keys (VALUE dummy, VALUE vctx, VALUE vkeys)
1302
+ {
1303
+ gpgme_ctx_t ctx;
1304
+ gpgme_key_t *keys;
1305
+ gpgme_error_t err;
1306
+ int i;
1307
+
1308
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1309
+
1310
+ UNWRAP_GPGME_CTX(vctx, ctx);
1311
+ if (!ctx)
1312
+ rb_raise (rb_eArgError, "released ctx");
1313
+
1314
+ keys = ALLOC_N(gpgme_key_t, RARRAY_LEN(vkeys) + 1);
1315
+ for (i = 0; i < RARRAY_LEN(vkeys); i++)
1316
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vkeys)[i], keys[i]);
1317
+ keys[i] = NULL;
1318
+
1319
+ err = gpgme_op_import_keys (ctx, keys);
1320
+ return LONG2NUM(err);
1321
+ }
1322
+
1323
+ static VALUE
1324
+ rb_s_gpgme_op_import_keys_start (VALUE dummy, VALUE vctx, VALUE vkeys)
1325
+ {
1326
+ gpgme_ctx_t ctx;
1327
+ gpgme_key_t *keys;
1328
+ gpgme_error_t err;
1329
+ int i;
1330
+
1331
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1332
+
1333
+ UNWRAP_GPGME_CTX(vctx, ctx);
1334
+ if (!ctx)
1335
+ rb_raise (rb_eArgError, "released ctx");
1336
+
1337
+ keys = ALLOC_N(gpgme_key_t, RARRAY_LEN(vkeys) + 1);
1338
+ for (i = 0; i < RARRAY_LEN(vkeys); i++)
1339
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vkeys)[i], keys[i]);
1340
+ keys[i] = NULL;
1341
+
1342
+ err = gpgme_op_import_keys_start (ctx, keys);
1343
+ return LONG2NUM(err);
1344
+ }
1345
+ #endif /*HAVE_GPGME_OP_EXPORT_KEYS*/
1346
+
1347
+ static VALUE
1348
+ rb_s_gpgme_op_import_result (VALUE dummy, VALUE vctx)
1349
+ {
1350
+ gpgme_ctx_t ctx;
1351
+ gpgme_import_result_t result;
1352
+ gpgme_import_status_t status;
1353
+ VALUE vresult, vimports;
1354
+
1355
+ UNWRAP_GPGME_CTX(vctx, ctx);
1356
+ if (!ctx)
1357
+ rb_raise (rb_eArgError, "released ctx");
1358
+
1359
+ result = gpgme_op_import_result (ctx);
1360
+ if (!result)
1361
+ rb_raise (rb_eArgError, "no result");
1362
+
1363
+ vresult = rb_class_new_instance (0, NULL, cImportResult);
1364
+ rb_iv_set (vresult, "@considered", INT2NUM(result->considered));
1365
+ rb_iv_set (vresult, "@no_user_id", INT2NUM(result->no_user_id));
1366
+ rb_iv_set (vresult, "@imported", INT2NUM(result->imported));
1367
+ rb_iv_set (vresult, "@imported_rsa", INT2NUM(result->imported_rsa));
1368
+ rb_iv_set (vresult, "@unchanged", INT2NUM(result->unchanged));
1369
+ rb_iv_set (vresult, "@new_user_ids", INT2NUM(result->new_user_ids));
1370
+ rb_iv_set (vresult, "@new_sub_keys", INT2NUM(result->new_sub_keys));
1371
+ rb_iv_set (vresult, "@new_signatures", INT2NUM(result->new_signatures));
1372
+ rb_iv_set (vresult, "@new_revocations", INT2NUM(result->new_revocations));
1373
+ rb_iv_set (vresult, "@secret_read", INT2NUM(result->secret_read));
1374
+ rb_iv_set (vresult, "@secret_imported", INT2NUM(result->secret_imported));
1375
+ rb_iv_set (vresult, "@secret_unchanged", INT2NUM(result->secret_unchanged));
1376
+ rb_iv_set (vresult, "@not_imported", INT2NUM(result->not_imported));
1377
+ vimports = rb_ary_new ();
1378
+ rb_iv_set (vresult, "@imports", vimports);
1379
+ for (status = result->imports; status;
1380
+ status = status->next)
1381
+ {
1382
+ VALUE vstatus =
1383
+ rb_class_new_instance (0, NULL, cImportStatus);
1384
+ rb_iv_set (vstatus, "@fpr", rb_str_new2 (status->fpr));
1385
+ rb_iv_set (vstatus, "@result", LONG2NUM(status->result));
1386
+ rb_iv_set (vstatus, "@status", UINT2NUM(status->status));
1387
+ rb_ary_push (vimports, vstatus);
1388
+ }
1389
+ return vresult;
1390
+ }
1391
+
1392
+ static VALUE
1393
+ rb_s_gpgme_op_delete (VALUE dummy, VALUE vctx, VALUE vkey, VALUE vallow_secret)
1394
+ {
1395
+ gpgme_ctx_t ctx;
1396
+ gpgme_key_t key;
1397
+ gpgme_error_t err;
1398
+
1399
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1400
+
1401
+ UNWRAP_GPGME_CTX(vctx, ctx);
1402
+ if (!ctx)
1403
+ rb_raise (rb_eArgError, "released ctx");
1404
+ UNWRAP_GPGME_KEY(vkey, key);
1405
+
1406
+ err = gpgme_op_delete (ctx, key, NUM2INT(vallow_secret));
1407
+ return LONG2NUM(err);
1408
+ }
1409
+
1410
+ static VALUE
1411
+ rb_s_gpgme_op_delete_start (VALUE dummy, VALUE vctx, VALUE vkey,
1412
+ VALUE vallow_secret)
1413
+ {
1414
+ gpgme_ctx_t ctx;
1415
+ gpgme_key_t key;
1416
+ gpgme_error_t err;
1417
+
1418
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1419
+
1420
+ UNWRAP_GPGME_CTX(vctx, ctx);
1421
+ if (!ctx)
1422
+ rb_raise (rb_eArgError, "released ctx");
1423
+ UNWRAP_GPGME_KEY(vkey, key);
1424
+
1425
+ err = gpgme_op_delete_start (ctx, key, NUM2INT(vallow_secret));
1426
+ return LONG2NUM(err);
1427
+ }
1428
+
1429
+ static gpgme_error_t
1430
+ edit_cb (void *hook, gpgme_status_code_t status, const char *args, int fd)
1431
+ {
1432
+ VALUE vcb = (VALUE)hook, veditfunc, vhook_value;
1433
+
1434
+
1435
+ veditfunc = RARRAY_PTR(vcb)[0];
1436
+ vhook_value = RARRAY_PTR(vcb)[1];
1437
+
1438
+ rb_funcall (veditfunc, rb_intern ("call"), 4, vhook_value, INT2FIX(status),
1439
+ rb_str_new2 (args), INT2NUM(fd));
1440
+ return gpgme_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_NO_ERROR);
1441
+ }
1442
+
1443
+ static VALUE
1444
+ rb_s_gpgme_op_edit (VALUE dummy, VALUE vctx, VALUE vkey,
1445
+ VALUE veditfunc, VALUE vhook_value, VALUE vout)
1446
+ {
1447
+ gpgme_ctx_t ctx;
1448
+ gpgme_key_t key;
1449
+ gpgme_data_t out = NULL;
1450
+ VALUE vcb;
1451
+ gpgme_error_t err;
1452
+
1453
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1454
+
1455
+ UNWRAP_GPGME_CTX(vctx, ctx);
1456
+ if (!ctx)
1457
+ rb_raise (rb_eArgError, "released ctx");
1458
+ UNWRAP_GPGME_KEY(vkey, key);
1459
+ if (!NIL_P(vout))
1460
+ UNWRAP_GPGME_DATA(vout, out);
1461
+
1462
+ vcb = rb_ary_new ();
1463
+ rb_ary_push (vcb, veditfunc);
1464
+ rb_ary_push (vcb, vhook_value);
1465
+ /* Keep a reference to avoid GC. */
1466
+ rb_iv_set (vctx, "@edit_cb", vcb);
1467
+
1468
+ err = gpgme_op_edit (ctx, key, edit_cb, (void *)vcb, out);
1469
+ return LONG2NUM(err);
1470
+ }
1471
+
1472
+ static VALUE
1473
+ rb_s_gpgme_op_edit_start (VALUE dummy, VALUE vctx, VALUE vkey,
1474
+ VALUE veditfunc, VALUE vhook_value, VALUE vout)
1475
+ {
1476
+ gpgme_ctx_t ctx;
1477
+ gpgme_key_t key;
1478
+ gpgme_data_t out = NULL;
1479
+ VALUE vcb;
1480
+ gpgme_error_t err;
1481
+
1482
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1483
+
1484
+ UNWRAP_GPGME_CTX(vctx, ctx);
1485
+ if (!ctx)
1486
+ rb_raise (rb_eArgError, "released ctx");
1487
+ UNWRAP_GPGME_KEY(vkey, key);
1488
+ if (!NIL_P(vout))
1489
+ UNWRAP_GPGME_DATA(vout, out);
1490
+
1491
+ vcb = rb_ary_new ();
1492
+ rb_ary_push (vcb, veditfunc);
1493
+ rb_ary_push (vcb, vhook_value);
1494
+ /* Keep a reference to avoid GC. */
1495
+ rb_iv_set (vctx, "@edit_cb", vcb);
1496
+
1497
+ err = gpgme_op_edit_start (ctx, key, edit_cb, (void *)vcb, out);
1498
+ return LONG2NUM(err);
1499
+ }
1500
+
1501
+ static VALUE
1502
+ rb_s_gpgme_op_card_edit (VALUE dummy, VALUE vctx, VALUE vkey,
1503
+ VALUE veditfunc, VALUE vhook_value, VALUE vout)
1504
+ {
1505
+ gpgme_ctx_t ctx;
1506
+ gpgme_key_t key;
1507
+ gpgme_data_t out = NULL;
1508
+ VALUE vcb;
1509
+ gpgme_error_t err;
1510
+
1511
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1512
+
1513
+ UNWRAP_GPGME_CTX(vctx, ctx);
1514
+ if (!ctx)
1515
+ rb_raise (rb_eArgError, "released ctx");
1516
+ UNWRAP_GPGME_KEY(vkey, key);
1517
+ if (!NIL_P(vout))
1518
+ UNWRAP_GPGME_DATA(vout, out);
1519
+
1520
+ vcb = rb_ary_new ();
1521
+ rb_ary_push (vcb, veditfunc);
1522
+ rb_ary_push (vcb, vhook_value);
1523
+ /* Keep a reference to avoid GC. */
1524
+ rb_iv_set (vctx, "@card_edit_cb", vcb);
1525
+
1526
+ err = gpgme_op_card_edit (ctx, key, edit_cb, (void *)vcb, out);
1527
+ return LONG2NUM(err);
1528
+ }
1529
+
1530
+ static VALUE
1531
+ rb_s_gpgme_op_card_edit_start (VALUE dummy, VALUE vctx, VALUE vkey,
1532
+ VALUE veditfunc, VALUE vhook_value, VALUE vout)
1533
+ {
1534
+ gpgme_ctx_t ctx;
1535
+ gpgme_key_t key;
1536
+ gpgme_data_t out = NULL;
1537
+ VALUE vcb;
1538
+ gpgme_error_t err;
1539
+
1540
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1541
+
1542
+ UNWRAP_GPGME_CTX(vctx, ctx);
1543
+ if (!ctx)
1544
+ rb_raise (rb_eArgError, "released ctx");
1545
+ UNWRAP_GPGME_KEY(vkey, key);
1546
+ if (!NIL_P(vout))
1547
+ UNWRAP_GPGME_DATA(vout, out);
1548
+
1549
+ vcb = rb_ary_new ();
1550
+ rb_ary_push (vcb, veditfunc);
1551
+ rb_ary_push (vcb, vhook_value);
1552
+ /* Keep a reference to avoid GC. */
1553
+ rb_iv_set (vctx, "@card_edit_cb", vcb);
1554
+
1555
+ err = gpgme_op_card_edit_start (ctx, key, edit_cb, (void *)vcb, out);
1556
+ return LONG2NUM(err);
1557
+ }
1558
+
1559
+ static VALUE
1560
+ rb_s_gpgme_op_trustlist_start (VALUE dummy, VALUE vctx, VALUE vpattern,
1561
+ VALUE vmax_level)
1562
+ {
1563
+ gpgme_ctx_t ctx;
1564
+ gpgme_error_t err;
1565
+
1566
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1567
+
1568
+ UNWRAP_GPGME_CTX(vctx, ctx);
1569
+ if (!ctx)
1570
+ rb_raise (rb_eArgError, "released ctx");
1571
+ err = gpgme_op_trustlist_start (ctx, StringValueCStr(vpattern),
1572
+ NUM2INT(vmax_level));
1573
+ return LONG2NUM(err);
1574
+ }
1575
+
1576
+ static VALUE
1577
+ rb_s_gpgme_op_trustlist_next (VALUE dummy, VALUE vctx, VALUE ritem)
1578
+ {
1579
+ gpgme_ctx_t ctx;
1580
+ gpgme_trust_item_t item;
1581
+ gpgme_error_t err;
1582
+ VALUE vitem;
1583
+
1584
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1585
+
1586
+ UNWRAP_GPGME_CTX(vctx, ctx);
1587
+ if (!ctx)
1588
+ rb_raise (rb_eArgError, "released ctx");
1589
+
1590
+ err = gpgme_op_trustlist_next (ctx, &item);
1591
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
1592
+ {
1593
+ vitem = WRAP_GPGME_TRUST_ITEM(item);
1594
+ rb_iv_set (vitem, "@keyid", rb_str_new2 (item->keyid));
1595
+ rb_iv_set (vitem, "@type", INT2FIX(item->type));
1596
+ rb_iv_set (vitem, "@level", INT2FIX(item->level));
1597
+ if (item->owner_trust)
1598
+ rb_iv_set (vitem, "@owner_trust", rb_str_new2 (item->owner_trust));
1599
+ rb_iv_set (vitem, "@validity", rb_str_new2 (item->validity));
1600
+ if (item->name)
1601
+ rb_iv_set (vitem, "@name", rb_str_new2 (item->name));
1602
+ rb_ary_store (ritem, 0, vitem);
1603
+ }
1604
+ return LONG2NUM(err);
1605
+ }
1606
+
1607
+ static VALUE
1608
+ rb_s_gpgme_op_trustlist_end (VALUE dummy, VALUE vctx)
1609
+ {
1610
+ gpgme_ctx_t ctx;
1611
+ gpgme_error_t err;
1612
+
1613
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1614
+
1615
+ UNWRAP_GPGME_CTX(vctx, ctx);
1616
+ if (!ctx)
1617
+ rb_raise (rb_eArgError, "released ctx");
1618
+
1619
+ err = gpgme_op_trustlist_end (ctx);
1620
+ return LONG2NUM(err);
1621
+ }
1622
+
1623
+ static VALUE
1624
+ rb_s_gpgme_op_decrypt (VALUE dummy, VALUE vctx, VALUE vcipher, VALUE vplain)
1625
+ {
1626
+ gpgme_ctx_t ctx;
1627
+ gpgme_data_t cipher, plain;
1628
+ gpgme_error_t err;
1629
+
1630
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1631
+
1632
+ UNWRAP_GPGME_CTX(vctx, ctx);
1633
+ if (!ctx)
1634
+ rb_raise (rb_eArgError, "released ctx");
1635
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1636
+ UNWRAP_GPGME_DATA(vplain, plain);
1637
+
1638
+ err = gpgme_op_decrypt (ctx, cipher, plain);
1639
+ return LONG2NUM(err);
1640
+ }
1641
+
1642
+ static VALUE
1643
+ rb_s_gpgme_op_decrypt_start (VALUE dummy, VALUE vctx, VALUE vcipher,
1644
+ VALUE vplain)
1645
+ {
1646
+ gpgme_ctx_t ctx;
1647
+ gpgme_data_t cipher, plain;
1648
+ gpgme_error_t err;
1649
+
1650
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1651
+
1652
+ UNWRAP_GPGME_CTX(vctx, ctx);
1653
+ if (!ctx)
1654
+ rb_raise (rb_eArgError, "released ctx");
1655
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1656
+ UNWRAP_GPGME_DATA(vplain, plain);
1657
+
1658
+ err = gpgme_op_decrypt_start (ctx, cipher, plain);
1659
+ return LONG2NUM(err);
1660
+ }
1661
+
1662
+ static VALUE
1663
+ rb_s_gpgme_op_decrypt_result (VALUE dummy, VALUE vctx)
1664
+ {
1665
+ gpgme_ctx_t ctx;
1666
+ gpgme_decrypt_result_t result;
1667
+ gpgme_recipient_t recipient;
1668
+ VALUE vresult, vrecipients;
1669
+
1670
+ UNWRAP_GPGME_CTX(vctx, ctx);
1671
+ if (!ctx)
1672
+ rb_raise (rb_eArgError, "released ctx");
1673
+
1674
+ result = gpgme_op_decrypt_result (ctx);
1675
+ if (!result)
1676
+ rb_raise (rb_eArgError, "no result");
1677
+
1678
+ vresult = rb_class_new_instance (0, NULL, cDecryptResult);
1679
+ if (result->unsupported_algorithm)
1680
+ rb_iv_set (vresult, "@unsupported_algorithm",
1681
+ rb_str_new2 (result->unsupported_algorithm));
1682
+ rb_iv_set (vresult, "@wrong_key_usage", INT2FIX(result->wrong_key_usage));
1683
+ vrecipients = rb_ary_new ();
1684
+ rb_iv_set (vresult, "@recipients", vrecipients);
1685
+ for (recipient = result->recipients; recipient; recipient = recipient->next)
1686
+ {
1687
+ VALUE vrecipient = rb_class_new_instance (0, NULL, cRecipient);
1688
+ rb_iv_set (vrecipient, "@pubkey_algo", INT2FIX(recipient->pubkey_algo));
1689
+ rb_iv_set (vrecipient, "@keyid", rb_str_new2 (recipient->keyid));
1690
+ rb_iv_set (vrecipient, "@status", UINT2NUM(recipient->status));
1691
+ rb_ary_push (vrecipients, vrecipient);
1692
+ }
1693
+ if (result->file_name)
1694
+ rb_iv_set (vresult, "@file_name", rb_str_new2 (result->file_name));
1695
+ return vresult;
1696
+ }
1697
+
1698
+ static VALUE
1699
+ rb_s_gpgme_op_verify (VALUE dummy, VALUE vctx, VALUE vsig, VALUE vsigned_text,
1700
+ VALUE vplain)
1701
+ {
1702
+ gpgme_ctx_t ctx;
1703
+ gpgme_data_t sig, signed_text = NULL, plain = NULL;
1704
+ gpgme_error_t err;
1705
+
1706
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1707
+
1708
+ UNWRAP_GPGME_CTX(vctx, ctx);
1709
+ if (!ctx)
1710
+ rb_raise (rb_eArgError, "released ctx");
1711
+ UNWRAP_GPGME_DATA(vsig, sig);
1712
+ if (!NIL_P(vsigned_text))
1713
+ UNWRAP_GPGME_DATA(vsigned_text, signed_text);
1714
+ if (!NIL_P(vplain))
1715
+ UNWRAP_GPGME_DATA(vplain, plain);
1716
+
1717
+ err = gpgme_op_verify (ctx, sig, signed_text, plain);
1718
+ return LONG2NUM(err);
1719
+ }
1720
+
1721
+ static VALUE
1722
+ rb_s_gpgme_op_verify_start (VALUE dummy, VALUE vctx, VALUE vsig,
1723
+ VALUE vsigned_text, VALUE vplain)
1724
+ {
1725
+ gpgme_ctx_t ctx;
1726
+ gpgme_data_t sig, signed_text = NULL, plain = NULL;
1727
+ gpgme_error_t err;
1728
+
1729
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1730
+
1731
+ UNWRAP_GPGME_CTX(vctx, ctx);
1732
+ if (!ctx)
1733
+ rb_raise (rb_eArgError, "released ctx");
1734
+ UNWRAP_GPGME_DATA(vsig, sig);
1735
+ if (!NIL_P(vsigned_text))
1736
+ UNWRAP_GPGME_DATA(vsigned_text, signed_text);
1737
+ if (!NIL_P(vplain))
1738
+ UNWRAP_GPGME_DATA(vplain, plain);
1739
+
1740
+ err = gpgme_op_verify_start (ctx, sig, signed_text, plain);
1741
+ return LONG2NUM(err);
1742
+ }
1743
+
1744
+ static VALUE
1745
+ rb_s_gpgme_op_verify_result (VALUE dummy, VALUE vctx)
1746
+ {
1747
+ gpgme_ctx_t ctx;
1748
+ gpgme_verify_result_t verify_result;
1749
+ gpgme_signature_t signature;
1750
+ VALUE vverify_result, vsignatures = rb_ary_new ();
1751
+
1752
+ UNWRAP_GPGME_CTX(vctx, ctx);
1753
+ if (!ctx)
1754
+ rb_raise (rb_eArgError, "released ctx");
1755
+
1756
+ verify_result = gpgme_op_verify_result (ctx);
1757
+ if (!verify_result)
1758
+ rb_raise (rb_eArgError, "no result");
1759
+
1760
+ vverify_result = rb_class_new_instance(0, NULL, cVerifyResult);
1761
+ rb_iv_set (vverify_result, "@signatures", vsignatures);
1762
+ for (signature = verify_result->signatures; signature;
1763
+ signature = signature->next)
1764
+ {
1765
+ VALUE vsignature = rb_class_new_instance(0, NULL, cSignature),
1766
+ vnotations = rb_ary_new ();
1767
+ gpgme_sig_notation_t notation;
1768
+ rb_iv_set (vsignature, "@summary", INT2FIX(signature->summary));
1769
+ rb_iv_set (vsignature, "@fpr", rb_str_new2 (signature->fpr));
1770
+ rb_iv_set (vsignature, "@status", LONG2NUM(signature->status));
1771
+ rb_iv_set (vsignature, "@notations", vnotations);
1772
+ for (notation = signature->notations; notation;
1773
+ notation = notation->next)
1774
+ {
1775
+ VALUE vnotation = rb_class_new_instance(0, NULL, cSigNotation);
1776
+ /* The docs say:
1777
+ * The name of the notation field. If this is NULL, then the member
1778
+ * value will contain a policy URL. */
1779
+ if (notation->name == NULL)
1780
+ rb_iv_set (vnotation, "@name", Qnil);
1781
+ else
1782
+ rb_iv_set (vnotation, "@name", rb_str_new2 (notation->name));
1783
+ rb_iv_set (vnotation, "@value", rb_str_new2 (notation->value));
1784
+ rb_ary_push (vnotations, vnotation);
1785
+ }
1786
+ rb_iv_set (vsignature, "@timestamp", ULONG2NUM(signature->timestamp));
1787
+ rb_iv_set (vsignature, "@exp_timestamp",
1788
+ ULONG2NUM(signature->exp_timestamp));
1789
+ rb_iv_set (vsignature, "@wrong_key_usage",
1790
+ INT2FIX(signature->wrong_key_usage));
1791
+ rb_iv_set (vsignature, "@validity", INT2FIX(signature->validity));
1792
+ rb_iv_set (vsignature, "@validity_reason",
1793
+ LONG2NUM(signature->validity_reason));
1794
+ /* PKA related fields were added in 1.1.1. */
1795
+ #ifdef GPGME_STATUS_PKA_TRUST_BAD
1796
+ rb_iv_set (vsignature, "@pka_trust", INT2FIX(signature->pka_trust));
1797
+ rb_iv_set (vsignature, "@pka_address",
1798
+ rb_str_new2 (signature->pka_address));
1799
+ #endif
1800
+ rb_ary_push (vsignatures, vsignature);
1801
+ }
1802
+ return vverify_result;
1803
+ }
1804
+
1805
+ static VALUE
1806
+ rb_s_gpgme_op_decrypt_verify (VALUE dummy, VALUE vctx, VALUE vcipher,
1807
+ VALUE vplain)
1808
+ {
1809
+ gpgme_ctx_t ctx;
1810
+ gpgme_data_t cipher, plain;
1811
+ gpgme_error_t err;
1812
+
1813
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1814
+
1815
+ UNWRAP_GPGME_CTX(vctx, ctx);
1816
+ if (!ctx)
1817
+ rb_raise (rb_eArgError, "released ctx");
1818
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1819
+ UNWRAP_GPGME_DATA(vplain, plain);
1820
+
1821
+ err = gpgme_op_decrypt_verify (ctx, cipher, plain);
1822
+ return LONG2NUM(err);
1823
+ }
1824
+
1825
+ static VALUE
1826
+ rb_s_gpgme_op_decrypt_verify_start (VALUE dummy, VALUE vctx, VALUE vcipher,
1827
+ VALUE vplain)
1828
+ {
1829
+ gpgme_ctx_t ctx;
1830
+ gpgme_data_t cipher, plain;
1831
+ gpgme_error_t err;
1832
+
1833
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1834
+
1835
+ UNWRAP_GPGME_CTX(vctx, ctx);
1836
+ if (!ctx)
1837
+ rb_raise (rb_eArgError, "released ctx");
1838
+ UNWRAP_GPGME_DATA(vcipher, cipher);
1839
+ UNWRAP_GPGME_DATA(vplain, plain);
1840
+
1841
+ err = gpgme_op_decrypt_verify_start (ctx, cipher, plain);
1842
+ return LONG2NUM(err);
1843
+ }
1844
+
1845
+ static VALUE
1846
+ rb_s_gpgme_signers_clear (VALUE dummy, VALUE vctx)
1847
+ {
1848
+ gpgme_ctx_t ctx;
1849
+
1850
+ UNWRAP_GPGME_CTX(vctx, ctx);
1851
+ if (!ctx)
1852
+ rb_raise (rb_eArgError, "released ctx");
1853
+ gpgme_signers_clear (ctx);
1854
+ return Qnil;
1855
+ }
1856
+
1857
+ static VALUE
1858
+ rb_s_gpgme_signers_add (VALUE dummy, VALUE vctx, VALUE vkey)
1859
+ {
1860
+ gpgme_ctx_t ctx;
1861
+ gpgme_key_t key;
1862
+ gpgme_error_t err;
1863
+
1864
+ UNWRAP_GPGME_CTX(vctx, ctx);
1865
+ if (!ctx)
1866
+ rb_raise (rb_eArgError, "released ctx");
1867
+ UNWRAP_GPGME_KEY(vkey, key);
1868
+
1869
+ err = gpgme_signers_add (ctx, key);
1870
+ return LONG2NUM(err);
1871
+ }
1872
+
1873
+ static VALUE
1874
+ rb_s_gpgme_signers_enum (VALUE dummy, VALUE vctx, VALUE vseq)
1875
+ {
1876
+ gpgme_ctx_t ctx;
1877
+ gpgme_key_t key;
1878
+
1879
+ UNWRAP_GPGME_CTX(vctx, ctx);
1880
+ if (!ctx)
1881
+ rb_raise (rb_eArgError, "released ctx");
1882
+
1883
+ key = gpgme_signers_enum (ctx, NUM2INT(vseq));
1884
+ if (!key)
1885
+ return Qnil;
1886
+ return WRAP_GPGME_KEY(key);
1887
+ }
1888
+
1889
+ static VALUE
1890
+ rb_s_gpgme_op_sign (VALUE dummy, VALUE vctx, VALUE vplain, VALUE vsig,
1891
+ VALUE vmode)
1892
+ {
1893
+ gpgme_ctx_t ctx;
1894
+ gpgme_data_t plain, sig;
1895
+ gpgme_error_t err;
1896
+
1897
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1898
+
1899
+ UNWRAP_GPGME_CTX(vctx, ctx);
1900
+ if (!ctx)
1901
+ rb_raise (rb_eArgError, "released ctx");
1902
+ UNWRAP_GPGME_DATA(vplain, plain);
1903
+ UNWRAP_GPGME_DATA(vsig, sig);
1904
+
1905
+ err = gpgme_op_sign (ctx, plain, sig, NUM2INT(vmode));
1906
+ return LONG2NUM(err);
1907
+ }
1908
+
1909
+ static VALUE
1910
+ rb_s_gpgme_op_sign_start (VALUE dummy, VALUE vctx, VALUE vplain, VALUE vsig,
1911
+ VALUE vmode)
1912
+ {
1913
+ gpgme_ctx_t ctx;
1914
+ gpgme_data_t plain, sig;
1915
+ gpgme_error_t err;
1916
+
1917
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1918
+
1919
+ UNWRAP_GPGME_CTX(vctx, ctx);
1920
+ if (!ctx)
1921
+ rb_raise (rb_eArgError, "released ctx");
1922
+ UNWRAP_GPGME_DATA(vplain, plain);
1923
+ UNWRAP_GPGME_DATA(vsig, sig);
1924
+
1925
+ err = gpgme_op_sign_start (ctx, plain, sig, NUM2INT(vmode));
1926
+ return LONG2NUM(err);
1927
+ }
1928
+
1929
+ static VALUE
1930
+ rb_s_gpgme_op_sign_result (VALUE dummy, VALUE vctx)
1931
+ {
1932
+ gpgme_ctx_t ctx;
1933
+ gpgme_sign_result_t result;
1934
+ gpgme_invalid_key_t invalid_key;
1935
+ gpgme_new_signature_t new_signature;
1936
+ VALUE vresult, vinvalid_signers, vsignatures;
1937
+
1938
+ UNWRAP_GPGME_CTX(vctx, ctx);
1939
+ if (!ctx)
1940
+ rb_raise (rb_eArgError, "released ctx");
1941
+
1942
+ result = gpgme_op_sign_result (ctx);
1943
+ if (!result)
1944
+ rb_raise (rb_eArgError, "no result");
1945
+
1946
+ vresult = rb_class_new_instance (0, NULL, cSignResult);
1947
+ vinvalid_signers = rb_ary_new ();
1948
+ rb_iv_set (vresult, "@invalid_signers", vinvalid_signers);
1949
+ for (invalid_key = result->invalid_signers; invalid_key;
1950
+ invalid_key = invalid_key->next)
1951
+ {
1952
+ VALUE vinvalid_key =
1953
+ rb_class_new_instance (0, NULL, cInvalidKey);
1954
+ rb_iv_set (vinvalid_key, "@fpr", rb_str_new2 (invalid_key->fpr));
1955
+ rb_iv_set (vinvalid_key, "@reason", LONG2NUM(invalid_key->reason));
1956
+ rb_ary_push (vinvalid_signers, vinvalid_key);
1957
+ }
1958
+ vsignatures = rb_ary_new ();
1959
+ rb_iv_set (vresult, "@signatures", vsignatures);
1960
+ for (new_signature = result->signatures; new_signature;
1961
+ new_signature = new_signature->next)
1962
+ {
1963
+ VALUE vnew_signature =
1964
+ rb_class_new_instance (0, NULL, cNewSignature);
1965
+ rb_iv_set (vnew_signature, "@type", INT2FIX(new_signature->type));
1966
+ rb_iv_set (vnew_signature, "@pubkey_algo",
1967
+ INT2FIX(new_signature->pubkey_algo));
1968
+ rb_iv_set (vnew_signature, "@hash_algo",
1969
+ INT2FIX(new_signature->hash_algo));
1970
+ rb_iv_set (vnew_signature, "@sig_class",
1971
+ UINT2NUM(new_signature->sig_class));
1972
+ rb_iv_set (vnew_signature, "@timestamp",
1973
+ LONG2NUM(new_signature->timestamp));
1974
+ rb_iv_set (vnew_signature, "@fpr", rb_str_new2 (new_signature->fpr));
1975
+ rb_ary_push (vsignatures, vnew_signature);
1976
+ }
1977
+ return vresult;
1978
+ }
1979
+
1980
+ static VALUE
1981
+ rb_s_gpgme_op_encrypt (VALUE dummy, VALUE vctx, VALUE vrecp, VALUE vflags,
1982
+ VALUE vplain, VALUE vcipher)
1983
+ {
1984
+ gpgme_ctx_t ctx;
1985
+ gpgme_key_t *recp = NULL;
1986
+ gpgme_data_t plain, cipher;
1987
+ gpgme_error_t err;
1988
+
1989
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1990
+
1991
+ UNWRAP_GPGME_CTX(vctx, ctx);
1992
+ if (!ctx)
1993
+ rb_raise (rb_eArgError, "released ctx");
1994
+ /* If RECP is `NULL', symmetric rather than public key encryption is
1995
+ performed. */
1996
+ if (!NIL_P(vrecp))
1997
+ {
1998
+ int i;
1999
+ recp = ALLOC_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
2000
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
2001
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
2002
+ recp[i] = NULL;
2003
+ }
2004
+ UNWRAP_GPGME_DATA(vplain, plain);
2005
+ UNWRAP_GPGME_DATA(vcipher, cipher);
2006
+
2007
+ err = gpgme_op_encrypt (ctx, recp, NUM2INT(vflags), plain, cipher);
2008
+ if (recp)
2009
+ xfree (recp);
2010
+ return LONG2NUM(err);
2011
+ }
2012
+
2013
+ static VALUE
2014
+ rb_s_gpgme_op_encrypt_start (VALUE dummy, VALUE vctx, VALUE vrecp,
2015
+ VALUE vflags, VALUE vplain, VALUE vcipher)
2016
+ {
2017
+ gpgme_ctx_t ctx;
2018
+ gpgme_key_t *recp = NULL;
2019
+ gpgme_data_t plain, cipher;
2020
+ gpgme_error_t err;
2021
+
2022
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
2023
+
2024
+ UNWRAP_GPGME_CTX(vctx, ctx);
2025
+ if (!ctx)
2026
+ rb_raise (rb_eArgError, "released ctx");
2027
+ /* If RECP is `NULL', symmetric rather than public key encryption is
2028
+ performed. */
2029
+ if (!NIL_P(vrecp))
2030
+ {
2031
+ int i;
2032
+ recp = ALLOC_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
2033
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
2034
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
2035
+ recp[i] = NULL;
2036
+ }
2037
+ UNWRAP_GPGME_DATA(vplain, plain);
2038
+ UNWRAP_GPGME_DATA(vcipher, cipher);
2039
+
2040
+ err = gpgme_op_encrypt_start (ctx, recp, NUM2INT(vflags), plain, cipher);
2041
+ if (recp)
2042
+ xfree (recp);
2043
+ return LONG2NUM(err);
2044
+ }
2045
+
2046
+ static VALUE
2047
+ rb_s_gpgme_op_encrypt_result (VALUE dummy, VALUE vctx)
2048
+ {
2049
+ gpgme_ctx_t ctx;
2050
+ gpgme_encrypt_result_t result;
2051
+ gpgme_invalid_key_t invalid_key;
2052
+ VALUE vresult, vinvalid_recipients;
2053
+
2054
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
2055
+
2056
+ UNWRAP_GPGME_CTX(vctx, ctx);
2057
+ if (!ctx)
2058
+ rb_raise (rb_eArgError, "released ctx");
2059
+
2060
+ result = gpgme_op_encrypt_result (ctx);
2061
+ if (!result)
2062
+ rb_raise (rb_eArgError, "no result");
2063
+
2064
+ vresult = rb_class_new_instance (0, NULL, cEncryptResult);
2065
+ vinvalid_recipients = rb_ary_new ();
2066
+ rb_iv_set (vresult, "@invalid_recipients", vinvalid_recipients);
2067
+ for (invalid_key = result->invalid_recipients; invalid_key;
2068
+ invalid_key = invalid_key->next)
2069
+ {
2070
+ VALUE vinvalid_key =
2071
+ rb_class_new_instance (0, NULL, cInvalidKey);
2072
+ rb_iv_set (vinvalid_key, "@fpr", rb_str_new2 (invalid_key->fpr));
2073
+ rb_iv_set (vinvalid_key, "@reason", LONG2NUM(invalid_key->reason));
2074
+ rb_ary_push (vinvalid_recipients, vinvalid_key);
2075
+ }
2076
+ return vresult;
2077
+ }
2078
+
2079
+ static VALUE
2080
+ rb_s_gpgme_op_encrypt_sign (VALUE dummy, VALUE vctx, VALUE vrecp, VALUE vflags,
2081
+ VALUE vplain, VALUE vcipher)
2082
+ {
2083
+ gpgme_ctx_t ctx;
2084
+ gpgme_key_t *recp = NULL;
2085
+ gpgme_data_t plain, cipher;
2086
+ gpgme_error_t err;
2087
+
2088
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
2089
+
2090
+ UNWRAP_GPGME_CTX(vctx, ctx);
2091
+ if (!ctx)
2092
+ rb_raise (rb_eArgError, "released ctx");
2093
+ /* If RECP is `NULL', symmetric rather than public key encryption is
2094
+ performed. */
2095
+ if (!NIL_P(vrecp))
2096
+ {
2097
+ int i;
2098
+ recp = ALLOC_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
2099
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
2100
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
2101
+ recp[i] = NULL;
2102
+ }
2103
+ UNWRAP_GPGME_DATA(vplain, plain);
2104
+ UNWRAP_GPGME_DATA(vcipher, cipher);
2105
+
2106
+ err = gpgme_op_encrypt_sign (ctx, recp, NUM2INT(vflags), plain, cipher);
2107
+ if (recp)
2108
+ xfree (recp);
2109
+ return LONG2NUM(err);
2110
+ }
2111
+
2112
+ static VALUE
2113
+ rb_s_gpgme_op_encrypt_sign_start (VALUE dummy, VALUE vctx, VALUE vrecp,
2114
+ VALUE vflags, VALUE vplain, VALUE vcipher)
2115
+ {
2116
+ gpgme_ctx_t ctx;
2117
+ gpgme_key_t *recp = NULL;
2118
+ gpgme_data_t plain, cipher;
2119
+ gpgme_error_t err;
2120
+
2121
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
2122
+
2123
+ UNWRAP_GPGME_CTX(vctx, ctx);
2124
+ if (!ctx)
2125
+ rb_raise (rb_eArgError, "released ctx");
2126
+ /* If RECP is `NULL', symmetric rather than public key encryption is
2127
+ performed. */
2128
+ if (!NIL_P(vrecp))
2129
+ {
2130
+ int i;
2131
+ recp = ALLOC_N(gpgme_key_t, RARRAY_LEN(vrecp) + 1);
2132
+ for (i = 0; i < RARRAY_LEN(vrecp); i++)
2133
+ UNWRAP_GPGME_KEY(RARRAY_PTR(vrecp)[i], recp[i]);
2134
+ recp[i] = NULL;
2135
+ }
2136
+ UNWRAP_GPGME_DATA(vplain, plain);
2137
+ UNWRAP_GPGME_DATA(vcipher, cipher);
2138
+
2139
+ err = gpgme_op_encrypt_sign_start (ctx, recp, NUM2INT(vflags), plain,
2140
+ cipher);
2141
+ if (recp)
2142
+ xfree (recp);
2143
+ return LONG2NUM(err);
2144
+ }
2145
+
2146
+ static VALUE
2147
+ rb_s_gpgme_wait (VALUE dummy, VALUE vctx, VALUE rstatus, VALUE vhang)
2148
+ {
2149
+ gpgme_ctx_t ctx = NULL, ret;
2150
+ gpgme_error_t status;
2151
+
2152
+ /* The CTX argument can be `NULL'. In that case, `gpgme_wait' waits
2153
+ for any context to complete its operation. */
2154
+ if (!NIL_P(vctx))
2155
+ {
2156
+ UNWRAP_GPGME_CTX(vctx, ctx);
2157
+ if (!ctx)
2158
+ rb_raise (rb_eArgError, "released ctx");
2159
+ }
2160
+
2161
+ ret = gpgme_wait (ctx, &status, NUM2INT(vhang));
2162
+ if (ret)
2163
+ {
2164
+ rb_ary_store (rstatus, 0, INT2NUM(status));
2165
+ if (ret != ctx)
2166
+ vctx = WRAP_GPGME_CTX(ret);
2167
+ return vctx;
2168
+ }
2169
+ return Qnil;
2170
+ }
2171
+
2172
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010500
2173
+ static VALUE
2174
+ rb_s_gpgme_op_spawn_start (VALUE dummy, VALUE vctx, VALUE vfile,
2175
+ VALUE vargv, VALUE vdatain, VALUE vdataout,
2176
+ VALUE vdataerr, VALUE vflags)
2177
+ {
2178
+ gpgme_ctx_t ctx;
2179
+ const char *file;
2180
+ const char **argv;
2181
+ gpgme_data_t datain = NULL;
2182
+ gpgme_data_t dataout = NULL;
2183
+ gpgme_data_t dataerr = NULL;
2184
+ gpgme_error_t err;
2185
+
2186
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
2187
+
2188
+ UNWRAP_GPGME_CTX(vctx, ctx);
2189
+ if (!ctx)
2190
+ rb_raise (rb_eArgError, "released ctx");
2191
+
2192
+ file = StringValueCStr(vfile);
2193
+
2194
+ if (NIL_P(vargv))
2195
+ argv = NULL;
2196
+ else
2197
+ {
2198
+ int i;
2199
+
2200
+ argv = ALLOC_N(const char *, RARRAY_LEN(vargv) + 1);
2201
+ for (i = 0; i < RARRAY_LEN(vargv); i++)
2202
+ argv[i] = StringValueCStr(RARRAY_PTR(vargv)[i]);
2203
+ argv[i] = NULL;
2204
+ }
2205
+
2206
+ UNWRAP_GPGME_DATA(vdatain, datain);
2207
+ UNWRAP_GPGME_DATA(vdataout, dataout);
2208
+ UNWRAP_GPGME_DATA(vdataerr, dataerr);
2209
+
2210
+ err = gpgme_op_spawn_start (ctx, file, argv, datain, dataout, dataerr,
2211
+ NUM2INT(vflags));
2212
+ if (argv)
2213
+ xfree (argv);
2214
+ return LONG2NUM(err);
2215
+ }
2216
+
2217
+ static VALUE
2218
+ rb_s_gpgme_op_spawn (VALUE dummy, VALUE vctx, VALUE vfile,
2219
+ VALUE vargv, VALUE vdatain, VALUE vdataout,
2220
+ VALUE vdataerr, VALUE vflags)
2221
+ {
2222
+ gpgme_ctx_t ctx;
2223
+ const char *file;
2224
+ const char **argv;
2225
+ gpgme_data_t datain = NULL;
2226
+ gpgme_data_t dataout = NULL;
2227
+ gpgme_data_t dataerr = NULL;
2228
+ gpgme_error_t err;
2229
+
2230
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
2231
+
2232
+ UNWRAP_GPGME_CTX(vctx, ctx);
2233
+ if (!ctx)
2234
+ rb_raise (rb_eArgError, "released ctx");
2235
+
2236
+ file = StringValueCStr(vfile);
2237
+
2238
+ if (NIL_P(vargv))
2239
+ argv = NULL;
2240
+ else
2241
+ {
2242
+ int i;
2243
+
2244
+ argv = ALLOC_N(const char *, RARRAY_LEN(vargv) + 1);
2245
+ for (i = 0; i < RARRAY_LEN(vargv); i++)
2246
+ argv[i] = StringValueCStr(RARRAY_PTR(vargv)[i]);
2247
+ argv[i] = NULL;
2248
+ }
2249
+
2250
+ UNWRAP_GPGME_DATA(vdatain, datain);
2251
+ UNWRAP_GPGME_DATA(vdataout, dataout);
2252
+ UNWRAP_GPGME_DATA(vdataerr, dataerr);
2253
+
2254
+ err = gpgme_op_spawn (ctx, file, argv, datain, dataout, dataerr,
2255
+ NUM2INT(vflags));
2256
+ if (argv)
2257
+ xfree (argv);
2258
+ return LONG2NUM(err);
2259
+ }
2260
+ #endif
2261
+
2262
+ void
2263
+ Init_gpgme_n (void)
2264
+ {
2265
+ VALUE mGPGME;
2266
+
2267
+ mGPGME = rb_define_module ("GPGME");
2268
+
2269
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010500
2270
+ rb_define_module_function (mGPGME, "gpgme_get_dirinfo",
2271
+ rb_s_gpgme_get_dirinfo, 1);
2272
+ #endif
2273
+ rb_define_module_function (mGPGME, "gpgme_check_version",
2274
+ rb_s_gpgme_check_version, 1);
2275
+ rb_define_module_function (mGPGME, "gpgme_engine_check_version",
2276
+ rb_s_gpgme_engine_check_version, 1);
2277
+ rb_define_module_function (mGPGME, "gpgme_get_engine_info",
2278
+ rb_s_gpgme_get_engine_info, 1);
2279
+ rb_define_module_function (mGPGME, "gpgme_set_engine_info",
2280
+ rb_s_gpgme_set_engine_info, 3);
2281
+ rb_define_module_function (mGPGME, "gpgme_ctx_get_engine_info",
2282
+ rb_s_gpgme_ctx_get_engine_info, 2);
2283
+ rb_define_module_function (mGPGME, "gpgme_ctx_set_engine_info",
2284
+ rb_s_gpgme_ctx_set_engine_info, 4);
2285
+ rb_define_module_function (mGPGME, "gpgme_pubkey_algo_name",
2286
+ rb_s_gpgme_pubkey_algo_name, 1);
2287
+ rb_define_module_function (mGPGME, "gpgme_hash_algo_name",
2288
+ rb_s_gpgme_hash_algo_name, 1);
2289
+
2290
+ rb_define_module_function (mGPGME, "gpgme_err_code",
2291
+ rb_s_gpgme_err_code, 1);
2292
+ rb_define_module_function (mGPGME, "gpgme_err_source",
2293
+ rb_s_gpgme_err_source, 1);
2294
+ rb_define_module_function (mGPGME, "gpgme_strerror",
2295
+ rb_s_gpgme_strerror, 1);
2296
+
2297
+ cEngineInfo =
2298
+ rb_define_class_under (mGPGME, "EngineInfo", rb_cObject);
2299
+ cCtx =
2300
+ rb_define_class_under (mGPGME, "Ctx", rb_cObject);
2301
+ cData =
2302
+ rb_define_class_under (mGPGME, "Data", rb_cObject);
2303
+ cKey =
2304
+ rb_define_class_under (mGPGME, "Key", rb_cObject);
2305
+ cSubKey =
2306
+ rb_define_class_under (mGPGME, "SubKey", rb_cObject);
2307
+ cUserID =
2308
+ rb_define_class_under (mGPGME, "UserID", rb_cObject);
2309
+ cKeySig =
2310
+ rb_define_class_under (mGPGME, "KeySig", rb_cObject);
2311
+ cRecipient =
2312
+ rb_define_class_under (mGPGME, "Recipient", rb_cObject);
2313
+ cDecryptResult =
2314
+ rb_define_class_under (mGPGME, "DecryptResult", rb_cObject);
2315
+ cVerifyResult =
2316
+ rb_define_class_under (mGPGME, "VerifyResult", rb_cObject);
2317
+ cSignResult =
2318
+ rb_define_class_under (mGPGME, "SignResult", rb_cObject);
2319
+ cEncryptResult =
2320
+ rb_define_class_under (mGPGME, "EncryptResult", rb_cObject);
2321
+ cSignature =
2322
+ rb_define_class_under (mGPGME, "Signature", rb_cObject);
2323
+ cSigNotation =
2324
+ rb_define_class_under (mGPGME, "SigNotation", rb_cObject);
2325
+ cTrustItem =
2326
+ rb_define_class_under (mGPGME, "TrustItem", rb_cObject);
2327
+ cInvalidKey =
2328
+ rb_define_class_under (mGPGME, "InvalidKey", rb_cObject);
2329
+ cNewSignature =
2330
+ rb_define_class_under (mGPGME, "NewSignature", rb_cObject);
2331
+ cImportResult =
2332
+ rb_define_class_under (mGPGME, "ImportResult", rb_cObject);
2333
+ cImportStatus =
2334
+ rb_define_class_under (mGPGME, "ImportStatus", rb_cObject);
2335
+
2336
+ /* Creating Data Buffers
2337
+ *
2338
+ * gpgme_data_new_from_filepart is not currently supported.
2339
+ */
2340
+ rb_define_module_function (mGPGME, "gpgme_data_new",
2341
+ rb_s_gpgme_data_new, 1);
2342
+ rb_define_module_function (mGPGME, "gpgme_data_new_from_mem",
2343
+ rb_s_gpgme_data_new_from_mem, 3);
2344
+ rb_define_module_function (mGPGME, "gpgme_data_new_from_fd",
2345
+ rb_s_gpgme_data_new_from_fd, 2);
2346
+ rb_define_module_function (mGPGME, "gpgme_data_new_from_cbs",
2347
+ rb_s_gpgme_data_new_from_cbs, 3);
2348
+
2349
+ /* Manipulating Data Buffers */
2350
+ rb_define_module_function (mGPGME, "gpgme_data_read",
2351
+ rb_s_gpgme_data_read, 2);
2352
+ rb_define_module_function (mGPGME, "gpgme_data_seek",
2353
+ rb_s_gpgme_data_seek, 3);
2354
+ rb_define_module_function (mGPGME, "gpgme_data_write",
2355
+ rb_s_gpgme_data_write, 3);
2356
+ rb_define_module_function (mGPGME, "gpgme_data_get_encoding",
2357
+ rb_s_gpgme_data_get_encoding, 1);
2358
+ rb_define_module_function (mGPGME, "gpgme_data_set_encoding",
2359
+ rb_s_gpgme_data_set_encoding, 2);
2360
+ rb_define_module_function (mGPGME, "gpgme_data_get_file_name",
2361
+ rb_s_gpgme_data_get_file_name, 1);
2362
+ rb_define_module_function (mGPGME, "gpgme_data_set_file_name",
2363
+ rb_s_gpgme_data_set_file_name, 2);
2364
+
2365
+ /* Creating Contexts */
2366
+ rb_define_module_function (mGPGME, "gpgme_new",
2367
+ rb_s_gpgme_new, 1);
2368
+ rb_define_module_function (mGPGME, "gpgme_release",
2369
+ rb_s_gpgme_release, 1);
2370
+
2371
+ /* Context Attributes */
2372
+ rb_define_module_function (mGPGME, "gpgme_set_protocol",
2373
+ rb_s_gpgme_set_protocol, 2);
2374
+ rb_define_module_function (mGPGME, "gpgme_get_protocol",
2375
+ rb_s_gpgme_get_protocol, 1);
2376
+ rb_define_module_function (mGPGME, "gpgme_set_armor",
2377
+ rb_s_gpgme_set_armor, 2);
2378
+ rb_define_module_function (mGPGME, "gpgme_get_armor",
2379
+ rb_s_gpgme_get_armor, 1);
2380
+ rb_define_module_function (mGPGME, "gpgme_set_textmode",
2381
+ rb_s_gpgme_set_textmode, 2);
2382
+ rb_define_module_function (mGPGME, "gpgme_get_textmode",
2383
+ rb_s_gpgme_get_textmode, 1);
2384
+ rb_define_module_function (mGPGME, "gpgme_set_include_certs",
2385
+ rb_s_gpgme_set_include_certs, 2);
2386
+ rb_define_module_function (mGPGME, "gpgme_get_include_certs",
2387
+ rb_s_gpgme_get_include_certs, 1);
2388
+ rb_define_module_function (mGPGME, "gpgme_set_keylist_mode",
2389
+ rb_s_gpgme_set_keylist_mode, 2);
2390
+ rb_define_module_function (mGPGME, "gpgme_get_keylist_mode",
2391
+ rb_s_gpgme_get_keylist_mode, 1);
2392
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010400
2393
+ rb_define_module_function (mGPGME, "gpgme_set_pinentry_mode",
2394
+ rb_s_gpgme_set_pinentry_mode, 2);
2395
+ rb_define_module_function (mGPGME, "gpgme_get_pinentry_mode",
2396
+ rb_s_gpgme_get_pinentry_mode, 1);
2397
+ #endif
2398
+ rb_define_module_function (mGPGME, "gpgme_set_passphrase_cb",
2399
+ rb_s_gpgme_set_passphrase_cb, 3);
2400
+ rb_define_module_function (mGPGME, "gpgme_get_passphrase_cb",
2401
+ rb_s_gpgme_get_passphrase_cb, 3);
2402
+ rb_define_module_function (mGPGME, "gpgme_set_progress_cb",
2403
+ rb_s_gpgme_set_progress_cb, 3);
2404
+ rb_define_module_function (mGPGME, "gpgme_get_progress_cb",
2405
+ rb_s_gpgme_get_progress_cb, 3);
2406
+ rb_define_module_function (mGPGME, "gpgme_set_locale",
2407
+ rb_s_gpgme_set_locale, 3);
2408
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010600
2409
+ rb_define_module_function (mGPGME, "gpgme_set_offline",
2410
+ rb_s_gpgme_set_offline, 2);
2411
+ rb_define_module_function (mGPGME, "gpgme_get_offline",
2412
+ rb_s_gpgme_get_offline, 1);
2413
+ rb_define_module_function (mGPGME, "gpgme_set_status_cb",
2414
+ rb_s_gpgme_set_status_cb, 3);
2415
+ rb_define_module_function (mGPGME, "gpgme_get_status_cb",
2416
+ rb_s_gpgme_get_status_cb, 3);
2417
+ #endif
2418
+
2419
+ /* Key Management */
2420
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_start",
2421
+ rb_s_gpgme_op_keylist_start, 3);
2422
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_ext_start",
2423
+ rb_s_gpgme_op_keylist_ext_start, 4);
2424
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_next",
2425
+ rb_s_gpgme_op_keylist_next, 2);
2426
+ rb_define_module_function (mGPGME, "gpgme_op_keylist_end",
2427
+ rb_s_gpgme_op_keylist_end, 1);
2428
+ rb_define_module_function (mGPGME, "gpgme_get_key",
2429
+ rb_s_gpgme_get_key, 4);
2430
+ rb_define_module_function (mGPGME, "gpgme_op_genkey",
2431
+ rb_s_gpgme_op_genkey, 4);
2432
+ rb_define_module_function (mGPGME, "gpgme_op_genkey_start",
2433
+ rb_s_gpgme_op_genkey_start, 4);
2434
+ rb_define_module_function (mGPGME, "gpgme_op_export",
2435
+ rb_s_gpgme_op_export, 4);
2436
+ rb_define_module_function (mGPGME, "gpgme_op_export_start",
2437
+ rb_s_gpgme_op_export_start, 4);
2438
+ rb_define_module_function (mGPGME, "gpgme_op_export_ext",
2439
+ rb_s_gpgme_op_export_ext, 4);
2440
+ rb_define_module_function (mGPGME, "gpgme_op_export_ext_start",
2441
+ rb_s_gpgme_op_export_ext_start, 4);
2442
+ #ifdef HAVE_GPGME_OP_EXPORT_KEYS
2443
+ rb_define_module_function (mGPGME, "gpgme_op_export_keys",
2444
+ rb_s_gpgme_op_export_keys, 4);
2445
+ rb_define_module_function (mGPGME, "gpgme_op_export_keys_start",
2446
+ rb_s_gpgme_op_export_keys_start, 4);
2447
+ #endif
2448
+ rb_define_module_function (mGPGME, "gpgme_op_import",
2449
+ rb_s_gpgme_op_import, 2);
2450
+ rb_define_module_function (mGPGME, "gpgme_op_import_start",
2451
+ rb_s_gpgme_op_import_start, 2);
2452
+ #ifdef HAVE_GPGME_OP_EXPORT_KEYS
2453
+ rb_define_module_function (mGPGME, "gpgme_op_import_keys",
2454
+ rb_s_gpgme_op_import_keys, 2);
2455
+ rb_define_module_function (mGPGME, "gpgme_op_import_keys_start",
2456
+ rb_s_gpgme_op_import_keys_start, 2);
2457
+ #endif
2458
+ rb_define_module_function (mGPGME, "gpgme_op_import_result",
2459
+ rb_s_gpgme_op_import_result, 1);
2460
+ rb_define_module_function (mGPGME, "gpgme_op_delete",
2461
+ rb_s_gpgme_op_delete, 3);
2462
+ rb_define_module_function (mGPGME, "gpgme_op_delete_start",
2463
+ rb_s_gpgme_op_delete_start, 3);
2464
+ rb_define_module_function (mGPGME, "gpgme_op_edit",
2465
+ rb_s_gpgme_op_edit, 5);
2466
+ rb_define_module_function (mGPGME, "gpgme_op_edit_start",
2467
+ rb_s_gpgme_op_edit_start, 5);
2468
+ rb_define_module_function (mGPGME, "gpgme_op_card_edit",
2469
+ rb_s_gpgme_op_card_edit, 5);
2470
+ rb_define_module_function (mGPGME, "gpgme_op_card_edit_start",
2471
+ rb_s_gpgme_op_card_edit_start, 5);
2472
+
2473
+ /* Trust Item Management */
2474
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_start",
2475
+ rb_s_gpgme_op_trustlist_start, 3);
2476
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_next",
2477
+ rb_s_gpgme_op_trustlist_next, 2);
2478
+ rb_define_module_function (mGPGME, "gpgme_op_trustlist_end",
2479
+ rb_s_gpgme_op_trustlist_end, 1);
2480
+
2481
+ /* Decrypt */
2482
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt",
2483
+ rb_s_gpgme_op_decrypt, 3);
2484
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_start",
2485
+ rb_s_gpgme_op_decrypt_start, 3);
2486
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_result",
2487
+ rb_s_gpgme_op_decrypt_result, 1);
2488
+
2489
+ /* Verify */
2490
+ rb_define_module_function (mGPGME, "gpgme_op_verify",
2491
+ rb_s_gpgme_op_verify, 4);
2492
+ rb_define_module_function (mGPGME, "gpgme_op_verify_start",
2493
+ rb_s_gpgme_op_verify_start, 4);
2494
+ rb_define_module_function (mGPGME, "gpgme_op_verify_result",
2495
+ rb_s_gpgme_op_verify_result, 1);
2496
+
2497
+ /* Decrypt and Verify */
2498
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_verify",
2499
+ rb_s_gpgme_op_decrypt_verify, 3);
2500
+ rb_define_module_function (mGPGME, "gpgme_op_decrypt_verify_start",
2501
+ rb_s_gpgme_op_decrypt_verify_start, 3);
2502
+
2503
+ /* Sign */
2504
+ rb_define_module_function (mGPGME, "gpgme_signers_clear",
2505
+ rb_s_gpgme_signers_clear, 1);
2506
+ rb_define_module_function (mGPGME, "gpgme_signers_add",
2507
+ rb_s_gpgme_signers_add, 2);
2508
+ rb_define_module_function (mGPGME, "gpgme_signers_enum",
2509
+ rb_s_gpgme_signers_enum, 2);
2510
+ rb_define_module_function (mGPGME, "gpgme_op_sign",
2511
+ rb_s_gpgme_op_sign, 4);
2512
+ rb_define_module_function (mGPGME, "gpgme_op_sign_start",
2513
+ rb_s_gpgme_op_sign_start, 4);
2514
+ rb_define_module_function (mGPGME, "gpgme_op_sign_result",
2515
+ rb_s_gpgme_op_sign_result, 1);
2516
+
2517
+ /* Encrypt */
2518
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt",
2519
+ rb_s_gpgme_op_encrypt, 5);
2520
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_start",
2521
+ rb_s_gpgme_op_encrypt_start, 5);
2522
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_result",
2523
+ rb_s_gpgme_op_encrypt_result, 1);
2524
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_sign",
2525
+ rb_s_gpgme_op_encrypt_sign, 5);
2526
+ rb_define_module_function (mGPGME, "gpgme_op_encrypt_sign_start",
2527
+ rb_s_gpgme_op_encrypt_sign_start, 5);
2528
+
2529
+ /* Run Control */
2530
+ rb_define_module_function (mGPGME, "gpgme_wait",
2531
+ rb_s_gpgme_wait, 3);
2532
+
2533
+ /* Running other Programs */
2534
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010500
2535
+ rb_define_module_function (mGPGME, "gpgme_op_spawn",
2536
+ rb_s_gpgme_op_spawn, 7);
2537
+ rb_define_module_function (mGPGME, "gpgme_op_spawn_start",
2538
+ rb_s_gpgme_op_spawn_start, 7);
2539
+ #endif
2540
+
2541
+ /* gpgme_pubkey_algo_t */
2542
+ rb_define_const (mGPGME, "GPGME_PK_RSA", INT2FIX(GPGME_PK_RSA));
2543
+ rb_define_const (mGPGME, "GPGME_PK_DSA", INT2FIX(GPGME_PK_DSA));
2544
+ rb_define_const (mGPGME, "GPGME_PK_ELG", INT2FIX(GPGME_PK_ELG));
2545
+ rb_define_const (mGPGME, "GPGME_PK_ELG_E", INT2FIX(GPGME_PK_ELG_E));
2546
+ /* This algorithm was added in 1.5.0. */
2547
+ #ifdef GPGME_PK_ECC
2548
+ rb_define_const (mGPGME, "GPGME_PK_ECC", INT2FIX(GPGME_PK_ECC));
2549
+ #endif
2550
+
2551
+ /* gpgme_hash_algo_t */
2552
+ rb_define_const (mGPGME, "GPGME_MD_MD5", INT2FIX(GPGME_MD_MD5));
2553
+ rb_define_const (mGPGME, "GPGME_MD_SHA1", INT2FIX(GPGME_MD_SHA1));
2554
+ rb_define_const (mGPGME, "GPGME_MD_RMD160", INT2FIX(GPGME_MD_RMD160));
2555
+ rb_define_const (mGPGME, "GPGME_MD_MD2", INT2FIX(GPGME_MD_MD2));
2556
+ rb_define_const (mGPGME, "GPGME_MD_TIGER", INT2FIX(GPGME_MD_TIGER));
2557
+ rb_define_const (mGPGME, "GPGME_MD_HAVAL", INT2FIX(GPGME_MD_HAVAL));
2558
+ /* This algorithm was added in 1.5.0. */
2559
+ #ifdef GPGME_MD_SHA224
2560
+ rb_define_const (mGPGME, "GPGME_MD_SHA224", INT2FIX(GPGME_MD_SHA224));
2561
+ #endif
2562
+ rb_define_const (mGPGME, "GPGME_MD_SHA256", INT2FIX(GPGME_MD_SHA256));
2563
+ rb_define_const (mGPGME, "GPGME_MD_SHA384", INT2FIX(GPGME_MD_SHA384));
2564
+ rb_define_const (mGPGME, "GPGME_MD_SHA512", INT2FIX(GPGME_MD_SHA512));
2565
+ rb_define_const (mGPGME, "GPGME_MD_MD4", INT2FIX(GPGME_MD_MD4));
2566
+ rb_define_const (mGPGME, "GPGME_MD_CRC32", INT2FIX(GPGME_MD_CRC32));
2567
+ rb_define_const (mGPGME, "GPGME_MD_CRC32_RFC1510",
2568
+ INT2FIX(GPGME_MD_CRC32_RFC1510));
2569
+ rb_define_const (mGPGME, "GPGME_MD_CRC24_RFC2440",
2570
+ INT2FIX(GPGME_MD_CRC24_RFC2440));
2571
+
2572
+ /* gpgme_err_code_t */
2573
+ rb_define_const (mGPGME, "GPG_ERR_EOF",
2574
+ INT2FIX(GPG_ERR_EOF));
2575
+ rb_define_const (mGPGME, "GPG_ERR_NO_ERROR",
2576
+ INT2FIX(GPG_ERR_NO_ERROR));
2577
+ rb_define_const (mGPGME, "GPG_ERR_GENERAL",
2578
+ INT2FIX(GPG_ERR_GENERAL));
2579
+ rb_define_const (mGPGME, "GPG_ERR_ENOMEM",
2580
+ INT2FIX(GPG_ERR_ENOMEM));
2581
+ rb_define_const (mGPGME, "GPG_ERR_INV_VALUE",
2582
+ INT2FIX(GPG_ERR_INV_VALUE));
2583
+ rb_define_const (mGPGME, "GPG_ERR_UNUSABLE_PUBKEY",
2584
+ INT2FIX(GPG_ERR_UNUSABLE_PUBKEY));
2585
+ rb_define_const (mGPGME, "GPG_ERR_UNUSABLE_SECKEY",
2586
+ INT2FIX(GPG_ERR_UNUSABLE_SECKEY));
2587
+ rb_define_const (mGPGME, "GPG_ERR_NO_DATA",
2588
+ INT2FIX(GPG_ERR_NO_DATA));
2589
+ rb_define_const (mGPGME, "GPG_ERR_CONFLICT",
2590
+ INT2FIX(GPG_ERR_CONFLICT));
2591
+ rb_define_const (mGPGME, "GPG_ERR_NOT_IMPLEMENTED",
2592
+ INT2FIX(GPG_ERR_NOT_IMPLEMENTED));
2593
+ rb_define_const (mGPGME, "GPG_ERR_DECRYPT_FAILED",
2594
+ INT2FIX(GPG_ERR_DECRYPT_FAILED));
2595
+ rb_define_const (mGPGME, "GPG_ERR_BAD_PASSPHRASE",
2596
+ INT2FIX(GPG_ERR_BAD_PASSPHRASE));
2597
+ rb_define_const (mGPGME, "GPG_ERR_KEY_EXPIRED",
2598
+ INT2FIX(GPG_ERR_KEY_EXPIRED));
2599
+ rb_define_const (mGPGME, "GPG_ERR_SIG_EXPIRED",
2600
+ INT2FIX(GPG_ERR_SIG_EXPIRED));
2601
+ rb_define_const (mGPGME, "GPG_ERR_CANCELED",
2602
+ INT2FIX(GPG_ERR_CANCELED));
2603
+ rb_define_const (mGPGME, "GPG_ERR_INV_ENGINE",
2604
+ INT2FIX(GPG_ERR_INV_ENGINE));
2605
+ rb_define_const (mGPGME, "GPG_ERR_AMBIGUOUS_NAME",
2606
+ INT2FIX(GPG_ERR_AMBIGUOUS_NAME));
2607
+ rb_define_const (mGPGME, "GPG_ERR_WRONG_KEY_USAGE",
2608
+ INT2FIX(GPG_ERR_WRONG_KEY_USAGE));
2609
+ rb_define_const (mGPGME, "GPG_ERR_CERT_REVOKED",
2610
+ INT2FIX(GPG_ERR_CERT_REVOKED));
2611
+ rb_define_const (mGPGME, "GPG_ERR_CERT_EXPIRED",
2612
+ INT2FIX(GPG_ERR_CERT_EXPIRED));
2613
+ rb_define_const (mGPGME, "GPG_ERR_NO_CRL_KNOWN",
2614
+ INT2FIX(GPG_ERR_NO_CRL_KNOWN));
2615
+ rb_define_const (mGPGME, "GPG_ERR_NO_POLICY_MATCH",
2616
+ INT2FIX(GPG_ERR_NO_POLICY_MATCH));
2617
+ rb_define_const (mGPGME, "GPG_ERR_NO_SECKEY",
2618
+ INT2FIX(GPG_ERR_NO_SECKEY));
2619
+ rb_define_const (mGPGME, "GPG_ERR_MISSING_CERT",
2620
+ INT2FIX(GPG_ERR_MISSING_CERT));
2621
+ rb_define_const (mGPGME, "GPG_ERR_BAD_CERT_CHAIN",
2622
+ INT2FIX(GPG_ERR_BAD_CERT_CHAIN));
2623
+ rb_define_const (mGPGME, "GPG_ERR_UNSUPPORTED_ALGORITHM",
2624
+ INT2FIX(GPG_ERR_UNSUPPORTED_ALGORITHM));
2625
+ rb_define_const (mGPGME, "GPG_ERR_BAD_SIGNATURE",
2626
+ INT2FIX(GPG_ERR_BAD_SIGNATURE));
2627
+ rb_define_const (mGPGME, "GPG_ERR_NO_PUBKEY",
2628
+ INT2FIX(GPG_ERR_NO_PUBKEY));
2629
+
2630
+ /* gpgme_err_source_t */
2631
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_UNKNOWN",
2632
+ INT2FIX(GPG_ERR_SOURCE_UNKNOWN));
2633
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGME",
2634
+ INT2FIX(GPG_ERR_SOURCE_GPGME));
2635
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPG",
2636
+ INT2FIX(GPG_ERR_SOURCE_GPG));
2637
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGSM",
2638
+ INT2FIX(GPG_ERR_SOURCE_GPGSM));
2639
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GCRYPT",
2640
+ INT2FIX(GPG_ERR_SOURCE_GCRYPT));
2641
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_GPGAGENT",
2642
+ INT2FIX(GPG_ERR_SOURCE_GPGAGENT));
2643
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_PINENTRY",
2644
+ INT2FIX(GPG_ERR_SOURCE_PINENTRY));
2645
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_SCD",
2646
+ INT2FIX(GPG_ERR_SOURCE_SCD));
2647
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_KEYBOX",
2648
+ INT2FIX(GPG_ERR_SOURCE_KEYBOX));
2649
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_1",
2650
+ INT2FIX(GPG_ERR_SOURCE_USER_1));
2651
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_2",
2652
+ INT2FIX(GPG_ERR_SOURCE_USER_2));
2653
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_3",
2654
+ INT2FIX(GPG_ERR_SOURCE_USER_3));
2655
+ rb_define_const (mGPGME, "GPG_ERR_SOURCE_USER_4",
2656
+ INT2FIX(GPG_ERR_SOURCE_USER_4));
2657
+
2658
+ /* gpgme_data_encoding_t */
2659
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_NONE",
2660
+ INT2FIX(GPGME_DATA_ENCODING_NONE));
2661
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_BINARY",
2662
+ INT2FIX(GPGME_DATA_ENCODING_BINARY));
2663
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_BASE64",
2664
+ INT2FIX(GPGME_DATA_ENCODING_BASE64));
2665
+ rb_define_const (mGPGME, "GPGME_DATA_ENCODING_ARMOR",
2666
+ INT2FIX(GPGME_DATA_ENCODING_ARMOR));
2667
+
2668
+ /* gpgme_sig_stat_t */
2669
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NONE",
2670
+ INT2FIX(GPGME_SIG_STAT_NONE));
2671
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD",
2672
+ INT2FIX(GPGME_SIG_STAT_GOOD));
2673
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_BAD",
2674
+ INT2FIX(GPGME_SIG_STAT_BAD));
2675
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NOKEY",
2676
+ INT2FIX(GPGME_SIG_STAT_NOKEY));
2677
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_NOSIG",
2678
+ INT2FIX(GPGME_SIG_STAT_NOSIG));
2679
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_ERROR",
2680
+ INT2FIX(GPGME_SIG_STAT_ERROR));
2681
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_DIFF",
2682
+ INT2FIX(GPGME_SIG_STAT_DIFF));
2683
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD_EXP",
2684
+ INT2FIX(GPGME_SIG_STAT_GOOD_EXP));
2685
+ rb_define_const (mGPGME, "GPGME_SIG_STAT_GOOD_EXPKEY",
2686
+ INT2FIX(GPGME_SIG_STAT_GOOD_EXPKEY));
2687
+
2688
+ /* gpgme_sigsum_t */
2689
+ rb_define_const (mGPGME, "GPGME_SIGSUM_VALID",
2690
+ INT2FIX(GPGME_SIGSUM_VALID));
2691
+ rb_define_const (mGPGME, "GPGME_SIGSUM_GREEN",
2692
+ INT2FIX(GPGME_SIGSUM_GREEN));
2693
+ rb_define_const (mGPGME, "GPGME_SIGSUM_RED",
2694
+ INT2FIX(GPGME_SIGSUM_RED));
2695
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_REVOKED",
2696
+ INT2FIX(GPGME_SIGSUM_KEY_REVOKED));
2697
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_EXPIRED",
2698
+ INT2FIX(GPGME_SIGSUM_KEY_EXPIRED));
2699
+ rb_define_const (mGPGME, "GPGME_SIGSUM_SIG_EXPIRED",
2700
+ INT2FIX(GPGME_SIGSUM_SIG_EXPIRED));
2701
+ rb_define_const (mGPGME, "GPGME_SIGSUM_KEY_MISSING",
2702
+ INT2FIX(GPGME_SIGSUM_KEY_MISSING));
2703
+ rb_define_const (mGPGME, "GPGME_SIGSUM_CRL_MISSING",
2704
+ INT2FIX(GPGME_SIGSUM_CRL_MISSING));
2705
+ rb_define_const (mGPGME, "GPGME_SIGSUM_CRL_TOO_OLD",
2706
+ INT2FIX(GPGME_SIGSUM_CRL_TOO_OLD));
2707
+ rb_define_const (mGPGME, "GPGME_SIGSUM_BAD_POLICY",
2708
+ INT2FIX(GPGME_SIGSUM_BAD_POLICY));
2709
+ rb_define_const (mGPGME, "GPGME_SIGSUM_SYS_ERROR",
2710
+ INT2FIX(GPGME_SIGSUM_SYS_ERROR));
2711
+
2712
+ /* gpgme_sig_mode_t */
2713
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_NORMAL",
2714
+ INT2FIX(GPGME_SIG_MODE_NORMAL));
2715
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_DETACH",
2716
+ INT2FIX(GPGME_SIG_MODE_DETACH));
2717
+ rb_define_const (mGPGME, "GPGME_SIG_MODE_CLEAR",
2718
+ INT2FIX(GPGME_SIG_MODE_CLEAR));
2719
+
2720
+ /* gpgme_attr_t */
2721
+ rb_define_const (mGPGME, "GPGME_ATTR_KEYID",
2722
+ INT2FIX(GPGME_ATTR_KEYID));
2723
+ rb_define_const (mGPGME, "GPGME_ATTR_FPR",
2724
+ INT2FIX(GPGME_ATTR_FPR));
2725
+ rb_define_const (mGPGME, "GPGME_ATTR_ALGO",
2726
+ INT2FIX(GPGME_ATTR_ALGO));
2727
+ rb_define_const (mGPGME, "GPGME_ATTR_LEN",
2728
+ INT2FIX(GPGME_ATTR_LEN));
2729
+ rb_define_const (mGPGME, "GPGME_ATTR_CREATED",
2730
+ INT2FIX(GPGME_ATTR_CREATED));
2731
+ rb_define_const (mGPGME, "GPGME_ATTR_EXPIRE",
2732
+ INT2FIX(GPGME_ATTR_EXPIRE));
2733
+ rb_define_const (mGPGME, "GPGME_ATTR_OTRUST",
2734
+ INT2FIX(GPGME_ATTR_OTRUST));
2735
+ rb_define_const (mGPGME, "GPGME_ATTR_USERID",
2736
+ INT2FIX(GPGME_ATTR_USERID));
2737
+ rb_define_const (mGPGME, "GPGME_ATTR_NAME",
2738
+ INT2FIX(GPGME_ATTR_NAME));
2739
+ rb_define_const (mGPGME, "GPGME_ATTR_EMAIL",
2740
+ INT2FIX(GPGME_ATTR_EMAIL));
2741
+ rb_define_const (mGPGME, "GPGME_ATTR_COMMENT",
2742
+ INT2FIX(GPGME_ATTR_COMMENT));
2743
+ rb_define_const (mGPGME, "GPGME_ATTR_VALIDITY",
2744
+ INT2FIX(GPGME_ATTR_VALIDITY));
2745
+ rb_define_const (mGPGME, "GPGME_ATTR_LEVEL",
2746
+ INT2FIX(GPGME_ATTR_LEVEL));
2747
+ rb_define_const (mGPGME, "GPGME_ATTR_TYPE",
2748
+ INT2FIX(GPGME_ATTR_TYPE));
2749
+ rb_define_const (mGPGME, "GPGME_ATTR_IS_SECRET",
2750
+ INT2FIX(GPGME_ATTR_IS_SECRET));
2751
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_REVOKED",
2752
+ INT2FIX(GPGME_ATTR_KEY_REVOKED));
2753
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_INVALID",
2754
+ INT2FIX(GPGME_ATTR_KEY_INVALID));
2755
+ rb_define_const (mGPGME, "GPGME_ATTR_UID_REVOKED",
2756
+ INT2FIX(GPGME_ATTR_UID_REVOKED));
2757
+ rb_define_const (mGPGME, "GPGME_ATTR_UID_INVALID",
2758
+ INT2FIX(GPGME_ATTR_UID_INVALID));
2759
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_CAPS",
2760
+ INT2FIX(GPGME_ATTR_KEY_CAPS));
2761
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_ENCRYPT",
2762
+ INT2FIX(GPGME_ATTR_CAN_ENCRYPT));
2763
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_SIGN",
2764
+ INT2FIX(GPGME_ATTR_CAN_SIGN));
2765
+ rb_define_const (mGPGME, "GPGME_ATTR_CAN_CERTIFY",
2766
+ INT2FIX(GPGME_ATTR_CAN_CERTIFY));
2767
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_EXPIRED",
2768
+ INT2FIX(GPGME_ATTR_KEY_EXPIRED));
2769
+ rb_define_const (mGPGME, "GPGME_ATTR_KEY_DISABLED",
2770
+ INT2FIX(GPGME_ATTR_KEY_DISABLED));
2771
+ rb_define_const (mGPGME, "GPGME_ATTR_SERIAL",
2772
+ INT2FIX(GPGME_ATTR_SERIAL));
2773
+ rb_define_const (mGPGME, "GPGME_ATTR_ISSUER",
2774
+ INT2FIX(GPGME_ATTR_ISSUER));
2775
+ rb_define_const (mGPGME, "GPGME_ATTR_CHAINID",
2776
+ INT2FIX(GPGME_ATTR_CHAINID));
2777
+ rb_define_const (mGPGME, "GPGME_ATTR_SIG_STATUS",
2778
+ INT2FIX(GPGME_ATTR_SIG_STATUS));
2779
+ rb_define_const (mGPGME, "GPGME_ATTR_ERRTOK",
2780
+ INT2FIX(GPGME_ATTR_ERRTOK));
2781
+ rb_define_const (mGPGME, "GPGME_ATTR_SIG_SUMMARY",
2782
+ INT2FIX(GPGME_ATTR_SIG_SUMMARY));
2783
+
2784
+ /* gpgme_validity_t */
2785
+ rb_define_const (mGPGME, "GPGME_VALIDITY_UNKNOWN",
2786
+ INT2FIX(GPGME_VALIDITY_UNKNOWN));
2787
+ rb_define_const (mGPGME, "GPGME_VALIDITY_UNDEFINED",
2788
+ INT2FIX(GPGME_VALIDITY_UNDEFINED));
2789
+ rb_define_const (mGPGME, "GPGME_VALIDITY_NEVER",
2790
+ INT2FIX(GPGME_VALIDITY_NEVER));
2791
+ rb_define_const (mGPGME, "GPGME_VALIDITY_MARGINAL",
2792
+ INT2FIX(GPGME_VALIDITY_MARGINAL));
2793
+ rb_define_const (mGPGME, "GPGME_VALIDITY_FULL",
2794
+ INT2FIX(GPGME_VALIDITY_FULL));
2795
+ rb_define_const (mGPGME, "GPGME_VALIDITY_ULTIMATE",
2796
+ INT2FIX(GPGME_VALIDITY_ULTIMATE));
2797
+
2798
+ /* gpgme_protocol_t */
2799
+ rb_define_const (mGPGME, "GPGME_PROTOCOL_OpenPGP",
2800
+ INT2FIX(GPGME_PROTOCOL_OpenPGP));
2801
+ rb_define_const (mGPGME, "GPGME_PROTOCOL_CMS",
2802
+ INT2FIX(GPGME_PROTOCOL_CMS));
2803
+ /* This protocol was added in 1.2.0. */
2804
+ #ifdef GPGME_PROTOCOL_ASSUAN
2805
+ rb_define_const (mGPGME, "GPGME_PROTOCOL_ASSUAN",
2806
+ INT2FIX(GPGME_PROTOCOL_ASSUAN))
2807
+ #endif
2808
+ /* This protocol was added in 1.5.0. */
2809
+ #ifdef GPGME_PROTOCOL_SPAWN
2810
+ rb_define_const (mGPGME, "GPGME_PROTOCOL_SPAWN",
2811
+ INT2FIX(GPGME_PROTOCOL_SPAWN));
2812
+ #endif
2813
+
2814
+ /* gpgme_status_code_t */
2815
+ rb_define_const (mGPGME, "GPGME_STATUS_EOF",
2816
+ INT2FIX(GPGME_STATUS_EOF));
2817
+ /* mkstatus starts here */
2818
+ rb_define_const (mGPGME, "GPGME_STATUS_ENTER",
2819
+ INT2FIX(GPGME_STATUS_ENTER));
2820
+ rb_define_const (mGPGME, "GPGME_STATUS_LEAVE",
2821
+ INT2FIX(GPGME_STATUS_LEAVE));
2822
+ rb_define_const (mGPGME, "GPGME_STATUS_ABORT",
2823
+ INT2FIX(GPGME_STATUS_ABORT));
2824
+
2825
+ rb_define_const (mGPGME, "GPGME_STATUS_GOODSIG",
2826
+ INT2FIX(GPGME_STATUS_GOODSIG));
2827
+ rb_define_const (mGPGME, "GPGME_STATUS_BADSIG",
2828
+ INT2FIX(GPGME_STATUS_BADSIG));
2829
+ rb_define_const (mGPGME, "GPGME_STATUS_ERRSIG",
2830
+ INT2FIX(GPGME_STATUS_ERRSIG));
2831
+
2832
+ rb_define_const (mGPGME, "GPGME_STATUS_BADARMOR",
2833
+ INT2FIX(GPGME_STATUS_BADARMOR));
2834
+
2835
+ rb_define_const (mGPGME, "GPGME_STATUS_RSA_OR_IDEA",
2836
+ INT2FIX(GPGME_STATUS_RSA_OR_IDEA));
2837
+ rb_define_const (mGPGME, "GPGME_STATUS_KEYEXPIRED",
2838
+ INT2FIX(GPGME_STATUS_KEYEXPIRED));
2839
+ rb_define_const (mGPGME, "GPGME_STATUS_KEYREVOKED",
2840
+ INT2FIX(GPGME_STATUS_KEYREVOKED));
2841
+
2842
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_UNDEFINED",
2843
+ INT2FIX(GPGME_STATUS_TRUST_UNDEFINED));
2844
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_NEVER",
2845
+ INT2FIX(GPGME_STATUS_TRUST_NEVER));
2846
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_MARGINAL",
2847
+ INT2FIX(GPGME_STATUS_TRUST_MARGINAL));
2848
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_FULLY",
2849
+ INT2FIX(GPGME_STATUS_TRUST_FULLY));
2850
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUST_ULTIMATE",
2851
+ INT2FIX(GPGME_STATUS_TRUST_ULTIMATE));
2852
+
2853
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_INFO",
2854
+ INT2FIX(GPGME_STATUS_SHM_INFO));
2855
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET",
2856
+ INT2FIX(GPGME_STATUS_SHM_GET));
2857
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET_BOOL",
2858
+ INT2FIX(GPGME_STATUS_SHM_GET_BOOL));
2859
+ rb_define_const (mGPGME, "GPGME_STATUS_SHM_GET_HIDDEN",
2860
+ INT2FIX(GPGME_STATUS_SHM_GET_HIDDEN));
2861
+
2862
+ rb_define_const (mGPGME, "GPGME_STATUS_NEED_PASSPHRASE",
2863
+ INT2FIX(GPGME_STATUS_NEED_PASSPHRASE));
2864
+ rb_define_const (mGPGME, "GPGME_STATUS_VALIDSIG",
2865
+ INT2FIX(GPGME_STATUS_VALIDSIG));
2866
+ rb_define_const (mGPGME, "GPGME_STATUS_SIG_ID",
2867
+ INT2FIX(GPGME_STATUS_SIG_ID));
2868
+ rb_define_const (mGPGME, "GPGME_STATUS_ENC_TO",
2869
+ INT2FIX(GPGME_STATUS_ENC_TO));
2870
+ rb_define_const (mGPGME, "GPGME_STATUS_NODATA",
2871
+ INT2FIX(GPGME_STATUS_NODATA));
2872
+ rb_define_const (mGPGME, "GPGME_STATUS_BAD_PASSPHRASE",
2873
+ INT2FIX(GPGME_STATUS_BAD_PASSPHRASE));
2874
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_PUBKEY",
2875
+ INT2FIX(GPGME_STATUS_NO_PUBKEY));
2876
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_SECKEY",
2877
+ INT2FIX(GPGME_STATUS_NO_SECKEY));
2878
+ rb_define_const (mGPGME, "GPGME_STATUS_NEED_PASSPHRASE_SYM",
2879
+ INT2FIX(GPGME_STATUS_NEED_PASSPHRASE_SYM));
2880
+ rb_define_const (mGPGME, "GPGME_STATUS_DECRYPTION_FAILED",
2881
+ INT2FIX(GPGME_STATUS_DECRYPTION_FAILED));
2882
+ rb_define_const (mGPGME, "GPGME_STATUS_DECRYPTION_OKAY",
2883
+ INT2FIX(GPGME_STATUS_DECRYPTION_OKAY));
2884
+ rb_define_const (mGPGME, "GPGME_STATUS_MISSING_PASSPHRASE",
2885
+ INT2FIX(GPGME_STATUS_MISSING_PASSPHRASE));
2886
+ rb_define_const (mGPGME, "GPGME_STATUS_GOOD_PASSPHRASE",
2887
+ INT2FIX(GPGME_STATUS_GOOD_PASSPHRASE));
2888
+ rb_define_const (mGPGME, "GPGME_STATUS_GOODMDC",
2889
+ INT2FIX(GPGME_STATUS_GOODMDC));
2890
+ rb_define_const (mGPGME, "GPGME_STATUS_BADMDC",
2891
+ INT2FIX(GPGME_STATUS_BADMDC));
2892
+ rb_define_const (mGPGME, "GPGME_STATUS_ERRMDC",
2893
+ INT2FIX(GPGME_STATUS_ERRMDC));
2894
+ rb_define_const (mGPGME, "GPGME_STATUS_IMPORTED",
2895
+ INT2FIX(GPGME_STATUS_IMPORTED));
2896
+ rb_define_const (mGPGME, "GPGME_STATUS_IMPORT_RES",
2897
+ INT2FIX(GPGME_STATUS_IMPORT_RES));
2898
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_START",
2899
+ INT2FIX(GPGME_STATUS_FILE_START));
2900
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_DONE",
2901
+ INT2FIX(GPGME_STATUS_FILE_DONE));
2902
+ rb_define_const (mGPGME, "GPGME_STATUS_FILE_ERROR",
2903
+ INT2FIX(GPGME_STATUS_FILE_ERROR));
2904
+
2905
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_DECRYPTION",
2906
+ INT2FIX(GPGME_STATUS_BEGIN_DECRYPTION));
2907
+ rb_define_const (mGPGME, "GPGME_STATUS_END_DECRYPTION",
2908
+ INT2FIX(GPGME_STATUS_END_DECRYPTION));
2909
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_ENCRYPTION",
2910
+ INT2FIX(GPGME_STATUS_BEGIN_ENCRYPTION));
2911
+ rb_define_const (mGPGME, "GPGME_STATUS_END_ENCRYPTION",
2912
+ INT2FIX(GPGME_STATUS_END_ENCRYPTION));
2913
+
2914
+ rb_define_const (mGPGME, "GPGME_STATUS_DELETE_PROBLEM",
2915
+ INT2FIX(GPGME_STATUS_DELETE_PROBLEM));
2916
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_BOOL",
2917
+ INT2FIX(GPGME_STATUS_GET_BOOL));
2918
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_LINE",
2919
+ INT2FIX(GPGME_STATUS_GET_LINE));
2920
+ rb_define_const (mGPGME, "GPGME_STATUS_GET_HIDDEN",
2921
+ INT2FIX(GPGME_STATUS_GET_HIDDEN));
2922
+ rb_define_const (mGPGME, "GPGME_STATUS_GOT_IT",
2923
+ INT2FIX(GPGME_STATUS_GOT_IT));
2924
+ rb_define_const (mGPGME, "GPGME_STATUS_PROGRESS",
2925
+ INT2FIX(GPGME_STATUS_PROGRESS));
2926
+ rb_define_const (mGPGME, "GPGME_STATUS_SIG_CREATED",
2927
+ INT2FIX(GPGME_STATUS_SIG_CREATED));
2928
+ rb_define_const (mGPGME, "GPGME_STATUS_SESSION_KEY",
2929
+ INT2FIX(GPGME_STATUS_SESSION_KEY));
2930
+ rb_define_const (mGPGME, "GPGME_STATUS_NOTATION_NAME",
2931
+ INT2FIX(GPGME_STATUS_NOTATION_NAME));
2932
+ rb_define_const (mGPGME, "GPGME_STATUS_NOTATION_DATA",
2933
+ INT2FIX(GPGME_STATUS_NOTATION_DATA));
2934
+ rb_define_const (mGPGME, "GPGME_STATUS_POLICY_URL",
2935
+ INT2FIX(GPGME_STATUS_POLICY_URL));
2936
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_STREAM",
2937
+ INT2FIX(GPGME_STATUS_BEGIN_STREAM));
2938
+ rb_define_const (mGPGME, "GPGME_STATUS_END_STREAM",
2939
+ INT2FIX(GPGME_STATUS_END_STREAM));
2940
+ rb_define_const (mGPGME, "GPGME_STATUS_KEY_CREATED",
2941
+ INT2FIX(GPGME_STATUS_KEY_CREATED));
2942
+ rb_define_const (mGPGME, "GPGME_STATUS_USERID_HINT",
2943
+ INT2FIX(GPGME_STATUS_USERID_HINT));
2944
+ rb_define_const (mGPGME, "GPGME_STATUS_UNEXPECTED",
2945
+ INT2FIX(GPGME_STATUS_UNEXPECTED));
2946
+ rb_define_const (mGPGME, "GPGME_STATUS_INV_RECP",
2947
+ INT2FIX(GPGME_STATUS_INV_RECP));
2948
+ rb_define_const (mGPGME, "GPGME_STATUS_NO_RECP",
2949
+ INT2FIX(GPGME_STATUS_NO_RECP));
2950
+ rb_define_const (mGPGME, "GPGME_STATUS_ALREADY_SIGNED",
2951
+ INT2FIX(GPGME_STATUS_ALREADY_SIGNED));
2952
+ rb_define_const (mGPGME, "GPGME_STATUS_SIGEXPIRED",
2953
+ INT2FIX(GPGME_STATUS_SIGEXPIRED));
2954
+ rb_define_const (mGPGME, "GPGME_STATUS_EXPSIG",
2955
+ INT2FIX(GPGME_STATUS_EXPSIG));
2956
+ rb_define_const (mGPGME, "GPGME_STATUS_EXPKEYSIG",
2957
+ INT2FIX(GPGME_STATUS_EXPKEYSIG));
2958
+ rb_define_const (mGPGME, "GPGME_STATUS_TRUNCATED",
2959
+ INT2FIX(GPGME_STATUS_TRUNCATED));
2960
+ rb_define_const (mGPGME, "GPGME_STATUS_ERROR",
2961
+ INT2FIX(GPGME_STATUS_ERROR));
2962
+ /* These status codes have been available since 1.1.1. */
2963
+ #ifdef GPGME_STATUS_PKA_TRUST_BAD
2964
+ rb_define_const (mGPGME, "GPGME_STATUS_PKA_TRUST_BAD",
2965
+ INT2FIX(GPGME_STATUS_PKA_TRUST_BAD));
2966
+ rb_define_const (mGPGME, "GPGME_STATUS_PKA_TRUST_GOOD",
2967
+ INT2FIX(GPGME_STATUS_PKA_TRUST_GOOD));
2968
+ #endif
2969
+ /* These status codes were added in 1.5.0. */
2970
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010500
2971
+ rb_define_const (mGPGME, "GPGME_STATUS_PLAINTEXT_LENGTH",
2972
+ INT2FIX(GPGME_STATUS_PLAINTEXT_LENGTH));
2973
+ rb_define_const (mGPGME, "GPGME_STATUS_MOUNTPOINT",
2974
+ INT2FIX(GPGME_STATUS_MOUNTPOINT));
2975
+ rb_define_const (mGPGME, "GPGME_STATUS_PINENTRY_LAUNCHED",
2976
+ INT2FIX(GPGME_STATUS_PINENTRY_LAUNCHED));
2977
+ rb_define_const (mGPGME, "GPGME_STATUS_ATTRIBUTE",
2978
+ INT2FIX(GPGME_STATUS_ATTRIBUTE));
2979
+ rb_define_const (mGPGME, "GPGME_STATUS_BEGIN_SIGNING",
2980
+ INT2FIX(GPGME_STATUS_BEGIN_SIGNING));
2981
+ rb_define_const (mGPGME, "GPGME_STATUS_KEY_NOT_CREATED",
2982
+ INT2FIX(GPGME_STATUS_KEY_NOT_CREATED));
2983
+ #endif
2984
+
2985
+ /* The available keylist mode flags. */
2986
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_LOCAL",
2987
+ INT2FIX(GPGME_KEYLIST_MODE_LOCAL));
2988
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_EXTERN",
2989
+ INT2FIX(GPGME_KEYLIST_MODE_EXTERN));
2990
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_SIGS",
2991
+ INT2FIX(GPGME_KEYLIST_MODE_SIGS));
2992
+ /* This flag was added in 1.1.1. */
2993
+ #ifdef GPGME_KEYLIST_MODE_SIG_NOTATIONS
2994
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_SIG_NOTATIONS",
2995
+ INT2FIX(GPGME_KEYLIST_MODE_SIG_NOTATIONS));
2996
+ #endif
2997
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_VALIDATE",
2998
+ INT2FIX(GPGME_KEYLIST_MODE_VALIDATE));
2999
+ /* This flag was added in 1.2.0. */
3000
+ #ifdef GPGME_KEYLIST_MODE_EPHEMERAL
3001
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_EPHEMERAL",
3002
+ INT2FIX(GPGME_KEYLIST_MODE_EPHEMERAL));
3003
+ #endif
3004
+ /* This flag was added in 1.5.1. */
3005
+ #ifdef GPGME_KEYLIST_MODE_WITH_SECRET
3006
+ rb_define_const (mGPGME, "GPGME_KEYLIST_MODE_WITH_SECRET",
3007
+ INT2FIX(GPGME_KEYLIST_MODE_WITH_SECRET));
3008
+ #endif
3009
+
3010
+ /* The available flags for status field of gpgme_import_status_t. */
3011
+ rb_define_const (mGPGME, "GPGME_IMPORT_NEW", INT2FIX(GPGME_IMPORT_NEW));
3012
+ rb_define_const (mGPGME, "GPGME_IMPORT_UID", INT2FIX(GPGME_IMPORT_UID));
3013
+ rb_define_const (mGPGME, "GPGME_IMPORT_SIG", INT2FIX(GPGME_IMPORT_SIG));
3014
+ rb_define_const (mGPGME, "GPGME_IMPORT_SUBKEY",
3015
+ INT2FIX(GPGME_IMPORT_SUBKEY));
3016
+ rb_define_const (mGPGME, "GPGME_IMPORT_SECRET",
3017
+ INT2FIX(GPGME_IMPORT_SECRET));
3018
+
3019
+ /* The available flags for gpgme_op_encrypt. */
3020
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_ALWAYS_TRUST",
3021
+ INT2FIX(GPGME_ENCRYPT_ALWAYS_TRUST));
3022
+ /* This flag was added in 1.2.0. */
3023
+ #ifdef GPGME_ENCRYPT_NO_ENCRYPT_TO
3024
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_NO_ENCRYPT_TO",
3025
+ INT2FIX(GPGME_ENCRYPT_NO_ENCRYPT_TO));
3026
+ #endif
3027
+
3028
+ /* These flags were added in 1.4.0. */
3029
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010400
3030
+ rb_define_const (mGPGME, "GPGME_PINENTRY_MODE_DEFAULT",
3031
+ INT2FIX(GPGME_PINENTRY_MODE_DEFAULT));
3032
+ rb_define_const (mGPGME, "GPGME_PINENTRY_MODE_ASK",
3033
+ INT2FIX(GPGME_PINENTRY_MODE_ASK));
3034
+ rb_define_const (mGPGME, "GPGME_PINENTRY_MODE_CANCEL",
3035
+ INT2FIX(GPGME_PINENTRY_MODE_CANCEL));
3036
+ rb_define_const (mGPGME, "GPGME_PINENTRY_MODE_ERROR",
3037
+ INT2FIX(GPGME_PINENTRY_MODE_ERROR));
3038
+ rb_define_const (mGPGME, "GPGME_PINENTRY_MODE_LOOPBACK",
3039
+ INT2FIX(GPGME_PINENTRY_MODE_LOOPBACK));
3040
+ #endif
3041
+
3042
+ /* These flags were added in 1.5.0. */
3043
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010500
3044
+ rb_define_const (mGPGME, "GPGME_SPAWN_DETACHED",
3045
+ INT2FIX(GPGME_SPAWN_DETACHED));
3046
+ rb_define_const (mGPGME, "GPGME_SPAWN_ALLOW_SET_FG",
3047
+ INT2FIX(GPGME_SPAWN_ALLOW_SET_FG));
3048
+ #endif
3049
+
3050
+ /* This flag was added in 1.2.0. */
3051
+ #ifdef GPGME_EXPORT_MODE_EXTERN
3052
+ rb_define_const (mGPGME, "GPGME_EXPORT_MODE_EXTERN",
3053
+ INT2FIX(GPGME_EXPORT_MODE_EXTERN));
3054
+ #endif
3055
+
3056
+ /* This flag was added in 1.3.0. */
3057
+ #ifdef GPGME_EXPORT_MODE_MINIMAL
3058
+ rb_define_const (mGPGME, "GPGME_EXPORT_MODE_MINIMAL",
3059
+ INT2FIX(GPGME_EXPORT_MODE_MINIMAL));
3060
+ #endif
3061
+
3062
+ /* These flags were added in 1.6.0. */
3063
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010600
3064
+ rb_define_const (mGPGME, "GPGME_EXPORT_MODE_SECRET",
3065
+ INT2FIX(GPGME_EXPORT_MODE_SECRET));
3066
+ rb_define_const (mGPGME, "GPGME_EXPORT_MODE_RAW",
3067
+ INT2FIX(GPGME_EXPORT_MODE_RAW));
3068
+ rb_define_const (mGPGME, "GPGME_EXPORT_MODE_PKCS12",
3069
+ INT2FIX(GPGME_EXPORT_MODE_PKCS12));
3070
+ #endif
3071
+ }