gpgme 2.0.24 → 2.0.26

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.
data/ext/gpgme/gpgme_n.c CHANGED
@@ -88,29 +88,106 @@
88
88
  #define RSTRING_LEN(a) RSTRING(a)->len
89
89
  #endif
90
90
 
91
+ /* TypedData type definitions for Ruby 3.x compatibility */
92
+ static void
93
+ gpgme_data_free(void *ptr)
94
+ {
95
+ if (ptr)
96
+ gpgme_data_release((gpgme_data_t)ptr);
97
+ }
98
+
99
+ static const rb_data_type_t gpgme_data_type = {
100
+ .wrap_struct_name = "GPGME::Data",
101
+ .function = {
102
+ .dmark = NULL,
103
+ .dfree = gpgme_data_free,
104
+ .dsize = NULL,
105
+ },
106
+ .data = NULL,
107
+ .flags = 0,
108
+ };
109
+
110
+ static void
111
+ gpgme_ctx_free(void *ptr)
112
+ {
113
+ if (ptr)
114
+ gpgme_release((gpgme_ctx_t)ptr);
115
+ }
116
+
117
+ static const rb_data_type_t gpgme_ctx_type = {
118
+ .wrap_struct_name = "GPGME::Ctx",
119
+ .function = {
120
+ .dmark = NULL,
121
+ .dfree = gpgme_ctx_free,
122
+ .dsize = NULL,
123
+ },
124
+ .data = NULL,
125
+ .flags = 0,
126
+ };
127
+
128
+ static void
129
+ gpgme_key_free(void *ptr)
130
+ {
131
+ if (ptr)
132
+ gpgme_key_unref((gpgme_key_t)ptr);
133
+ }
134
+
135
+ static const rb_data_type_t gpgme_key_type = {
136
+ .wrap_struct_name = "GPGME::Key",
137
+ .function = {
138
+ .dmark = NULL,
139
+ .dfree = gpgme_key_free,
140
+ .dsize = NULL,
141
+ },
142
+ .data = NULL,
143
+ .flags = 0,
144
+ };
145
+
146
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER < 0x020000
147
+ static void
148
+ gpgme_trust_item_free(void *ptr)
149
+ {
150
+ if (ptr)
151
+ gpgme_trust_item_unref((gpgme_trust_item_t)ptr);
152
+ }
153
+
154
+ static const rb_data_type_t gpgme_trust_item_type = {
155
+ .wrap_struct_name = "GPGME::TrustItem",
156
+ .function = {
157
+ .dmark = NULL,
158
+ .dfree = gpgme_trust_item_free,
159
+ .dsize = NULL,
160
+ },
161
+ .data = NULL,
162
+ .flags = 0,
163
+ };
164
+ #endif
165
+
91
166
  #define WRAP_GPGME_DATA(dh) \
92
- Data_Wrap_Struct(cData, 0, gpgme_data_release, dh)
167
+ TypedData_Wrap_Struct(cData, &gpgme_data_type, dh)
93
168
  /* `gpgme_data_t' is typedef'ed as `struct gpgme_data *'. */
94
169
  #define UNWRAP_GPGME_DATA(vdh, dh) \
95
- Data_Get_Struct(vdh, struct gpgme_data, dh);
170
+ TypedData_Get_Struct(vdh, struct gpgme_data, &gpgme_data_type, dh)
96
171
 
97
172
  #define WRAP_GPGME_CTX(ctx) \
98
- Data_Wrap_Struct(cCtx, 0, gpgme_release, ctx)
173
+ TypedData_Wrap_Struct(cCtx, &gpgme_ctx_type, ctx)
99
174
  /* `gpgme_ctx_t' is typedef'ed as `struct gpgme_context *'. */
100
175
  #define UNWRAP_GPGME_CTX(vctx, ctx) \
101
- Data_Get_Struct(vctx, struct gpgme_context, ctx)
176
+ TypedData_Get_Struct(vctx, struct gpgme_context, &gpgme_ctx_type, ctx)
102
177
 
103
178
  #define WRAP_GPGME_KEY(key) \
104
- Data_Wrap_Struct(cKey, 0, gpgme_key_unref, key)
179
+ TypedData_Wrap_Struct(cKey, &gpgme_key_type, key)
105
180
  /* `gpgme_key_t' is typedef'ed as `struct _gpgme_key *'. */
106
181
  #define UNWRAP_GPGME_KEY(vkey, key) \
107
- Data_Get_Struct(vkey, struct _gpgme_key, key)
182
+ TypedData_Get_Struct(vkey, struct _gpgme_key, &gpgme_key_type, key)
108
183
 
184
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER < 0x020000
109
185
  #define WRAP_GPGME_TRUST_ITEM(item) \
110
- Data_Wrap_Struct(cTrustItem, 0, gpgme_trust_item_unref, item)
186
+ TypedData_Wrap_Struct(cTrustItem, &gpgme_trust_item_type, item)
111
187
  /* `gpgme_trust_item_t' is typedef'ed as `struct _gpgme_trust_item *'. */
112
188
  #define UNWRAP_GPGME_TRUST_ITEM(vitem, item) \
113
- Data_Get_Struct(vitem, struct _gpgme_trust_item, item)
189
+ TypedData_Get_Struct(vitem, struct _gpgme_trust_item, &gpgme_trust_item_type, item)
190
+ #endif
114
191
 
115
192
  static VALUE cEngineInfo,
116
193
  cCtx,
@@ -123,7 +200,9 @@ static VALUE cEngineInfo,
123
200
  cNewSignature,
124
201
  cSignature,
125
202
  cSigNotation,
203
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER < 0x020000
126
204
  cTrustItem,
205
+ #endif
127
206
  cRecipient,
128
207
  cDecryptResult,
129
208
  cVerifyResult,
@@ -264,19 +343,19 @@ rb_s_gpgme_hash_algo_name (VALUE dummy, VALUE valgo)
264
343
  static VALUE
265
344
  rb_s_gpgme_err_code (VALUE dummy, VALUE verr)
