ruby-gpgme 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +1 -0
- data/THANKS +13 -0
- data/gpgme_n.c +133 -7
- data/lib/gpgme.rb +131 -96
- metadata +3 -2
data/MANIFEST
CHANGED
data/THANKS
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Ruby-GPGME was originally written by Daiki Ueno. Other people
|
2
|
+
contributed by reporting problems, suggesting various improvements or
|
3
|
+
submitting actual code. Here is a list of those people. Help us keep
|
4
|
+
it complete and free of errors.
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
Carl Corliss
|
9
|
+
Kris Nuttycombe
|
10
|
+
Marc Dequènes
|
11
|
+
Rob Pitt
|
12
|
+
Rory McKinley
|
13
|
+
Sam Hall
|
data/gpgme_n.c
CHANGED
@@ -80,6 +80,11 @@
|
|
80
80
|
#define RARRAY_PTR(a) RARRAY(a)->ptr
|
81
81
|
#endif
|
82
82
|
|
83
|
+
/* RSTRING_LEN is not available in 1.8.5. */
|
84
|
+
#ifndef RSTRING_LEN
|
85
|
+
#define RSTRING_LEN(a) RSTRING(a)->len
|
86
|
+
#endif
|
87
|
+
|
83
88
|
#define WRAP_GPGME_DATA(dh) \
|
84
89
|
Data_Wrap_Struct(cData, 0, gpgme_data_release, dh)
|
85
90
|
/* `gpgme_data_t' is typedef'ed as `struct gpgme_data *'. */
|
@@ -414,6 +419,19 @@ rb_s_gpgme_new (VALUE dummy, VALUE rctx)
|
|
414
419
|
return LONG2NUM(err);
|
415
420
|
}
|
416
421
|
|
422
|
+
static VALUE
|
423
|
+
rb_s_gpgme_release (VALUE dummy, VALUE vctx)
|
424
|
+
{
|
425
|
+
gpgme_ctx_t ctx;
|
426
|
+
|
427
|
+
UNWRAP_GPGME_CTX(vctx, ctx);
|
428
|
+
if (!ctx)
|
429
|
+
rb_raise (rb_eArgError, "released ctx");
|
430
|
+
gpgme_release (ctx);
|
431
|
+
DATA_PTR(vctx) = NULL;
|
432
|
+
return Qnil;
|
433
|
+
}
|
434
|
+
|
417
435
|
static VALUE
|
418
436
|
rb_s_gpgme_set_protocol (VALUE dummy, VALUE vctx, VALUE vproto)
|
419
437
|
{
|
@@ -421,6 +439,8 @@ rb_s_gpgme_set_protocol (VALUE dummy, VALUE vctx, VALUE vproto)
|
|
421
439
|
gpgme_error_t err;
|
422
440
|
|
423
441
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
442
|
+
if (!ctx)
|
443
|
+
rb_raise (rb_eArgError, "released ctx");
|
424
444
|
err = gpgme_set_protocol (ctx, NUM2INT(vproto));
|
425
445
|
return LONG2NUM(err);
|
426
446
|
}
|
@@ -432,6 +452,8 @@ rb_s_gpgme_get_protocol (VALUE dummy, VALUE vctx)
|
|
432
452
|
gpgme_protocol_t proto;
|
433
453
|
|
434
454
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
455
|
+
if (!ctx)
|
456
|
+
rb_raise (rb_eArgError, "released ctx");
|
435
457
|
proto = gpgme_get_protocol (ctx);
|
436
458
|
return INT2FIX(proto);
|
437
459
|
}
|
@@ -442,6 +464,8 @@ rb_s_gpgme_set_armor (VALUE dummy, VALUE vctx, VALUE vyes)
|
|
442
464
|
gpgme_ctx_t ctx;
|
443
465
|
|
444
466
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
467
|
+
if (!ctx)
|
468
|
+
rb_raise (rb_eArgError, "released ctx");
|
445
469
|
gpgme_set_armor (ctx, NUM2INT(vyes));
|
446
470
|
|
447
471
|
return Qnil;
|
@@ -454,6 +478,8 @@ rb_s_gpgme_get_armor (VALUE dummy, VALUE vctx)
|
|
454
478
|
int yes;
|
455
479
|
|
456
480
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
481
|
+
if (!ctx)
|
482
|
+
rb_raise (rb_eArgError, "released ctx");
|
457
483
|
yes = gpgme_get_armor (ctx);
|
458
484
|
return INT2FIX(yes);
|
459
485
|
}
|
@@ -464,6 +490,8 @@ rb_s_gpgme_set_textmode (VALUE dummy, VALUE vctx, VALUE vyes)
|
|
464
490
|
gpgme_ctx_t ctx;
|
465
491
|
|
466
492
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
493
|
+
if (!ctx)
|
494
|
+
rb_raise (rb_eArgError, "released ctx");
|
467
495
|
gpgme_set_textmode (ctx, NUM2INT(vyes));
|
468
496
|
return Qnil;
|
469
497
|
}
|
@@ -475,6 +503,8 @@ rb_s_gpgme_get_textmode (VALUE dummy, VALUE vctx)
|
|
475
503
|
int yes;
|
476
504
|
|
477
505
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
506
|
+
if (!ctx)
|
507
|
+
rb_raise (rb_eArgError, "released ctx");
|
478
508
|
yes = gpgme_get_textmode (ctx);
|
479
509
|
return INT2FIX(yes);
|
480
510
|
}
|
@@ -485,6 +515,8 @@ rb_s_gpgme_set_include_certs (VALUE dummy, VALUE vctx, VALUE vnr_of_certs)
|
|
485
515
|
gpgme_ctx_t ctx;
|
486
516
|
|
487
517
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
518
|
+
if (!ctx)
|
519
|
+
rb_raise (rb_eArgError, "released ctx");
|
488
520
|
gpgme_set_include_certs (ctx, NUM2INT(vnr_of_certs));
|
489
521
|
return Qnil;
|
490
522
|
}
|
@@ -496,6 +528,8 @@ rb_s_gpgme_get_include_certs (VALUE dummy, VALUE vctx)
|
|
496
528
|
gpgme_error_t err;
|
497
529
|
|
498
530
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
531
|
+
if (!ctx)
|
532
|
+
rb_raise (rb_eArgError, "released ctx");
|
499
533
|
err = gpgme_get_include_certs (ctx);
|
500
534
|
return LONG2NUM(err);
|
501
535
|
}
|
@@ -507,6 +541,8 @@ rb_s_gpgme_set_keylist_mode (VALUE dummy, VALUE vctx, VALUE vmode)
|
|
507
541
|
gpgme_error_t err;
|
508
542
|
|
509
543
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
544
|
+
if (!ctx)
|
545
|
+
rb_raise (rb_eArgError, "released ctx");
|
510
546
|
err = gpgme_set_keylist_mode (ctx, NUM2INT(vmode));
|
511
547
|
return LONG2NUM(err);
|
512
548
|
}
|
@@ -518,6 +554,8 @@ rb_s_gpgme_get_keylist_mode (VALUE dummy, VALUE vctx)
|
|
518
554
|
int mode;
|
519
555
|
|
520
556
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
557
|
+
if (!ctx)
|
558
|
+
rb_raise (rb_eArgError, "released ctx");
|
521
559
|
mode = gpgme_get_keylist_mode (ctx);
|
522
560
|
return INT2FIX(mode);
|
523
561
|
}
|
@@ -553,6 +591,8 @@ rb_s_gpgme_set_passphrase_cb (VALUE dummy, VALUE vctx, VALUE vpassfunc,
|
|
553
591
|
rb_iv_set (vctx, "@passphrase_cb", vcb);
|
554
592
|
|
555
593
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
594
|
+
if (!ctx)
|
595
|
+
rb_raise (rb_eArgError, "released ctx");
|
556
596
|
gpgme_set_passphrase_cb (ctx, passphrase_cb, (void*)vcb);
|
557
597
|
return Qnil;
|
558
598
|
}
|
@@ -595,6 +635,8 @@ rb_s_gpgme_set_progress_cb (VALUE dummy, VALUE vctx, VALUE vprogfunc,
|
|
595
635
|
rb_iv_set (vctx, "@progress_cb", vcb);
|
596
636
|
|
597
637
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
638
|
+
if (!ctx)
|
639
|
+
rb_raise (rb_eArgError, "released ctx");
|
598
640
|
gpgme_set_progress_cb (ctx, progress_cb, (void*)vcb);
|
599
641
|
|
600
642
|
return Qnil;
|
@@ -617,6 +659,8 @@ rb_s_gpgme_set_locale (VALUE dummy, VALUE vctx, VALUE vcategory, VALUE vvalue)
|
|
617
659
|
gpgme_error_t err;
|
618
660
|
|
619
661
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
662
|
+
if (!ctx)
|
663
|
+
rb_raise (rb_eArgError, "released ctx");
|
620
664
|
|
621
665
|
err = gpgme_set_locale (ctx, NUM2INT(vcategory), StringValueCStr(vvalue));
|
622
666
|
return LONG2NUM(err);
|
@@ -632,6 +676,8 @@ rb_s_gpgme_op_keylist_start (VALUE dummy, VALUE vctx, VALUE vpattern,
|
|
632
676
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
633
677
|
|
634
678
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
679
|
+
if (!ctx)
|
680
|
+
rb_raise (rb_eArgError, "released ctx");
|
635
681
|
|
636
682
|
err = gpgme_op_keylist_start (ctx, NIL_P(vpattern) ? NULL :
|
637
683
|
StringValueCStr(vpattern),
|
@@ -652,6 +698,8 @@ rb_s_gpgme_op_keylist_ext_start (VALUE dummy, VALUE vctx, VALUE vpattern,
|
|
652
698
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
653
699
|
|
654
700
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
701
|
+
if (!ctx)
|
702
|
+
rb_raise (rb_eArgError, "released ctx");
|
655
703
|
|
656
704
|
if (!NIL_P(vpattern))
|
657
705
|
{
|
@@ -763,6 +811,8 @@ rb_s_gpgme_op_keylist_next (VALUE dummy, VALUE vctx, VALUE rkey)
|
|
763
811
|
CHECK_KEYLIST_IN_PROGRESS(vctx);
|
764
812
|
|
765
813
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
814
|
+
if (!ctx)
|
815
|
+
rb_raise (rb_eArgError, "released ctx");
|
766
816
|
|
767
817
|
err = gpgme_op_keylist_next (ctx, &key);
|
768
818
|
if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
|
@@ -783,6 +833,8 @@ rb_s_gpgme_op_keylist_end (VALUE dummy, VALUE vctx)
|
|
783
833
|
CHECK_KEYLIST_IN_PROGRESS(vctx);
|
784
834
|
|
785
835
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
836
|
+
if (!ctx)
|
837
|
+
rb_raise (rb_eArgError, "released ctx");
|
786
838
|
|
787
839
|
err = gpgme_op_keylist_end (ctx);
|
788
840
|
RESET_KEYLIST_IN_PROGRESS(vctx);
|
@@ -798,6 +850,8 @@ rb_s_gpgme_get_key (VALUE dummy, VALUE vctx, VALUE vfpr, VALUE rkey,
|
|
798
850
|
gpgme_key_t key;
|
799
851
|
|
800
852
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
853
|
+
if (!ctx)
|
854
|
+
rb_raise (rb_eArgError, "released ctx");
|
801
855
|
err = gpgme_get_key (ctx, StringValueCStr(vfpr), &key, NUM2INT(vsecret));
|
802
856
|
|
803
857
|
if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
|
@@ -820,6 +874,8 @@ rb_s_gpgme_op_genkey (VALUE dummy, VALUE vctx, VALUE vparms, VALUE vpubkey,
|
|
820
874
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
821
875
|
|
822
876
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
877
|
+
if (!ctx)
|
878
|
+
rb_raise (rb_eArgError, "released ctx");
|
823
879
|
if (!NIL_P(vpubkey))
|
824
880
|
UNWRAP_GPGME_DATA(vpubkey, pubkey);
|
825
881
|
if (!NIL_P(vseckey))
|
@@ -840,6 +896,8 @@ rb_s_gpgme_op_genkey_start (VALUE dummy, VALUE vctx, VALUE vparms,
|
|
840
896
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
841
897
|
|
842
898
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
899
|
+
if (!ctx)
|
900
|
+
rb_raise (rb_eArgError, "released ctx");
|
843
901
|
if (!NIL_P(vpubkey))
|
844
902
|
UNWRAP_GPGME_DATA(vpubkey, pubkey);
|
845
903
|
if (!NIL_P(vseckey))
|
@@ -860,6 +918,8 @@ rb_s_gpgme_op_export (VALUE dummy, VALUE vctx, VALUE vpattern, VALUE vreserved,
|
|
860
918
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
861
919
|
|
862
920
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
921
|
+
if (!ctx)
|
922
|
+
rb_raise (rb_eArgError, "released ctx");
|
863
923
|
UNWRAP_GPGME_DATA(vkeydata, keydata);
|
864
924
|
|
865
925
|
err = gpgme_op_export (ctx, StringValueCStr(vpattern), NUM2UINT(vreserved),
|
@@ -878,6 +938,8 @@ rb_s_gpgme_op_export_start (VALUE dummy, VALUE vctx, VALUE vpattern,
|
|
878
938
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
879
939
|
|
880
940
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
941
|
+
if (!ctx)
|
942
|
+
rb_raise (rb_eArgError, "released ctx");
|
881
943
|
UNWRAP_GPGME_DATA(vkeydata, keydata);
|
882
944
|
|
883
945
|
err = gpgme_op_export_start (ctx, StringValueCStr(vpattern),
|
@@ -895,6 +957,8 @@ rb_s_gpgme_op_import (VALUE dummy, VALUE vctx, VALUE vkeydata)
|
|
895
957
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
896
958
|
|
897
959
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
960
|
+
if (!ctx)
|
961
|
+
rb_raise (rb_eArgError, "released ctx");
|
898
962
|
UNWRAP_GPGME_DATA(vkeydata, keydata);
|
899
963
|
|
900
964
|
err = gpgme_op_import (ctx, keydata);
|
@@ -911,6 +975,8 @@ rb_s_gpgme_op_import_start (VALUE dummy, VALUE vctx, VALUE vkeydata)
|
|
911
975
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
912
976
|
|
913
977
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
978
|
+
if (!ctx)
|
979
|
+
rb_raise (rb_eArgError, "released ctx");
|
914
980
|
UNWRAP_GPGME_DATA(vkeydata, keydata);
|
915
981
|
|
916
982
|
err = gpgme_op_import_start (ctx, keydata);
|
@@ -926,6 +992,8 @@ rb_s_gpgme_op_import_result (VALUE dummy, VALUE vctx)
|
|
926
992
|
VALUE vresult, vimports;
|
927
993
|
|
928
994
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
995
|
+
if (!ctx)
|
996
|
+
rb_raise (rb_eArgError, "released ctx");
|
929
997
|
|
930
998
|
result = gpgme_op_import_result (ctx);
|
931
999
|
vresult = rb_class_new_instance (0, NULL, cImportResult);
|
@@ -967,6 +1035,8 @@ rb_s_gpgme_op_delete (VALUE dummy, VALUE vctx, VALUE vkey, VALUE vallow_secret)
|
|
967
1035
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
968
1036
|
|
969
1037
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1038
|
+
if (!ctx)
|
1039
|
+
rb_raise (rb_eArgError, "released ctx");
|
970
1040
|
UNWRAP_GPGME_KEY(vkey, key);
|
971
1041
|
|
972
1042
|
err = gpgme_op_delete (ctx, key, NUM2INT(vallow_secret));
|
@@ -984,6 +1054,8 @@ rb_s_gpgme_op_delete_start (VALUE dummy, VALUE vctx, VALUE vkey,
|
|
984
1054
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
985
1055
|
|
986
1056
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1057
|
+
if (!ctx)
|
1058
|
+
rb_raise (rb_eArgError, "released ctx");
|
987
1059
|
UNWRAP_GPGME_KEY(vkey, key);
|
988
1060
|
|
989
1061
|
err = gpgme_op_delete_start (ctx, key, NUM2INT(vallow_secret));
|
@@ -1010,13 +1082,14 @@ rb_s_gpgme_op_edit (VALUE dummy, VALUE vctx, VALUE vkey,
|
|
1010
1082
|
gpgme_ctx_t ctx;
|
1011
1083
|
gpgme_key_t key;
|
1012
1084
|
gpgme_data_t out = NULL;
|
1013
|
-
void *hook_value = NULL;
|
1014
1085
|
VALUE vcb;
|
1015
1086
|
gpgme_error_t err;
|
1016
1087
|
|
1017
1088
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1018
1089
|
|
1019
1090
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1091
|
+
if (!ctx)
|
1092
|
+
rb_raise (rb_eArgError, "released ctx");
|
1020
1093
|
UNWRAP_GPGME_KEY(vkey, key);
|
1021
1094
|
if (!NIL_P(vout))
|
1022
1095
|
UNWRAP_GPGME_DATA(vout, out);
|
@@ -1038,13 +1111,14 @@ rb_s_gpgme_op_edit_start (VALUE dummy, VALUE vctx, VALUE vkey,
|
|
1038
1111
|
gpgme_ctx_t ctx;
|
1039
1112
|
gpgme_key_t key;
|
1040
1113
|
gpgme_data_t out = NULL;
|
1041
|
-
void *hook_value = NULL;
|
1042
1114
|
VALUE vcb;
|
1043
1115
|
gpgme_error_t err;
|
1044
1116
|
|
1045
1117
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1046
1118
|
|
1047
1119
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1120
|
+
if (!ctx)
|
1121
|
+
rb_raise (rb_eArgError, "released ctx");
|
1048
1122
|
UNWRAP_GPGME_KEY(vkey, key);
|
1049
1123
|
if (!NIL_P(vout))
|
1050
1124
|
UNWRAP_GPGME_DATA(vout, out);
|
@@ -1066,13 +1140,14 @@ rb_s_gpgme_op_card_edit (VALUE dummy, VALUE vctx, VALUE vkey,
|
|
1066
1140
|
gpgme_ctx_t ctx;
|
1067
1141
|
gpgme_key_t key;
|
1068
1142
|
gpgme_data_t out = NULL;
|
1069
|
-
void *hook_value = NULL;
|
1070
1143
|
VALUE vcb;
|
1071
1144
|
gpgme_error_t err;
|
1072
1145
|
|
1073
1146
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1074
1147
|
|
1075
1148
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1149
|
+
if (!ctx)
|
1150
|
+
rb_raise (rb_eArgError, "released ctx");
|
1076
1151
|
UNWRAP_GPGME_KEY(vkey, key);
|
1077
1152
|
if (!NIL_P(vout))
|
1078
1153
|
UNWRAP_GPGME_DATA(vout, out);
|
@@ -1094,13 +1169,14 @@ rb_s_gpgme_op_card_edit_start (VALUE dummy, VALUE vctx, VALUE vkey,
|
|
1094
1169
|
gpgme_ctx_t ctx;
|
1095
1170
|
gpgme_key_t key;
|
1096
1171
|
gpgme_data_t out = NULL;
|
1097
|
-
void *hook_value = NULL;
|
1098
1172
|
VALUE vcb;
|
1099
1173
|
gpgme_error_t err;
|
1100
1174
|
|
1101
1175
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1102
1176
|
|
1103
1177
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1178
|
+
if (!ctx)
|
1179
|
+
rb_raise (rb_eArgError, "released ctx");
|
1104
1180
|
UNWRAP_GPGME_KEY(vkey, key);
|
1105
1181
|
if (!NIL_P(vout))
|
1106
1182
|
UNWRAP_GPGME_DATA(vout, out);
|
@@ -1125,6 +1201,8 @@ rb_s_gpgme_op_trustlist_start (VALUE dummy, VALUE vctx, VALUE vpattern,
|
|
1125
1201
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1126
1202
|
|
1127
1203
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1204
|
+
if (!ctx)
|
1205
|
+
rb_raise (rb_eArgError, "released ctx");
|
1128
1206
|
err = gpgme_op_trustlist_start (ctx, StringValueCStr(vpattern),
|
1129
1207
|
NUM2INT(vmax_level));
|
1130
1208
|
return LONG2NUM(err);
|
@@ -1141,6 +1219,8 @@ rb_s_gpgme_op_trustlist_next (VALUE dummy, VALUE vctx, VALUE ritem)
|
|
1141
1219
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1142
1220
|
|
1143
1221
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1222
|
+
if (!ctx)
|
1223
|
+
rb_raise (rb_eArgError, "released ctx");
|
1144
1224
|
|
1145
1225
|
err = gpgme_op_trustlist_next (ctx, &item);
|
1146
1226
|
if (gpgme_err_code(err) == GPG_ERR_NO_ERROR)
|
@@ -1168,6 +1248,8 @@ rb_s_gpgme_op_trustlist_end (VALUE dummy, VALUE vctx)
|
|
1168
1248
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1169
1249
|
|
1170
1250
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1251
|
+
if (!ctx)
|
1252
|
+
rb_raise (rb_eArgError, "released ctx");
|
1171
1253
|
|
1172
1254
|
err = gpgme_op_trustlist_end (ctx);
|
1173
1255
|
return LONG2NUM(err);
|
@@ -1183,6 +1265,8 @@ rb_s_gpgme_op_decrypt (VALUE dummy, VALUE vctx, VALUE vcipher, VALUE vplain)
|
|
1183
1265
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1184
1266
|
|
1185
1267
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1268
|
+
if (!ctx)
|
1269
|
+
rb_raise (rb_eArgError, "released ctx");
|
1186
1270
|
UNWRAP_GPGME_DATA(vcipher, cipher);
|
1187
1271
|
UNWRAP_GPGME_DATA(vplain, plain);
|
1188
1272
|
|
@@ -1201,6 +1285,8 @@ rb_s_gpgme_op_decrypt_start (VALUE dummy, VALUE vctx, VALUE vcipher,
|
|
1201
1285
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1202
1286
|
|
1203
1287
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1288
|
+
if (!ctx)
|
1289
|
+
rb_raise (rb_eArgError, "released ctx");
|
1204
1290
|
UNWRAP_GPGME_DATA(vcipher, cipher);
|
1205
1291
|
UNWRAP_GPGME_DATA(vplain, plain);
|
1206
1292
|
|
@@ -1216,6 +1302,8 @@ rb_s_gpgme_op_decrypt_result (VALUE dummy, VALUE vctx)
|
|
1216
1302
|
VALUE vresult;
|
1217
1303
|
|
1218
1304
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1305
|
+
if (!ctx)
|
1306
|
+
rb_raise (rb_eArgError, "released ctx");
|
1219
1307
|
|
1220
1308
|
result = gpgme_op_decrypt_result (ctx);
|
1221
1309
|
vresult = rb_class_new_instance (0, NULL, cDecryptResult);
|
@@ -1237,6 +1325,8 @@ rb_s_gpgme_op_verify (VALUE dummy, VALUE vctx, VALUE vsig, VALUE vsigned_text,
|
|
1237
1325
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1238
1326
|
|
1239
1327
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1328
|
+
if (!ctx)
|
1329
|
+
rb_raise (rb_eArgError, "released ctx");
|
1240
1330
|
UNWRAP_GPGME_DATA(vsig, sig);
|
1241
1331
|
if (!NIL_P(vsigned_text))
|
1242
1332
|
UNWRAP_GPGME_DATA(vsigned_text, signed_text);
|
@@ -1258,6 +1348,8 @@ rb_s_gpgme_op_verify_start (VALUE dummy, VALUE vctx, VALUE vsig,
|
|
1258
1348
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1259
1349
|
|
1260
1350
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1351
|
+
if (!ctx)
|
1352
|
+
rb_raise (rb_eArgError, "released ctx");
|
1261
1353
|
UNWRAP_GPGME_DATA(vsig, sig);
|
1262
1354
|
if (!NIL_P(vsigned_text))
|
1263
1355
|
UNWRAP_GPGME_DATA(vsigned_text, signed_text);
|
@@ -1277,6 +1369,8 @@ rb_s_gpgme_op_verify_result (VALUE dummy, VALUE vctx)
|
|
1277
1369
|
VALUE vverify_result, vsignatures = rb_ary_new ();
|
1278
1370
|
|
1279
1371
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1372
|
+
if (!ctx)
|
1373
|
+
rb_raise (rb_eArgError, "released ctx");
|
1280
1374
|
|
1281
1375
|
verify_result = gpgme_op_verify_result (ctx);
|
1282
1376
|
vverify_result = rb_class_new_instance(0, NULL, cVerifyResult);
|
@@ -1329,6 +1423,8 @@ rb_s_gpgme_op_decrypt_verify (VALUE dummy, VALUE vctx, VALUE vcipher,
|
|
1329
1423
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1330
1424
|
|
1331
1425
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1426
|
+
if (!ctx)
|
1427
|
+
rb_raise (rb_eArgError, "released ctx");
|
1332
1428
|
UNWRAP_GPGME_DATA(vcipher, cipher);
|
1333
1429
|
UNWRAP_GPGME_DATA(vplain, plain);
|
1334
1430
|
|
@@ -1347,6 +1443,8 @@ rb_s_gpgme_op_decrypt_verify_start (VALUE dummy, VALUE vctx, VALUE vcipher,
|
|
1347
1443
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1348
1444
|
|
1349
1445
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1446
|
+
if (!ctx)
|
1447
|
+
rb_raise (rb_eArgError, "released ctx");
|
1350
1448
|
UNWRAP_GPGME_DATA(vcipher, cipher);
|
1351
1449
|
UNWRAP_GPGME_DATA(vplain, plain);
|
1352
1450
|
|
@@ -1360,6 +1458,8 @@ rb_s_gpgme_signers_clear (VALUE dummy, VALUE vctx)
|
|
1360
1458
|
gpgme_ctx_t ctx;
|
1361
1459
|
|
1362
1460
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1461
|
+
if (!ctx)
|
1462
|
+
rb_raise (rb_eArgError, "released ctx");
|
1363
1463
|
gpgme_signers_clear (ctx);
|
1364
1464
|
return Qnil;
|
1365
1465
|
}
|
@@ -1372,6 +1472,8 @@ rb_s_gpgme_signers_add (VALUE dummy, VALUE vctx, VALUE vkey)
|
|
1372
1472
|
gpgme_error_t err;
|
1373
1473
|
|
1374
1474
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1475
|
+
if (!ctx)
|
1476
|
+
rb_raise (rb_eArgError, "released ctx");
|
1375
1477
|
UNWRAP_GPGME_KEY(vkey, key);
|
1376
1478
|
|
1377
1479
|
err = gpgme_signers_add (ctx, key);
|
@@ -1385,6 +1487,8 @@ rb_s_gpgme_signers_enum (VALUE dummy, VALUE vctx, VALUE vseq)
|
|
1385
1487
|
gpgme_key_t key;
|
1386
1488
|
|
1387
1489
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1490
|
+
if (!ctx)
|
1491
|
+
rb_raise (rb_eArgError, "released ctx");
|
1388
1492
|
|
1389
1493
|
key = gpgme_signers_enum (ctx, NUM2INT(vseq));
|
1390
1494
|
if (!key)
|
@@ -1403,6 +1507,8 @@ rb_s_gpgme_op_sign (VALUE dummy, VALUE vctx, VALUE vplain, VALUE vsig,
|
|
1403
1507
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1404
1508
|
|
1405
1509
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1510
|
+
if (!ctx)
|
1511
|
+
rb_raise (rb_eArgError, "released ctx");
|
1406
1512
|
UNWRAP_GPGME_DATA(vplain, plain);
|
1407
1513
|
UNWRAP_GPGME_DATA(vsig, sig);
|
1408
1514
|
|
@@ -1421,6 +1527,8 @@ rb_s_gpgme_op_sign_start (VALUE dummy, VALUE vctx, VALUE vplain, VALUE vsig,
|
|
1421
1527
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1422
1528
|
|
1423
1529
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1530
|
+
if (!ctx)
|
1531
|
+
rb_raise (rb_eArgError, "released ctx");
|
1424
1532
|
UNWRAP_GPGME_DATA(vplain, plain);
|
1425
1533
|
UNWRAP_GPGME_DATA(vsig, sig);
|
1426
1534
|
|
@@ -1438,6 +1546,8 @@ rb_s_gpgme_op_sign_result (VALUE dummy, VALUE vctx)
|
|
1438
1546
|
VALUE vresult, vinvalid_signers, vsignatures;
|
1439
1547
|
|
1440
1548
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1549
|
+
if (!ctx)
|
1550
|
+
rb_raise (rb_eArgError, "released ctx");
|
1441
1551
|
|
1442
1552
|
result = gpgme_op_sign_result (ctx);
|
1443
1553
|
vresult = rb_class_new_instance (0, NULL, cSignResult);
|
@@ -1486,6 +1596,8 @@ rb_s_gpgme_op_encrypt (VALUE dummy, VALUE vctx, VALUE vrecp, VALUE vflags,
|
|
1486
1596
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1487
1597
|
|
1488
1598
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1599
|
+
if (!ctx)
|
1600
|
+
rb_raise (rb_eArgError, "released ctx");
|
1489
1601
|
/* If RECP is `NULL', symmetric rather than public key encryption is
|
1490
1602
|
performed. */
|
1491
1603
|
if (!NIL_P(vrecp))
|
@@ -1517,6 +1629,8 @@ rb_s_gpgme_op_encrypt_start (VALUE dummy, VALUE vctx, VALUE vrecp,
|
|
1517
1629
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1518
1630
|
|
1519
1631
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1632
|
+
if (!ctx)
|
1633
|
+
rb_raise (rb_eArgError, "released ctx");
|
1520
1634
|
/* If RECP is `NULL', symmetric rather than public key encryption is
|
1521
1635
|
performed. */
|
1522
1636
|
if (!NIL_P(vrecp))
|
@@ -1547,6 +1661,8 @@ rb_s_gpgme_op_encrypt_result (VALUE dummy, VALUE vctx)
|
|
1547
1661
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1548
1662
|
|
1549
1663
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1664
|
+
if (!ctx)
|
1665
|
+
rb_raise (rb_eArgError, "released ctx");
|
1550
1666
|
|
1551
1667
|
result = gpgme_op_encrypt_result (ctx);
|
1552
1668
|
vresult = rb_class_new_instance (0, NULL, cEncryptResult);
|
@@ -1576,6 +1692,8 @@ rb_s_gpgme_op_encrypt_sign (VALUE dummy, VALUE vctx, VALUE vrecp, VALUE vflags,
|
|
1576
1692
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1577
1693
|
|
1578
1694
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1695
|
+
if (!ctx)
|
1696
|
+
rb_raise (rb_eArgError, "released ctx");
|
1579
1697
|
/* If RECP is `NULL', symmetric rather than public key encryption is
|
1580
1698
|
performed. */
|
1581
1699
|
if (!NIL_P(vrecp))
|
@@ -1607,6 +1725,8 @@ rb_s_gpgme_op_encrypt_sign_start (VALUE dummy, VALUE vctx, VALUE vrecp,
|
|
1607
1725
|
CHECK_KEYLIST_NOT_IN_PROGRESS(vctx);
|
1608
1726
|
|
1609
1727
|
UNWRAP_GPGME_CTX(vctx, ctx);
|
1728
|
+
if (!ctx)
|
1729
|
+
rb_raise (rb_eArgError, "released ctx");
|
1610
1730
|
/* If RECP is `NULL', symmetric rather than public key encryption is
|
1611
1731
|
performed. */
|
1612
1732
|
if (!NIL_P(vrecp))
|
@@ -1636,7 +1756,11 @@ rb_s_gpgme_wait (VALUE dummy, VALUE vctx, VALUE rstatus, VALUE vhang)
|
|
1636
1756
|
/* The CTX argument can be `NULL'. In that case, `gpgme_wait' waits
|
1637
1757
|
for any context to complete its operation. */
|
1638
1758
|
if (!NIL_P(vctx))
|
1639
|
-
|
1759
|
+
{
|
1760
|
+
UNWRAP_GPGME_CTX(vctx, ctx);
|
1761
|
+
if (!ctx)
|
1762
|
+
rb_raise (rb_eArgError, "released ctx");
|
1763
|
+
}
|
1640
1764
|
|
1641
1765
|
ret = gpgme_wait (ctx, &status, NUM2INT(vhang));
|
1642
1766
|
if (ret)
|
@@ -1742,6 +1866,8 @@ Init_gpgme_n (void)
|
|
1742
1866
|
/* Creating Contexts */
|
1743
1867
|
rb_define_module_function (mGPGME, "gpgme_new",
|
1744
1868
|
rb_s_gpgme_new, 1);
|
1869
|
+
rb_define_module_function (mGPGME, "gpgme_release",
|
1870
|
+
rb_s_gpgme_release, 1);
|
1745
1871
|
|
1746
1872
|
/* Context Attributes */
|
1747
1873
|
rb_define_module_function (mGPGME, "gpgme_set_protocol",
|
@@ -1809,9 +1935,9 @@ Init_gpgme_n (void)
|
|
1809
1935
|
rb_define_module_function (mGPGME, "gpgme_op_edit_start",
|
1810
1936
|
rb_s_gpgme_op_edit_start, 5);
|
1811
1937
|
rb_define_module_function (mGPGME, "gpgme_op_card_edit",
|
1812
|
-
|
1938
|
+
rb_s_gpgme_op_card_edit, 5);
|
1813
1939
|
rb_define_module_function (mGPGME, "gpgme_op_card_edit_start",
|
1814
|
-
|
1940
|
+
rb_s_gpgme_op_card_edit_start, 5);
|
1815
1941
|
|
1816
1942
|
/* Trust Item Management */
|
1817
1943
|
rb_define_module_function (mGPGME, "gpgme_op_trustlist_start",
|
data/lib/gpgme.rb
CHANGED
@@ -123,29 +123,30 @@ def GPGME.decrypt(cipher, *args_options)
|
|
123
123
|
args, options = split_args(args_options)
|
124
124
|
plain = args[0]
|
125
125
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
126
|
+
GPGME::Ctx.new(options) do |ctx|
|
127
|
+
cipher_data = input_data(cipher)
|
128
|
+
plain_data = output_data(plain)
|
129
|
+
begin
|
130
|
+
ctx.decrypt_verify(cipher_data, plain_data)
|
131
|
+
rescue GPGME::Error::UnsupportedAlgorithm => exc
|
132
|
+
exc.algorithm = ctx.decrypt_result.unsupported_algorithm
|
133
|
+
raise exc
|
134
|
+
rescue GPGME::Error::WrongKeyUsage => exc
|
135
|
+
exc.key_usage = ctx.decrypt_result.wrong_key_usage
|
136
|
+
raise exc
|
137
|
+
end
|
138
|
+
|
139
|
+
verify_result = ctx.verify_result
|
140
|
+
if verify_result && block_given?
|
141
|
+
verify_result.signatures.each do |signature|
|
142
|
+
yield signature
|
143
|
+
end
|
143
144
|
end
|
144
|
-
end
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
146
|
+
unless plain
|
147
|
+
plain_data.seek(0, IO::SEEK_SET)
|
148
|
+
plain_data.read
|
149
|
+
end
|
149
150
|
end
|
150
151
|
end
|
151
152
|
|
@@ -181,22 +182,23 @@ def GPGME.verify(sig, *args_options) # :yields: signature
|
|
181
182
|
args, options = split_args(args_options)
|
182
183
|
signed_text, plain = args
|
183
184
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
185
|
+
GPGME::Ctx.new(options) do |ctx|
|
186
|
+
sig_data = input_data(sig)
|
187
|
+
if signed_text
|
188
|
+
signed_text_data = input_data(signed_text)
|
189
|
+
plain_data = nil
|
190
|
+
else
|
191
|
+
signed_text_data = nil
|
192
|
+
plain_data = output_data(plain)
|
193
|
+
end
|
194
|
+
ctx.verify(sig_data, signed_text_data, plain_data)
|
195
|
+
ctx.verify_result.signatures.each do |signature|
|
196
|
+
yield signature
|
197
|
+
end
|
198
|
+
if !signed_text && !plain
|
199
|
+
plain_data.seek(0, IO::SEEK_SET)
|
200
|
+
plain_data.read
|
201
|
+
end
|
200
202
|
end
|
201
203
|
end
|
202
204
|
|
@@ -234,21 +236,22 @@ def GPGME.sign(plain, *args_options)
|
|
234
236
|
args, options = split_args(args_options)
|
235
237
|
sig = args[0]
|
236
238
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
239
|
+
GPGME::Ctx.new(options) do |ctx|
|
240
|
+
ctx.add_signer(*resolve_keys(options[:signers], true, [:sign])) if options[:signers]
|
241
|
+
mode = options[:mode] || GPGME::SIG_MODE_NORMAL
|
242
|
+
plain_data = input_data(plain)
|
243
|
+
sig_data = output_data(sig)
|
244
|
+
begin
|
245
|
+
ctx.sign(plain_data, sig_data, mode)
|
246
|
+
rescue GPGME::Error::UnusableSecretKey => exc
|
247
|
+
exc.keys = ctx.sign_result.invalid_signers
|
248
|
+
raise exc
|
249
|
+
end
|
248
250
|
|
249
|
-
|
250
|
-
|
251
|
-
|
251
|
+
unless sig
|
252
|
+
sig_data.seek(0, IO::SEEK_SET)
|
253
|
+
sig_data.read
|
254
|
+
end
|
252
255
|
end
|
253
256
|
end
|
254
257
|
|
@@ -353,35 +356,36 @@ def GPGME.encrypt(recipients, plain, *args_options)
|
|
353
356
|
raise ArgumentError, 'wrong number of arguments' if args_options.length > 3
|
354
357
|
args, options = split_args(args_options)
|
355
358
|
cipher = args[0]
|
356
|
-
recipient_keys = recipients ? resolve_keys(recipients, false) : nil
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
end
|
366
|
-
if options[:sign]
|
367
|
-
if options[:signers]
|
368
|
-
ctx.add_signer(*resolve_keys(options[:signers], true))
|
359
|
+
recipient_keys = recipients ? resolve_keys(recipients, false, [:encrypt]) : nil
|
360
|
+
|
361
|
+
GPGME::Ctx.new(options) do |ctx|
|
362
|
+
plain_data = input_data(plain)
|
363
|
+
cipher_data = output_data(cipher)
|
364
|
+
begin
|
365
|
+
flags = 0
|
366
|
+
if options[:always_trust]
|
367
|
+
flags |= GPGME::ENCRYPT_ALWAYS_TRUST
|
369
368
|
end
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
369
|
+
if options[:sign]
|
370
|
+
if options[:signers]
|
371
|
+
ctx.add_signer(*resolve_keys(options[:signers], true, [:sign]))
|
372
|
+
end
|
373
|
+
ctx.encrypt_sign(recipient_keys, plain_data, cipher_data, flags)
|
374
|
+
else
|
375
|
+
ctx.encrypt(recipient_keys, plain_data, cipher_data, flags)
|
376
|
+
end
|
377
|
+
rescue GPGME::Error::UnusablePublicKey => exc
|
378
|
+
exc.keys = ctx.encrypt_result.invalid_recipients
|
379
|
+
raise exc
|
380
|
+
rescue GPGME::Error::UnusableSecretKey => exc
|
381
|
+
exc.keys = ctx.sign_result.invalid_signers
|
382
|
+
raise exc
|
383
|
+
end
|
381
384
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
+
unless cipher
|
386
|
+
cipher_data.seek(0, IO::SEEK_SET)
|
387
|
+
cipher_data.read
|
388
|
+
end
|
385
389
|
end
|
386
390
|
end
|
387
391
|
|
@@ -408,13 +412,14 @@ def GPGME.list_keys(*args_options) # :yields: key
|
|
408
412
|
raise ArgumentError, 'wrong number of arguments' if args_options.length > 3
|
409
413
|
args, options = split_args(args_options)
|
410
414
|
pattern, secret_only = args
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
+
GPGME::Ctx.new do |ctx|
|
416
|
+
if block_given?
|
417
|
+
ctx.each_key(pattern, secret_only || false) do |key|
|
418
|
+
yield key
|
419
|
+
end
|
420
|
+
else
|
421
|
+
ctx.keys(pattern, secret_only || false)
|
415
422
|
end
|
416
|
-
else
|
417
|
-
ctx.keys(pattern, secret_only || false)
|
418
423
|
end
|
419
424
|
end
|
420
425
|
|
@@ -445,12 +450,13 @@ def GPGME.export(*args_options)
|
|
445
450
|
args, options = split_args(args_options)
|
446
451
|
pattern, key = args[0]
|
447
452
|
key_data = output_data(key)
|
448
|
-
|
449
|
-
|
453
|
+
GPGME::Ctx.new(options) do |ctx|
|
454
|
+
ctx.export_keys(pattern, key_data)
|
450
455
|
|
451
|
-
|
452
|
-
|
453
|
-
|
456
|
+
unless key
|
457
|
+
key_data.seek(0, IO::SEEK_SET)
|
458
|
+
key_data.read
|
459
|
+
end
|
454
460
|
end
|
455
461
|
end
|
456
462
|
|
@@ -478,9 +484,10 @@ def GPGME.import(*args_options)
|
|
478
484
|
args, options = split_args(args_options)
|
479
485
|
key = args[0]
|
480
486
|
key_data = input_data(key)
|
481
|
-
|
482
|
-
|
483
|
-
|
487
|
+
GPGME::Ctx.new(options) do |ctx|
|
488
|
+
ctx.import_keys(key_data)
|
489
|
+
ctx.import_result
|
490
|
+
end
|
484
491
|
end
|
485
492
|
|
486
493
|
module GPGME
|
@@ -499,14 +506,18 @@ module GPGME
|
|
499
506
|
end
|
500
507
|
module_function :split_args
|
501
508
|
|
502
|
-
def resolve_keys(keys_or_names, secret_only)
|
503
|
-
ctx = GPGME::Ctx.new
|
509
|
+
def resolve_keys(keys_or_names, secret_only, purposes = Array.new)
|
504
510
|
keys = Array.new
|
505
511
|
keys_or_names.each do |key_or_name|
|
506
512
|
if key_or_name.kind_of? Key
|
507
513
|
keys << key_or_name
|
508
514
|
elsif key_or_name.kind_of? String
|
509
|
-
|
515
|
+
GPGME::Ctx.new do |ctx|
|
516
|
+
key = ctx.keys(key_or_name, secret_only).find {|k|
|
517
|
+
k.usable_for?(purposes)
|
518
|
+
}
|
519
|
+
keys << key if key
|
520
|
+
end
|
510
521
|
end
|
511
522
|
end
|
512
523
|
keys
|
@@ -904,7 +915,15 @@ module GPGME
|
|
904
915
|
options[:progress_callback_value])
|
905
916
|
end
|
906
917
|
end
|
907
|
-
|
918
|
+
if block_given?
|
919
|
+
begin
|
920
|
+
yield ctx
|
921
|
+
ensure
|
922
|
+
GPGME::gpgme_release(ctx)
|
923
|
+
end
|
924
|
+
else
|
925
|
+
ctx
|
926
|
+
end
|
908
927
|
end
|
909
928
|
|
910
929
|
# Set the <i>protocol</i> used within this context.
|
@@ -1246,6 +1265,14 @@ keylist_mode=#{KEYLIST_MODE_NAMES[keylist_mode]}>"
|
|
1246
1265
|
caps
|
1247
1266
|
end
|
1248
1267
|
|
1268
|
+
def usable_for?(purposes)
|
1269
|
+
unless purposes.kind_of? Array
|
1270
|
+
purposes = [purposes]
|
1271
|
+
end
|
1272
|
+
return false if [:revoked, :expired, :disabled, :invalid].include? trust
|
1273
|
+
return (purposes - capability).empty?
|
1274
|
+
end
|
1275
|
+
|
1249
1276
|
def secret?
|
1250
1277
|
@secret == 1
|
1251
1278
|
end
|
@@ -1306,6 +1333,14 @@ capability=%s, subkeys=%s, uids=%s>",
|
|
1306
1333
|
caps
|
1307
1334
|
end
|
1308
1335
|
|
1336
|
+
def usable_for?(purposes)
|
1337
|
+
unless purposes.kind_of? Array
|
1338
|
+
purposes = [purposes]
|
1339
|
+
end
|
1340
|
+
return false if [:revoked, :expired, :disabled, :invalid].include? trust
|
1341
|
+
return (purposes - capability).empty?
|
1342
|
+
end
|
1343
|
+
|
1309
1344
|
def secret?
|
1310
1345
|
@secret == 1
|
1311
1346
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-gpgme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daiki Ueno
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-08 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- MANIFEST
|
28
28
|
- Makefile
|
29
29
|
- README
|
30
|
+
- THANKS
|
30
31
|
- extconf.rb
|
31
32
|
- gpgme_n.c
|
32
33
|
- lib/gpgme.rb
|