106106#define UNWRAP_GPGME_KEY (vkey , key ) \
107107 Data_Get_Struct(vkey, struct _gpgme_key, key)
108108
109+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER < 0x020000
109110#define WRAP_GPGME_TRUST_ITEM (item ) \
110111 Data_Wrap_Struct(cTrustItem, 0, gpgme_trust_item_unref, item)
111112/* `gpgme_trust_item_t' is typedef'ed as `struct _gpgme_trust_item *'. */
112113#define UNWRAP_GPGME_TRUST_ITEM (vitem , item ) \
113114 Data_Get_Struct(vitem, struct _gpgme_trust_item, item)
115+ #endif
114116
115117static VALUE cEngineInfo ,
116118 cCtx ,
@@ -123,7 +125,9 @@ static VALUE cEngineInfo,
123125 cNewSignature ,
124126 cSignature ,
125127 cSigNotation ,
128+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER < 0x020000
126129 cTrustItem ,
130+ #endif
127131 cRecipient ,
128132 cDecryptResult ,
129133 cVerifyResult ,
@@ -1044,11 +1048,19 @@ save_gpgme_key_attrs (VALUE vkey, gpgme_key_t key)
10441048 rb_iv_set (vsubkey , "@keyid" , rb_str_new2 (subkey -> keyid ));
10451049 if (subkey -> fpr )
10461050 rb_iv_set (vsubkey , "@fpr" , rb_str_new2 (subkey -> fpr ));
1051+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
1052+ rb_iv_set (vsubkey , "@timestamp" , ULONG2NUM (subkey -> timestamp ));
1053+ rb_iv_set (vsubkey , "@expires" , ULONG2NUM (subkey -> expires ));
1054+ #else
10471055 rb_iv_set (vsubkey , "@timestamp" , LONG2NUM (subkey -> timestamp ));
10481056 rb_iv_set (vsubkey , "@expires" , LONG2NUM (subkey -> expires ));
1057+ #endif
10491058#if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x010500
10501059 if (subkey -> curve )
10511060 rb_iv_set (vsubkey , "@curve" , rb_str_new2 (subkey -> curve ));
1061+ #endif
1062+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
1063+ rb_iv_set (vsubkey , "@subkey_match" , INT2FIX (subkey -> subkey_match ));
10521064#endif
10531065 rb_ary_push (vsubkeys , vsubkey );
10541066 }
@@ -1079,8 +1091,13 @@ save_gpgme_key_attrs (VALUE vkey, gpgme_key_t key)
10791091 rb_iv_set (vkey_sig , "@exportable" , INT2FIX (key_sig -> exportable ));
10801092 rb_iv_set (vkey_sig , "@pubkey_algo" , INT2FIX (key_sig -> pubkey_algo ));
10811093 rb_iv_set (vkey_sig , "@keyid" , rb_str_new2 (key_sig -> keyid ));
1094+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
1095+ rb_iv_set (vkey_sig , "@timestamp" , ULONG2NUM (key_sig -> timestamp ));
1096+ rb_iv_set (vkey_sig , "@expires" , ULONG2NUM (key_sig -> expires ));
1097+ #else
10821098 rb_iv_set (vkey_sig , "@timestamp" , LONG2NUM (key_sig -> timestamp ));
10831099 rb_iv_set (vkey_sig , "@expires" , LONG2NUM (key_sig -> expires ));
1100+ #endif
10841101 rb_ary_push (vsignatures , vkey_sig );
10851102 }
10861103 rb_ary_push (vuids , vuser_id );
@@ -1653,6 +1670,7 @@ rb_s_gpgme_op_card_edit_start (VALUE dummy, VALUE vctx, VALUE vkey,
16531670 return LONG2NUM (err );
16541671}
16551672
1673+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER < 0x020000
16561674static VALUE
16571675rb_s_gpgme_op_trustlist_start (VALUE dummy , VALUE vctx , VALUE vpattern ,
16581676 VALUE vmax_level )
@@ -1716,6 +1734,7 @@ rb_s_gpgme_op_trustlist_end (VALUE dummy, VALUE vctx)
17161734 err = gpgme_op_trustlist_end (ctx );
17171735 return LONG2NUM (err );
17181736}
1737+ #endif
17191738
17201739static VALUE
17211740rb_s_gpgme_op_decrypt (VALUE dummy , VALUE vctx , VALUE vcipher , VALUE vplain )
@@ -2066,8 +2085,13 @@ rb_s_gpgme_op_sign_result (VALUE dummy, VALUE vctx)
20662085 INT2FIX (new_signature -> hash_algo ));
20672086 rb_iv_set (vnew_signature , "@sig_class" ,
20682087 UINT2NUM (new_signature -> sig_class ));
2088+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
2089+ rb_iv_set (vnew_signature , "@timestamp" ,
2090+ ULONG2NUM (new_signature -> timestamp ));
2091+ #else
20692092 rb_iv_set (vnew_signature , "@timestamp" ,
20702093 LONG2NUM (new_signature -> timestamp ));
2094+ #endif
20712095 rb_iv_set (vnew_signature , "@fpr" , rb_str_new2 (new_signature -> fpr ));
20722096 rb_ary_push (vsignatures , vnew_signature );
20732097 }
@@ -2356,6 +2380,57 @@ rb_s_gpgme_op_spawn (VALUE dummy, VALUE vctx, VALUE vfile,
23562380}
23572381#endif
23582382
2383+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
2384+ static VALUE
2385+ rb_s_gpgme_op_random_bytes (VALUE dummy , VALUE vctx , VALUE vsize , VALUE vmode )
2386+ {
2387+ gpgme_ctx_t ctx ;
2388+ gpgme_error_t err ;
2389+ size_t size ;
2390+ char * buffer ;
2391+ VALUE result ;
2392+
2393+ CHECK_KEYLIST_NOT_IN_PROGRESS (vctx );
2394+
2395+ UNWRAP_GPGME_CTX (vctx , ctx );
2396+ if (!ctx )
2397+ rb_raise (rb_eArgError , "released ctx" );
2398+
2399+ size = NUM2SIZET (vsize );
2400+ buffer = ALLOC_N (char , size );
2401+
2402+ err = gpgme_op_random_bytes (ctx , NUM2INT (vmode ), buffer , size );
2403+ if (err ) {
2404+ xfree (buffer );
2405+ return LONG2NUM (err );
2406+ }
2407+
2408+ result = rb_str_new (buffer , size );
2409+ xfree (buffer );
2410+ return result ;
2411+ }
2412+
2413+ static VALUE
2414+ rb_s_gpgme_op_random_value (VALUE dummy , VALUE vctx , VALUE vlimit )
2415+ {
2416+ gpgme_ctx_t ctx ;
2417+ size_t limit , result ;
2418+ gpgme_error_t err ;
2419+
2420+ CHECK_KEYLIST_NOT_IN_PROGRESS (vctx );
2421+
2422+ UNWRAP_GPGME_CTX (vctx , ctx );
2423+ if (!ctx )
2424+ rb_raise (rb_eArgError , "released ctx" );
2425+
2426+ limit = NUM2SIZET (vlimit );
2427+ err = gpgme_op_random_value (ctx , limit , & result );
2428+ if (gpgme_err_code (err ) == GPG_ERR_NO_ERROR )
2429+ return SIZET2NUM (result );
2430+ return LONG2NUM (err );
2431+ }
2432+ #endif
2433+
23592434void
23602435Init_gpgme_n (void )
23612436{
@@ -2422,8 +2497,10 @@ Init_gpgme_n (void)
24222497 rb_define_class_under (mGPGME , "Signature" , rb_cObject );
24232498 cSigNotation =
24242499 rb_define_class_under (mGPGME , "SigNotation" , rb_cObject );
2500+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER < 0x020000
24252501 cTrustItem =
24262502 rb_define_class_under (mGPGME , "TrustItem" , rb_cObject );
2503+ #endif
24272504 cInvalidKey =
24282505 rb_define_class_under (mGPGME , "InvalidKey" , rb_cObject );
24292506 cNewSignature =
@@ -2581,12 +2658,14 @@ Init_gpgme_n (void)
25812658 rb_s_gpgme_op_card_edit_start , 5 );
25822659
25832660 /* Trust Item Management */
2661+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER < 0x020000
25842662 rb_define_module_function (mGPGME , "gpgme_op_trustlist_start" ,
25852663 rb_s_gpgme_op_trustlist_start , 3 );
25862664 rb_define_module_function (mGPGME , "gpgme_op_trustlist_next" ,
25872665 rb_s_gpgme_op_trustlist_next , 2 );
25882666 rb_define_module_function (mGPGME , "gpgme_op_trustlist_end" ,
25892667 rb_s_gpgme_op_trustlist_end , 1 );
2668+ #endif
25902669
25912670 /* Decrypt */
25922671 rb_define_module_function (mGPGME , "gpgme_op_decrypt" ,
@@ -2648,6 +2727,14 @@ Init_gpgme_n (void)
26482727 rb_s_gpgme_op_spawn_start , 7 );
26492728#endif
26502729
2730+ /* Random Number Generation */
2731+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
2732+ rb_define_module_function (mGPGME , "gpgme_op_random_bytes" ,
2733+ rb_s_gpgme_op_random_bytes , 3 );
2734+ rb_define_module_function (mGPGME , "gpgme_op_random_value" ,
2735+ rb_s_gpgme_op_random_value , 2 );
2736+ #endif
2737+
26512738 /* gpgme_pubkey_algo_t */
26522739 rb_define_const (mGPGME , "GPGME_PK_RSA" , INT2FIX (GPGME_PK_RSA ));
26532740 rb_define_const (mGPGME , "GPGME_PK_DSA" , INT2FIX (GPGME_PK_DSA ));
@@ -2828,6 +2915,7 @@ Init_gpgme_n (void)
28282915 INT2FIX (GPGME_SIG_MODE_CLEAR ));
28292916
28302917 /* gpgme_attr_t */
2918+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER < 0x020000
28312919 rb_define_const (mGPGME , "GPGME_ATTR_KEYID" ,
28322920 INT2FIX (GPGME_ATTR_KEYID ));
28332921 rb_define_const (mGPGME , "GPGME_ATTR_FPR" ,
@@ -2890,6 +2978,7 @@ Init_gpgme_n (void)
28902978 INT2FIX (GPGME_ATTR_ERRTOK ));
28912979 rb_define_const (mGPGME , "GPGME_ATTR_SIG_SUMMARY" ,
28922980 INT2FIX (GPGME_ATTR_SIG_SUMMARY ));
2981+ #endif
28932982
28942983 /* gpgme_validity_t */
28952984 rb_define_const (mGPGME , "GPGME_VALIDITY_UNKNOWN" ,
@@ -3135,6 +3224,26 @@ Init_gpgme_n (void)
31353224 INT2FIX (GPGME_ENCRYPT_NO_ENCRYPT_TO ));
31363225#endif
31373226
3227+ /* Random number generation mode flags added in 2.0.0 */
3228+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
3229+ rb_define_const (mGPGME , "GPGME_RANDOM_MODE_NORMAL" ,
3230+ INT2FIX (GPGME_RANDOM_MODE_NORMAL ));
3231+ rb_define_const (mGPGME , "GPGME_RANDOM_MODE_ZBASE32" ,
3232+ INT2FIX (GPGME_RANDOM_MODE_ZBASE32 ));
3233+ #endif
3234+
3235+ /* Decrypt flags added in 2.0.0 */
3236+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
3237+ rb_define_const (mGPGME , "GPGME_DECRYPT_LISTONLY" ,
3238+ INT2FIX (GPGME_DECRYPT_LISTONLY ));
3239+ #endif
3240+
3241+ /* Key generation flags added in 2.0.0 */
3242+ #if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x020000
3243+ rb_define_const (mGPGME , "GPGME_CREATE_GROUP" ,
3244+ INT2FIX (GPGME_CREATE_GROUP ));
3245+ #endif
3246+
31383247 /* These flags were added in 1.4.0. */
31393248#if defined(GPGME_VERSION_NUMBER ) && GPGME_VERSION_NUMBER >= 0x010400
31403249 rb_define_const (mGPGME , "GPGME_PINENTRY_MODE_DEFAULT" ,
0 commit comments