266
345
  {
267
- return INT2FIX(gpgme_err_code (NUM2LONG(verr)));
346
+ return INT2FIX(gpgme_err_code (NUM2UINT(verr)));
268
347
  }
269
348
 
270
349
  static VALUE
271
350
  rb_s_gpgme_err_source (VALUE dummy, VALUE verr)
272
351
  {
273
- return INT2FIX(gpgme_err_source (NUM2LONG(verr)));
352
+ return INT2FIX(gpgme_err_source (NUM2UINT(verr)));
274
353
  }
275
354
 
276
355
  static VALUE
277
356
  rb_s_gpgme_strerror (VALUE dummy, VALUE verr)
278
357
  {
279
- return rb_str_new2 (gpgme_strerror (NUM2LONG(verr)));
358
+ return rb_str_new2 (gpgme_strerror (NUM2UINT(verr)));
280
359
  }
281
360
 
282
361
  static VALUE
@@ -299,7 +378,7 @@ rb_s_gpgme_data_new_from_mem (VALUE dummy, VALUE rdh, VALUE vbuffer,
299
378
  size_t size = NUM2UINT(vsize);
300
379
  gpgme_error_t err;
301
380
 
302
- if (RSTRING_LEN(vbuffer) < size)
381
+ if ((size_t)RSTRING_LEN(vbuffer) < size)
303
382
  rb_raise (rb_eArgError, "argument out of range");
304
383
 
305
384
  err = gpgme_data_new_from_mem (&dh, StringValuePtr(vbuffer), size, 1);
@@ -341,11 +420,21 @@ static ssize_t
341
420
  write_cb (void *handle, const void *buffer, size_t size)
342
421
  {
343
422
  VALUE vcb = (VALUE)handle, vcbs, vhook_value, vbuffer, vnwrite;
423
+ rb_encoding *enc;
344
424
 
345
425
  vcbs = RARRAY_PTR(vcb)[0];
346
426
  vhook_value = RARRAY_PTR(vcb)[1];
347
427
  vbuffer = rb_str_new (buffer, size);
348
428
 
429
+ /* Associate encoding with the buffer string.
430
+ * Use default internal encoding if set, otherwise use binary encoding.
431
+ * This allows the app author to control the encoding via
432
+ * Encoding.default_internal while maintaining backward compatibility. */
433
+ enc = rb_default_internal_encoding ();
434
+ if (!enc)
435
+ enc = rb_ascii8bit_encoding ();
436
+ rb_enc_associate (vbuffer, enc);
437
+
349
438
  vnwrite = rb_funcall (vcbs, rb_intern ("write"), 3,
350
439
  vhook_value, vbuffer, LONG2NUM(size));
351
440
  return NUM2LONG(vnwrite);
@@ -510,7 +599,7 @@ rb_s_gpgme_release (VALUE dummy, VALUE vctx)
510
599
  if (!ctx)
511
600
  rb_raise (rb_eArgError, "released ctx");
512
601
  gpgme_release (ctx);
513
- DATA_PTR(vctx) = NULL;
602
+ RTYPEDDATA_DATA(vctx) = NULL;
514
603
  return Qnil;
515
604
  }
516
605
 
@@ -538,7 +627,6 @@ rb_s_gpgme_get_ctx_flag (VALUE dummy, VALUE vctx, VALUE vname)
538
627
  {
539
628
  gpgme_ctx_t ctx;
540
629
  const char* name;
541
- int yes;
542
630
 
543
631
  name = StringValueCStr(vname);
544
632
 
@@ -1045,11 +1133,19 @@ save_gpgme_key_attrs (VALUE vkey, gpgme_key_t key)
1045
1133
  rb_iv_set (vsubkey, "@keyid", rb_str_new2 (subkey->keyid));
1046
1134
  if (subkey->fpr)
1047
1135
  rb_iv_set (vsubkey, "@fpr", rb_str_new2 (subkey->fpr));
1136
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
1137
+ rb_iv_set (vsubkey, "@timestamp", ULONG2NUM(subkey->timestamp));
1138
+ rb_iv_set (vsubkey, "@expires", ULONG2NUM(subkey->expires));
1139
+ #else
1048
1140
  rb_iv_set (vsubkey, "@timestamp", LONG2NUM(subkey->timestamp));
1049
1141
  rb_iv_set (vsubkey, "@expires", LONG2NUM(subkey->expires));
1142
+ #endif
1050
1143
  #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010500
1051
1144
  if (subkey->curve)
1052
1145
  rb_iv_set (vsubkey, "@curve", rb_str_new2 (subkey->curve));
1146
+ #endif
1147
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
1148
+ rb_iv_set (vsubkey, "@subkey_match", INT2FIX(subkey->subkey_match));
1053
1149
  #endif
1054
1150
  rb_ary_push (vsubkeys, vsubkey);
1055
1151
  }
@@ -1080,8 +1176,13 @@ save_gpgme_key_attrs (VALUE vkey, gpgme_key_t key)
1080
1176
  rb_iv_set (vkey_sig, "@exportable", INT2FIX(key_sig->exportable));
1081
1177
  rb_iv_set (vkey_sig, "@pubkey_algo", INT2FIX(key_sig->pubkey_algo));
1082
1178
  rb_iv_set (vkey_sig, "@keyid", rb_str_new2 (key_sig->keyid));
1179
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
1180
+ rb_iv_set (vkey_sig, "@timestamp", ULONG2NUM(key_sig->timestamp));
1181
+ rb_iv_set (vkey_sig, "@expires", ULONG2NUM(key_sig->expires));
1182
+ #else
1083
1183
  rb_iv_set (vkey_sig, "@timestamp", LONG2NUM(key_sig->timestamp));
1084
1184
  rb_iv_set (vkey_sig, "@expires", LONG2NUM(key_sig->expires));
1185
+ #endif
1085
1186
  rb_ary_push (vsignatures, vkey_sig);
1086
1187
  }
1087
1188
  rb_ary_push (vuids, vuser_id);
@@ -1109,6 +1210,9 @@ rb_s_gpgme_op_keylist_next (VALUE dummy, VALUE vctx, VALUE rkey)
1109
1210
  save_gpgme_key_attrs (vkey, key);
1110
1211
  rb_ary_store (rkey, 0, vkey);
1111
1212
  }
1213
+
1214
+ RB_GC_GUARD(vctx);
1215
+
1112
1216
  return LONG2NUM(err);
1113
1217
  }
1114
1218
 
@@ -1484,6 +1588,27 @@ rb_s_gpgme_op_delete (VALUE dummy, VALUE vctx, VALUE vkey, VALUE vallow_secret)
1484
1588
  return LONG2NUM(err);
1485
1589
  }
1486
1590
 
1591
+ /* This method was added in 1.9.1. */
1592
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010901
1593
+ static VALUE
1594
+ rb_s_gpgme_op_delete_ext (VALUE dummy, VALUE vctx, VALUE vkey, VALUE vflags)
1595
+ {
1596
+ gpgme_ctx_t ctx;
1597
+ gpgme_key_t key;
1598
+ gpgme_error_t err;
1599
+
1600
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1601
+
1602
+ UNWRAP_GPGME_CTX(vctx, ctx);
1603
+ if (!ctx)
1604
+ rb_raise (rb_eArgError, "released ctx");
1605
+ UNWRAP_GPGME_KEY(vkey, key);
1606
+
1607
+ err = gpgme_op_delete_ext (ctx, key, NUM2INT(vflags));
1608
+ return LONG2NUM(err);
1609
+ }
1610
+ #endif
1611
+
1487
1612
  static VALUE
1488
1613
  rb_s_gpgme_op_delete_start (VALUE dummy, VALUE vctx, VALUE vkey,
1489
1614
  VALUE vallow_secret)
@@ -1503,6 +1628,305 @@ rb_s_gpgme_op_delete_start (VALUE dummy, VALUE vctx, VALUE vkey,
1503
1628
  return LONG2NUM(err);
1504
1629
  }
1505
1630
 
1631
+ /*
1632
+ * Key Edit Interface
1633
+ *
1634
+ * GPGME 2.0.0 deprecated gpgme_op_edit, gpgme_op_edit_start, gpgme_op_card_edit,
1635
+ * and gpgme_op_card_edit_start in favor of gpgme_op_interact and gpgme_op_interact_start.
1636
+ *
1637
+ * The new interact callback has a different signature:
1638
+ * Old: gpgme_error_t (*)(void *opaque, gpgme_status_code_t status, const char *args, int fd)
1639
+ * New: gpgme_error_t (*)(void *opaque, const char *keyword, const char *args, int fd)
1640
+ *
1641
+ * For backward compatibility, we keep the same Ruby interface (gpgme_op_edit, etc.)
1642
+ * but internally use gpgme_op_interact for GPGME 2.0.0+, converting keyword strings
1643
+ * to status codes in the callback shim.
1644
+ */
1645
+
1646
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
1647
+ /*
1648
+ * GPGME 2.0.0+: Use gpgme_op_interact internally, but expose the same
1649
+ * gpgme_op_edit interface to Ruby for backward compatibility.
1650
+ *
1651
+ * The shim callback converts keyword strings to status codes.
1652
+ */
1653
+
1654
+ /* Macro to define keyword-to-status mapping entries */
1655
+ #define STATUS_ENTRY(x) { #x, GPGME_STATUS_##x }
1656
+
1657
+ /* Mapping table from keyword strings to status codes */
1658
+ static struct {
1659
+ const char *keyword;
1660
+ gpgme_status_code_t status;
1661
+ } keyword_to_status[] = {
1662
+ STATUS_ENTRY(EOF),
1663
+ STATUS_ENTRY(ENTER),
1664
+ STATUS_ENTRY(LEAVE),
1665
+ STATUS_ENTRY(ABORT),
1666
+ STATUS_ENTRY(GOODSIG),
1667
+ STATUS_ENTRY(BADSIG),
1668
+ STATUS_ENTRY(ERRSIG),
1669
+ STATUS_ENTRY(BADARMOR),
1670
+ STATUS_ENTRY(RSA_OR_IDEA),
1671
+ STATUS_ENTRY(KEYEXPIRED),
1672
+ STATUS_ENTRY(KEYREVOKED),
1673
+ STATUS_ENTRY(TRUST_UNDEFINED),
1674
+ STATUS_ENTRY(TRUST_NEVER),
1675
+ STATUS_ENTRY(TRUST_MARGINAL),
1676
+ STATUS_ENTRY(TRUST_FULLY),
1677
+ STATUS_ENTRY(TRUST_ULTIMATE),
1678
+ STATUS_ENTRY(SHM_INFO),
1679
+ STATUS_ENTRY(SHM_GET),
1680
+ STATUS_ENTRY(SHM_GET_BOOL),
1681
+ STATUS_ENTRY(SHM_GET_HIDDEN),
1682
+ STATUS_ENTRY(NEED_PASSPHRASE),
1683
+ STATUS_ENTRY(VALIDSIG),
1684
+ STATUS_ENTRY(SIG_ID),
1685
+ STATUS_ENTRY(ENC_TO),
1686
+ STATUS_ENTRY(NODATA),
1687
+ STATUS_ENTRY(BAD_PASSPHRASE),
1688
+ STATUS_ENTRY(NO_PUBKEY),
1689
+ STATUS_ENTRY(NO_SECKEY),
1690
+ STATUS_ENTRY(NEED_PASSPHRASE_SYM),
1691
+ STATUS_ENTRY(DECRYPTION_FAILED),
1692
+ STATUS_ENTRY(DECRYPTION_OKAY),
1693
+ STATUS_ENTRY(MISSING_PASSPHRASE),
1694
+ STATUS_ENTRY(GOOD_PASSPHRASE),
1695
+ STATUS_ENTRY(GOODMDC),
1696
+ STATUS_ENTRY(BADMDC),
1697
+ STATUS_ENTRY(ERRMDC),
1698
+ STATUS_ENTRY(IMPORTED),
1699
+ STATUS_ENTRY(IMPORT_OK),
1700
+ STATUS_ENTRY(IMPORT_PROBLEM),
1701
+ STATUS_ENTRY(IMPORT_RES),
1702
+ STATUS_ENTRY(FILE_START),
1703
+ STATUS_ENTRY(FILE_DONE),
1704
+ STATUS_ENTRY(FILE_ERROR),
1705
+ STATUS_ENTRY(BEGIN_DECRYPTION),
1706
+ STATUS_ENTRY(END_DECRYPTION),
1707
+ STATUS_ENTRY(BEGIN_ENCRYPTION),
1708
+ STATUS_ENTRY(END_ENCRYPTION),
1709
+ STATUS_ENTRY(DELETE_PROBLEM),
1710
+ STATUS_ENTRY(GET_BOOL),
1711
+ STATUS_ENTRY(GET_LINE),
1712
+ STATUS_ENTRY(GET_HIDDEN),
1713
+ STATUS_ENTRY(GOT_IT),
1714
+ STATUS_ENTRY(PROGRESS),
1715
+ STATUS_ENTRY(SIG_CREATED),
1716
+ STATUS_ENTRY(SESSION_KEY),
1717
+ STATUS_ENTRY(NOTATION_NAME),
1718
+ STATUS_ENTRY(NOTATION_DATA),
1719
+ STATUS_ENTRY(POLICY_URL),
1720
+ STATUS_ENTRY(BEGIN_STREAM),
1721
+ STATUS_ENTRY(END_STREAM),
1722
+ STATUS_ENTRY(KEY_CREATED),
1723
+ STATUS_ENTRY(USERID_HINT),
1724
+ STATUS_ENTRY(UNEXPECTED),
1725
+ STATUS_ENTRY(INV_RECP),
1726
+ STATUS_ENTRY(NO_RECP),
1727
+ STATUS_ENTRY(ALREADY_SIGNED),
1728
+ STATUS_ENTRY(SIGEXPIRED),
1729
+ STATUS_ENTRY(EXPSIG),
1730
+ STATUS_ENTRY(EXPKEYSIG),
1731
+ STATUS_ENTRY(TRUNCATED),
1732
+ STATUS_ENTRY(ERROR),
1733
+ STATUS_ENTRY(NEWSIG),
1734
+ STATUS_ENTRY(REVKEYSIG),
1735
+ STATUS_ENTRY(SIG_SUBPACKET),
1736
+ STATUS_ENTRY(NEED_PASSPHRASE_PIN),
1737
+ STATUS_ENTRY(SC_OP_FAILURE),
1738
+ STATUS_ENTRY(SC_OP_SUCCESS),
1739
+ STATUS_ENTRY(CARDCTRL),
1740
+ STATUS_ENTRY(BACKUP_KEY_CREATED),
1741
+ STATUS_ENTRY(PKA_TRUST_BAD),
1742
+ STATUS_ENTRY(PKA_TRUST_GOOD),
1743
+ STATUS_ENTRY(PLAINTEXT),
1744
+ STATUS_ENTRY(INV_SGNR),
1745
+ STATUS_ENTRY(NO_SGNR),
1746
+ STATUS_ENTRY(SUCCESS),
1747
+ STATUS_ENTRY(DECRYPTION_INFO),
1748
+ STATUS_ENTRY(PLAINTEXT_LENGTH),
1749
+ STATUS_ENTRY(MOUNTPOINT),
1750
+ STATUS_ENTRY(PINENTRY_LAUNCHED),
1751
+ STATUS_ENTRY(ATTRIBUTE),
1752
+ STATUS_ENTRY(BEGIN_SIGNING),
1753
+ STATUS_ENTRY(KEY_NOT_CREATED),
1754
+ STATUS_ENTRY(INQUIRE_MAXLEN),
1755
+ STATUS_ENTRY(FAILURE),
1756
+ STATUS_ENTRY(KEY_CONSIDERED),
1757
+ STATUS_ENTRY(TOFU_USER),
1758
+ STATUS_ENTRY(TOFU_STATS),
1759
+ STATUS_ENTRY(TOFU_STATS_LONG),
1760
+ STATUS_ENTRY(NOTATION_FLAGS),
1761
+ STATUS_ENTRY(DECRYPTION_COMPLIANCE_MODE),
1762
+ STATUS_ENTRY(VERIFICATION_COMPLIANCE_MODE),
1763
+ STATUS_ENTRY(CANCELED_BY_USER),
1764
+ { NULL, GPGME_STATUS_EOF }
1765
+ };
1766
+
1767
+ #undef STATUS_ENTRY
1768
+
1769
+ static gpgme_status_code_t
1770
+ keyword_to_status_code (const char *keyword)
1771
+ {
1772
+ size_t i;
1773
+
1774
+ if (!keyword)
1775
+ return GPGME_STATUS_EOF;
1776
+
1777
+ for (i = 0; keyword_to_status[i].keyword != NULL; i++)
1778
+ {
1779
+ if (strcmp (keyword, keyword_to_status[i].keyword) == 0)
1780
+ return keyword_to_status[i].status;
1781
+ }
1782
+
1783
+ /* Unknown keyword - return EOF as fallback */
1784
+ return GPGME_STATUS_EOF;
1785
+ }
1786
+
1787
+ /*
1788
+ * Shim callback that converts keyword strings to status codes
1789
+ * for backward compatibility with existing Ruby callbacks.
1790
+ */
1791
+ static gpgme_error_t
1792
+ edit_cb_shim (void *hook, const char *keyword, const char *args, int fd)
1793
+ {
1794
+ VALUE vcb = (VALUE) hook, veditfunc, vhook_value;
1795
+ gpgme_status_code_t status;
1796
+
1797
+ veditfunc = RARRAY_PTR (vcb)[0];
1798
+ vhook_value = RARRAY_PTR (vcb)[1];
1799
+
1800
+ status = keyword_to_status_code (keyword);
1801
+
1802
+ rb_funcall (veditfunc, rb_intern ("call"), 4, vhook_value, INT2FIX (status),
1803
+ args ? rb_str_new2 (args) : rb_str_new2 (""), INT2NUM (fd));
1804
+ return gpgme_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_NO_ERROR);
1805
+ }
1806
+
1807
+ static VALUE
1808
+ rb_s_gpgme_op_edit (VALUE dummy, VALUE vctx, VALUE vkey,
1809
+ VALUE veditfunc, VALUE vhook_value, VALUE vout)
1810
+ {
1811
+ gpgme_ctx_t ctx;
1812
+ gpgme_key_t key;
1813
+ gpgme_data_t out = NULL;
1814
+ VALUE vcb;
1815
+ gpgme_error_t err;
1816
+
1817
+ CHECK_KEYLIST_NOT_IN_PROGRESS (vctx);
1818
+
1819
+ UNWRAP_GPGME_CTX(vctx, ctx);
1820
+ if (!ctx)
1821
+ rb_raise (rb_eArgError, "released ctx");
1822
+ UNWRAP_GPGME_KEY(vkey, key);
1823
+ if (!NIL_P(vout))
1824
+ UNWRAP_GPGME_DATA(vout, out);
1825
+
1826
+ vcb = rb_ary_new ();
1827
+ rb_ary_push (vcb, veditfunc);
1828
+ rb_ary_push (vcb, vhook_value);
1829
+ /* Keep a reference to avoid GC. */
1830
+ rb_iv_set (vctx, "@edit_cb", vcb);
1831
+
1832
+ /* Use gpgme_op_interact with flags=0, shim converts keywords to status codes */
1833
+ err = gpgme_op_interact (ctx, key, 0, edit_cb_shim, (void *)vcb, out);
1834
+ return LONG2NUM(err);
1835
+ }
1836
+
1837
+ static VALUE
1838
+ rb_s_gpgme_op_edit_start (VALUE dummy, VALUE vctx, VALUE vkey,
1839
+ VALUE veditfunc, VALUE vhook_value, VALUE vout)
1840
+ {
1841
+ gpgme_ctx_t ctx;
1842
+ gpgme_key_t key;
1843
+ gpgme_data_t out = NULL;
1844
+ VALUE vcb;
1845
+ gpgme_error_t err;
1846
+
1847
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1848
+
1849
+ UNWRAP_GPGME_CTX(vctx, ctx);
1850
+ if (!ctx)
1851
+ rb_raise (rb_eArgError, "released ctx");
1852
+ UNWRAP_GPGME_KEY(vkey, key);
1853
+ if (!NIL_P(vout))
1854
+ UNWRAP_GPGME_DATA(vout, out);
1855
+
1856
+ vcb = rb_ary_new ();
1857
+ rb_ary_push (vcb, veditfunc);
1858
+ rb_ary_push (vcb, vhook_value);
1859
+ /* Keep a reference to avoid GC. */
1860
+ rb_iv_set (vctx, "@edit_cb", vcb);
1861
+
1862
+ /* Use gpgme_op_interact_start with flags=0, shim converts keywords to status codes */
1863
+ err = gpgme_op_interact_start (ctx, key, 0, edit_cb_shim, (void *)vcb, out);
1864
+ return LONG2NUM(err);
1865
+ }
1866
+
1867
+ static VALUE
1868
+ rb_s_gpgme_op_card_edit (VALUE dummy, VALUE vctx, VALUE vkey,
1869
+ VALUE veditfunc, VALUE vhook_value, VALUE vout)
1870
+ {
1871
+ gpgme_ctx_t ctx;
1872
+ gpgme_key_t key;
1873
+ gpgme_data_t out = NULL;
1874
+ VALUE vcb;
1875
+ gpgme_error_t err;
1876
+
1877
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1878
+
1879
+ UNWRAP_GPGME_CTX(vctx, ctx);
1880
+ if (!ctx)
1881
+ rb_raise (rb_eArgError, "released ctx");
1882
+ UNWRAP_GPGME_KEY(vkey, key);
1883
+ if (!NIL_P(vout))
1884
+ UNWRAP_GPGME_DATA(vout, out);
1885
+
1886
+ vcb = rb_ary_new ();
1887
+ rb_ary_push (vcb, veditfunc);
1888
+ rb_ary_push (vcb, vhook_value);
1889
+ /* Keep a reference to avoid GC. */
1890
+ rb_iv_set (vctx, "@card_edit_cb", vcb);
1891
+
1892
+ /* Use gpgme_op_interact with GPGME_INTERACT_CARD flag */
1893
+ err = gpgme_op_interact (ctx, key, GPGME_INTERACT_CARD, edit_cb_shim, (void *)vcb, out);
1894
+ return LONG2NUM(err);
1895
+ }
1896
+
1897
+ static VALUE
1898
+ rb_s_gpgme_op_card_edit_start (VALUE dummy, VALUE vctx, VALUE vkey,
1899
+ VALUE veditfunc, VALUE vhook_value, VALUE vout)
1900
+ {
1901
+ gpgme_ctx_t ctx;
1902
+ gpgme_key_t key;
1903
+ gpgme_data_t out = NULL;
1904
+ VALUE vcb;
1905
+ gpgme_error_t err;
1906
+
1907
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
1908
+
1909
+ UNWRAP_GPGME_CTX(vctx, ctx);
1910
+ if (!ctx)
1911
+ rb_raise (rb_eArgError, "released ctx");
1912
+ UNWRAP_GPGME_KEY(vkey, key);
1913
+ if (!NIL_P(vout))
1914
+ UNWRAP_GPGME_DATA(vout, out);
1915
+
1916
+ vcb = rb_ary_new ();
1917
+ rb_ary_push (vcb, veditfunc);
1918
+ rb_ary_push (vcb, vhook_value);
1919
+ /* Keep a reference to avoid GC. */
1920
+ rb_iv_set (vctx, "@card_edit_cb", vcb);
1921
+
1922
+ /* Use gpgme_op_interact_start with GPGME_INTERACT_CARD flag */
1923
+ err = gpgme_op_interact_start (ctx, key, GPGME_INTERACT_CARD, edit_cb_shim, (void *)vcb, out);
1924
+ return LONG2NUM(err);
1925
+ }
1926
+
1927
+ #else
1928
+ /* GPGME < 2.0.0: Use the original gpgme_op_edit functions directly */
1929
+
1506
1930
  static gpgme_error_t
1507
1931
  edit_cb (void *hook, gpgme_status_code_t status, const char *args, int fd)
1508
1932
  {
@@ -1632,7 +2056,9 @@ rb_s_gpgme_op_card_edit_start (VALUE dummy, VALUE vctx, VALUE vkey,
1632
2056
  err = gpgme_op_card_edit_start (ctx, key, edit_cb, (void *)vcb, out);
1633
2057
  return LONG2NUM(err);
1634
2058
  }
2059
+ #endif /* GPGME_VERSION_NUMBER >= 0x020000 */
1635
2060
 
2061
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER < 0x020000
1636
2062
  static VALUE
1637
2063
  rb_s_gpgme_op_trustlist_start (VALUE dummy, VALUE vctx, VALUE vpattern,
1638
2064
  VALUE vmax_level)
@@ -1696,6 +2122,7 @@ rb_s_gpgme_op_trustlist_end (VALUE dummy, VALUE vctx)
1696
2122
  err = gpgme_op_trustlist_end (ctx);
1697
2123
  return LONG2NUM(err);
1698
2124
  }
2125
+ #endif
1699
2126
 
1700
2127
  static VALUE
1701
2128
  rb_s_gpgme_op_decrypt (VALUE dummy, VALUE vctx, VALUE vcipher, VALUE vplain)
@@ -1713,6 +2140,11 @@ rb_s_gpgme_op_decrypt (VALUE dummy, VALUE vctx, VALUE vcipher, VALUE vplain)
1713
2140
  UNWRAP_GPGME_DATA(vplain, plain);
1714
2141
 
1715
2142
  err = gpgme_op_decrypt (ctx, cipher, plain);
2143
+
2144
+ RB_GC_GUARD(vctx);
2145
+ RB_GC_GUARD(vcipher);
2146
+ RB_GC_GUARD(vplain);
2147
+
1716
2148
  return LONG2NUM(err);
1717
2149
  }
1718
2150
 
@@ -1792,6 +2224,12 @@ rb_s_gpgme_op_verify (VALUE dummy, VALUE vctx, VALUE vsig, VALUE vsigned_text,
1792
2224
  UNWRAP_GPGME_DATA(vplain, plain);
1793
2225
 
1794
2226
  err = gpgme_op_verify (ctx, sig, signed_text, plain);
2227
+
2228
+ RB_GC_GUARD(vctx);
2229
+ RB_GC_GUARD(vsig);
2230
+ RB_GC_GUARD(vsigned_text);
2231
+ RB_GC_GUARD(vplain);
2232
+
1795
2233
  return LONG2NUM(err);
1796
2234
  }
1797
2235
 
@@ -1896,6 +2334,11 @@ rb_s_gpgme_op_decrypt_verify (VALUE dummy, VALUE vctx, VALUE vcipher,
1896
2334
  UNWRAP_GPGME_DATA(vplain, plain);
1897
2335
 
1898
2336
  err = gpgme_op_decrypt_verify (ctx, cipher, plain);
2337
+
2338
+ RB_GC_GUARD(vctx);
2339
+ RB_GC_GUARD(vcipher);
2340
+ RB_GC_GUARD(vplain);
2341
+
1899
2342
  return LONG2NUM(err);
1900
2343
  }
1901
2344
 
@@ -1980,6 +2423,11 @@ rb_s_gpgme_op_sign (VALUE dummy, VALUE vctx, VALUE vplain, VALUE vsig,
1980
2423
  UNWRAP_GPGME_DATA(vsig, sig);
1981
2424
 
1982
2425
  err = gpgme_op_sign (ctx, plain, sig, NUM2INT(vmode));
2426
+
2427
+ RB_GC_GUARD(vctx);
2428
+ RB_GC_GUARD(vplain);
2429
+ RB_GC_GUARD(vsig);
2430
+
1983
2431
  return LONG2NUM(err);
1984
2432
  }
1985
2433
 
@@ -2046,8 +2494,13 @@ rb_s_gpgme_op_sign_result (VALUE dummy, VALUE vctx)
2046
2494
  INT2FIX(new_signature->hash_algo));
2047
2495
  rb_iv_set (vnew_signature, "@sig_class",
2048
2496
  UINT2NUM(new_signature->sig_class));
2497
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
2498
+ rb_iv_set (vnew_signature, "@timestamp",
2499
+ ULONG2NUM(new_signature->timestamp));
2500
+ #else
2049
2501
  rb_iv_set (vnew_signature, "@timestamp",
2050
2502
  LONG2NUM(new_signature->timestamp));
2503
+ #endif
2051
2504
  rb_iv_set (vnew_signature, "@fpr", rb_str_new2 (new_signature->fpr));
2052
2505
  rb_ary_push (vsignatures, vnew_signature);
2053
2506
  }
@@ -2084,6 +2537,12 @@ rb_s_gpgme_op_encrypt (VALUE dummy, VALUE vctx, VALUE vrecp, VALUE vflags,
2084
2537
  err = gpgme_op_encrypt (ctx, recp, NUM2INT(vflags), plain, cipher);
2085
2538
  if (recp)
2086
2539
  xfree (recp);
2540
+
2541
+ RB_GC_GUARD(vctx);
2542
+ RB_GC_GUARD(vrecp);
2543
+ RB_GC_GUARD(vplain);
2544
+ RB_GC_GUARD(vcipher);
2545
+
2087
2546
  return LONG2NUM(err);
2088
2547
  }
2089
2548
 
@@ -2183,6 +2642,12 @@ rb_s_gpgme_op_encrypt_sign (VALUE dummy, VALUE vctx, VALUE vrecp, VALUE vflags,
2183
2642
  err = gpgme_op_encrypt_sign (ctx, recp, NUM2INT(vflags), plain, cipher);
2184
2643
  if (recp)
2185
2644
  xfree (recp);
2645
+
2646
+ RB_GC_GUARD(vctx);
2647
+ RB_GC_GUARD(vrecp);
2648
+ RB_GC_GUARD(vplain);
2649
+ RB_GC_GUARD(vcipher);
2650
+
2186
2651
  return LONG2NUM(err);
2187
2652
  }
2188
2653
 
@@ -2336,6 +2801,57 @@ rb_s_gpgme_op_spawn (VALUE dummy, VALUE vctx, VALUE vfile,
2336
2801
  }
2337
2802
  #endif
2338
2803
 
2804
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
2805
+ static VALUE
2806
+ rb_s_gpgme_op_random_bytes (VALUE dummy, VALUE vctx, VALUE vsize, VALUE vmode)
2807
+ {
2808
+ gpgme_ctx_t ctx;
2809
+ gpgme_error_t err;
2810
+ size_t size;
2811
+ char *buffer;
2812
+ VALUE result;
2813
+
2814
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
2815
+
2816
+ UNWRAP_GPGME_CTX(vctx, ctx);
2817
+ if (!ctx)
2818
+ rb_raise (rb_eArgError, "released ctx");
2819
+
2820
+ size = NUM2SIZET(vsize);
2821
+ buffer = ALLOC_N(char, size);
2822
+
2823
+ err = gpgme_op_random_bytes (ctx, NUM2INT(vmode), buffer, size);
2824
+ if (err) {
2825
+ xfree(buffer);
2826
+ return LONG2NUM(err);
2827
+ }
2828
+
2829
+ result = rb_str_new(buffer, size);
2830
+ xfree(buffer);
2831
+ return result;
2832
+ }
2833
+
2834
+ static VALUE
2835
+ rb_s_gpgme_op_random_value (VALUE dummy, VALUE vctx, VALUE vlimit)
2836
+ {
2837
+ gpgme_ctx_t ctx;
2838
+ size_t limit, result;
2839
+ gpgme_error_t err;
2840
+
2841
+ CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
2842
+
2843
+ UNWRAP_GPGME_CTX(vctx, ctx);
2844
+ if (!ctx)
2845
+ rb_raise (rb_eArgError, "released ctx");
2846
+
2847
+ limit = NUM2SIZET(vlimit);
2848
+ err = gpgme_op_random_value (ctx, limit, &result);
2849
+ if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
2850
+ return SIZET2NUM(result);
2851
+ return LONG2NUM(err);
2852
+ }
2853
+ #endif
2854
+
2339
2855
  void
2340
2856
  Init_gpgme_n (void)
2341
2857
  {
@@ -2402,8 +2918,10 @@ Init_gpgme_n (void)
2402
2918
  rb_define_class_under (mGPGME, "Signature", rb_cObject);
2403
2919
  cSigNotation =
2404
2920
  rb_define_class_under (mGPGME, "SigNotation", rb_cObject);
2921
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER < 0x020000
2405
2922
  cTrustItem =
2406
2923
  rb_define_class_under (mGPGME, "TrustItem", rb_cObject);
2924
+ #endif
2407
2925
  cInvalidKey =
2408
2926
  rb_define_class_under (mGPGME, "InvalidKey", rb_cObject);
2409
2927
  cNewSignature =
@@ -2547,8 +3065,15 @@ Init_gpgme_n (void)
2547
3065
  rb_s_gpgme_op_import_result, 1);
2548
3066
  rb_define_module_function (mGPGME, "gpgme_op_delete",
2549
3067
  rb_s_gpgme_op_delete, 3);
3068
+ rb_define_module_function (mGPGME, "gpgme_op_delete_ext",
3069
+ rb_s_gpgme_op_delete_ext, 3);
2550
3070
  rb_define_module_function (mGPGME, "gpgme_op_delete_start",
2551
3071
  rb_s_gpgme_op_delete_start, 3);
3072
+
3073
+ /* Key Edit Interface
3074
+ * For GPGME 2.0.0+, these functions use gpgme_op_interact internally
3075
+ * with a shim to maintain backward compatibility with existing callbacks.
3076
+ */
2552
3077
  rb_define_module_function (mGPGME, "gpgme_op_edit",
2553
3078
  rb_s_gpgme_op_edit, 5);
2554
3079
  rb_define_module_function (mGPGME, "gpgme_op_edit_start",
@@ -2559,12 +3084,14 @@ Init_gpgme_n (void)
2559
3084
  rb_s_gpgme_op_card_edit_start, 5);
2560
3085
 
2561
3086
  /* Trust Item Management */
3087
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER < 0x020000
2562
3088
  rb_define_module_function (mGPGME, "gpgme_op_trustlist_start",
2563
3089
  rb_s_gpgme_op_trustlist_start, 3);
2564
3090
  rb_define_module_function (mGPGME, "gpgme_op_trustlist_next",
2565
3091
  rb_s_gpgme_op_trustlist_next, 2);
2566
3092
  rb_define_module_function (mGPGME, "gpgme_op_trustlist_end",
2567
3093
  rb_s_gpgme_op_trustlist_end, 1);
3094
+ #endif
2568
3095
 
2569
3096
  /* Decrypt */
2570
3097
  rb_define_module_function (mGPGME, "gpgme_op_decrypt",
@@ -2626,6 +3153,14 @@ Init_gpgme_n (void)
2626
3153
  rb_s_gpgme_op_spawn_start, 7);
2627
3154
  #endif
2628
3155
 
3156
+ /* Random Number Generation */
3157
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
3158
+ rb_define_module_function (mGPGME, "gpgme_op_random_bytes",
3159
+ rb_s_gpgme_op_random_bytes, 3);
3160
+ rb_define_module_function (mGPGME, "gpgme_op_random_value",
3161
+ rb_s_gpgme_op_random_value, 2);
3162
+ #endif
3163
+
2629
3164
  /* gpgme_pubkey_algo_t */
2630
3165
  rb_define_const (mGPGME, "GPGME_PK_RSA", INT2FIX(GPGME_PK_RSA));
2631
3166
  rb_define_const (mGPGME, "GPGME_PK_DSA", INT2FIX(GPGME_PK_DSA));
@@ -2806,6 +3341,7 @@ Init_gpgme_n (void)
2806
3341
  INT2FIX(GPGME_SIG_MODE_CLEAR));
2807
3342
 
2808
3343
  /* gpgme_attr_t */
3344
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER < 0x020000
2809
3345
  rb_define_const (mGPGME, "GPGME_ATTR_KEYID",
2810
3346
  INT2FIX(GPGME_ATTR_KEYID));
2811
3347
  rb_define_const (mGPGME, "GPGME_ATTR_FPR",
@@ -2868,6 +3404,7 @@ Init_gpgme_n (void)
2868
3404
  INT2FIX(GPGME_ATTR_ERRTOK));
2869
3405
  rb_define_const (mGPGME, "GPGME_ATTR_SIG_SUMMARY",
2870
3406
  INT2FIX(GPGME_ATTR_SIG_SUMMARY));
3407
+ #endif
2871
3408
 
2872
3409
  /* gpgme_validity_t */
2873
3410
  rb_define_const (mGPGME, "GPGME_VALIDITY_UNKNOWN",
@@ -3107,11 +3644,78 @@ Init_gpgme_n (void)
3107
3644
  /* The available flags for gpgme_op_encrypt. */
3108
3645
  rb_define_const (mGPGME, "GPGME_ENCRYPT_ALWAYS_TRUST",
3109
3646
  INT2FIX(GPGME_ENCRYPT_ALWAYS_TRUST));
3110
- /* This flag was added in 1.2.0. */
3111
- #ifdef GPGME_ENCRYPT_NO_ENCRYPT_TO
3647
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_NO_ENCRYPT_TO
3112
3648
  rb_define_const (mGPGME, "GPGME_ENCRYPT_NO_ENCRYPT_TO",
3113
3649
  INT2FIX(GPGME_ENCRYPT_NO_ENCRYPT_TO));
3114
3650
  #endif
3651
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_PREPARE
3652
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_PREPARE",
3653
+ INT2FIX(GPGME_ENCRYPT_PREPARE));
3654
+ #endif
3655
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_EXPECT_SIGN
3656
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_EXPECT_SIGN",
3657
+ INT2FIX(GPGME_ENCRYPT_EXPECT_SIGN));
3658
+ #endif
3659
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_NO_COMPRESS
3660
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_NO_COMPRESS",
3661
+ INT2FIX(GPGME_ENCRYPT_NO_COMPRESS));
3662
+ #endif
3663
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_UNSIGNED_INTEGRITY_CHECK
3664
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_UNSIGNED_INTEGRITY_CHECK",
3665
+ INT2FIX(GPGME_ENCRYPT_UNSIGNED_INTEGRITY_CHECK));
3666
+ #endif
3667
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_SYMMETRIC
3668
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_SYMMETRIC",
3669
+ INT2FIX(GPGME_ENCRYPT_SYMMETRIC));
3670
+ #endif
3671
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_THROW_KEYIDS
3672
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_THROW_KEYIDS",
3673
+ INT2FIX(GPGME_ENCRYPT_THROW_KEYIDS));
3674
+ #endif
3675
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_WRAP
3676
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_WRAP",
3677
+ INT2FIX(GPGME_ENCRYPT_WRAP));
3678
+ #endif
3679
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_WANT_ADDRESS
3680
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_WANT_ADDRESS",
3681
+ INT2FIX(GPGME_ENCRYPT_WANT_ADDRESS));
3682
+ #endif
3683
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_ARCHIVE
3684
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_ARCHIVE",
3685
+ INT2FIX(GPGME_ENCRYPT_ARCHIVE));
3686
+ #endif
3687
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_FILE
3688
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_FILE",
3689
+ INT2FIX(GPGME_ENCRYPT_FILE));
3690
+ #endif
3691
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_ADD_RECP
3692
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_ADD_RECP",
3693
+ INT2FIX(GPGME_ENCRYPT_ADD_RECP));
3694
+ #endif
3695
+ #ifdef HAVE_CONST_GPGME_ENCRYPT_CHG_RECP
3696
+ rb_define_const (mGPGME, "GPGME_ENCRYPT_CHG_RECP",
3697
+ INT2FIX(GPGME_ENCRYPT_CHG_RECP));
3698
+ #endif
3699
+
3700
+ /* Random number generation mode flags added in 2.0.0 */
3701
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
3702
+ rb_define_const (mGPGME, "GPGME_RANDOM_MODE_NORMAL",
3703
+ INT2FIX(GPGME_RANDOM_MODE_NORMAL));
3704
+ rb_define_const (mGPGME, "GPGME_RANDOM_MODE_ZBASE32",
3705
+ INT2FIX(GPGME_RANDOM_MODE_ZBASE32));
3706
+ #endif
3707
+
3708
+ /* Decrypt flags added in 2.0.0 */
3709
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
3710
+ rb_define_const (mGPGME, "GPGME_DECRYPT_LISTONLY",
3711
+ INT2FIX(GPGME_DECRYPT_LISTONLY));
3712
+ #endif
3713
+
3714
+ /* Key generation flags added in 2.0.0 */
3715
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
3716
+ rb_define_const (mGPGME, "GPGME_CREATE_GROUP",
3717
+ INT2FIX(GPGME_CREATE_GROUP));
3718
+ #endif
3115
3719
 
3116
3720
  /* These flags were added in 1.4.0. */
3117
3721
  #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010400
@@ -3156,4 +3760,13 @@ Init_gpgme_n (void)
3156
3760
  rb_define_const (mGPGME, "GPGME_EXPORT_MODE_PKCS12",
3157
3761
  INT2FIX(GPGME_EXPORT_MODE_PKCS12));
3158
3762
  #endif
3763
+
3764
+ /* These flags were added in 1.9.1. */
3765
+ #if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x010901
3766
+ rb_define_const (mGPGME, "GPGME_DELETE_ALLOW_SECRET",
3767
+ INT2FIX(GPGME_DELETE_ALLOW_SECRET));
3768
+ rb_define_const (mGPGME, "GPGME_DELETE_FORCE",
3769
+ INT2FIX(GPGME_DELETE_FORCE));
3770
+ #endif
3159
3771
  }
3772
+