summaryrefslogtreecommitdiff
path: root/doc/gpgme.info-1
blob: bc822a403882feda9501197772a639eb00465318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
This is gpgme.info, produced by makeinfo version 5.2 from gpgme.texi.

Copyright © 2002–2008, 2010, 2012–2016 g10 Code GmbH.

     Permission is granted to copy, distribute and/or modify this
     document under the terms of the GNU General Public License as
     published by the Free Software Foundation; either version 3 of the
     License, or (at your option) any later version.  The text of the
     license can be found in the section entitled “Copying”.

   This document is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
INFO-DIR-SECTION GNU Libraries
START-INFO-DIR-ENTRY
* GPGME: (gpgme).          Adding support for cryptography to your program.
END-INFO-DIR-ENTRY

   This file documents the GPGME library.

   This is Edition 1.8.0-beta50, last updated 16 November 2016, of ‘The
‘GnuPG Made Easy’ Reference Manual’, for Version 1.8.0-beta50.

   Copyright © 2002–2008, 2010, 2012–2016 g10 Code GmbH.

     Permission is granted to copy, distribute and/or modify this
     document under the terms of the GNU General Public License as
     published by the Free Software Foundation; either version 3 of the
     License, or (at your option) any later version.  The text of the
     license can be found in the section entitled “Copying”.

   This document is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.


File: gpgme.info,  Node: Top,  Next: Introduction,  Up: (dir)

Main Menu
*********

This is Edition 1.8.0-beta50, last updated 16 November 2016, of ‘The
‘GnuPG Made Easy’ Reference Manual’, for Version 1.8.0-beta50 of the
GPGME library.

* Menu:

* Introduction::                  How to use this manual.
* Preparation::                   What you should do before using the library.
* Protocols and Engines::         Supported crypto protocols.
* Algorithms::                    Supported algorithms.
* Error Handling::                Error numbers and their meanings.
* Exchanging Data::               Passing data to and from GPGME.
* Contexts::                      Handling GPGME contexts.

Appendices

* UI Server Protocol::            The GnuPG UI Server Protocol.
* Debugging::                     How to solve problems.
* Deprecated Functions::          Documentation of deprecated functions.

* Library Copying::               The GNU Lesser General Public License says
                                  how you can copy and share ‘GnuPG Made Easy’.
* Copying::                       The GNU General Public License says how you
                                  can copy and share this manual.

Indices

* Concept Index::                 Index of concepts and programs.
* Function and Data Index::       Index of functions, variables and data types.

 — The Detailed Node Listing —

Introduction

* Getting Started::               Purpose of the manual, and how to use it.
* Features::                      Reasons to install and use GPGME.
* Overview::                      Basic architecture of the GPGME library.

Preparation

* Header::                        What header file you need to include.
* Building the Source::           Compiler options to be used.
* Largefile Support (LFS)::       How to use GPGME with LFS.
* Using Automake::                Compiler options to be used the easy way.
* Using Libtool::                 Avoiding compiler options entirely.
* Library Version Check::         Getting and verifying the library version.
* Signal Handling::               How GPGME affects signal handling.
* Multi-Threading::               How GPGME can be used in an MT environment.

Protocols and Engines

* Engine Version Check::          Verifying the engine version.
* Engine Information::            Obtaining more information about the engines.
* Engine Configuration::          Changing the engine configuration.
* OpenPGP::                       Support for the OpenPGP protocol.
* Cryptographic Message Syntax::  Support for the CMS.

Algorithms

* Public Key Algorithms::         A list of all public key algorithms.
* Hash Algorithms::               A list of all hash algorithms.

Error Handling

* Error Values::                  The error value and what it means.
* Error Codes::                   A list of important error codes.
* Error Sources::                 A list of important error sources.
* Error Strings::                 How to get a descriptive string from a value.

Exchanging Data

* Creating Data Buffers::         Creating new data buffers.
* Destroying Data Buffers::       Releasing data buffers.
* Manipulating Data Buffers::     Operations on data buffers.

Creating Data Buffers

* Memory Based Data Buffers::     Creating memory based data buffers.
* File Based Data Buffers::       Creating file based data buffers.
* Callback Based Data Buffers::   Creating callback based data buffers.

Manipulating Data Buffers

* Data Buffer I/O Operations::    I/O operations on data buffers.
* Data Buffer Meta-Data::         Meta-data manipulation of data buffers.
* Data Buffer Convenience::       Convenience function for data buffers.

Contexts

* Creating Contexts::             Creating new GPGME contexts.
* Destroying Contexts::           Releasing GPGME contexts.
* Result Management::             Managing the result of crypto operations.
* Context Attributes::            Setting properties of a context.
* Key Management::                Managing keys with GPGME.
* Trust Item Management::         Managing trust items with GPGME.
* Crypto Operations::             Using a context for cryptography.
* Miscellaneous::                 Miscellaneous operations.
* Run Control::                   Controlling how operations are run.

Context Attributes

* Protocol Selection::            Selecting the protocol used by a context.
* Crypto Engine::                 Configuring the crypto engine.
* Setting the Sender::            How to tell the engine the sender.
* ASCII Armor::                   Requesting ASCII armored output.
* Text Mode::                     Choosing canonical text mode.
* Offline Mode::                  Choosing offline mode.
* Included Certificates::         Including a number of certificates.
* Key Listing Mode::              Selecting key listing mode.
* Passphrase Callback::           Getting the passphrase from the user.
* Progress Meter Callback::       Being informed about the progress.
* Status Message Callback::       Status messages received from gpg.
* Locale::                        Setting the locale of a context.

Key Management

* Key objects::                   Description of the key structures.
* Listing Keys::                  Browsing the list of available keys.
* Information About Keys::        Requesting detailed information about keys.
* Manipulating Keys::             Operations on keys.
* Generating Keys::               Creating new key pairs.
* Signing Keys::                  Adding key signatures to public keys.
* Exporting Keys::                Retrieving key data from the key ring.
* Importing Keys::                Adding keys to the key ring.
* Deleting Keys::                 Removing keys from the key ring.
* Changing Passphrases::          Change the passphrase of a key.
* Changing TOFU Data::            Changing data pertaining to TOFU.
* Advanced Key Editing::          Advanced key edit operation.

Trust Item Management

* Listing Trust Items::           Browsing the list of available trust items.
* Manipulating Trust Items::      Operations on trust items.

Crypto Operations

* Decrypt::                       Decrypting a ciphertext.
* Verify::                        Verifying a signature.
* Decrypt and Verify::            Decrypting a signed ciphertext.
* Sign::                          Creating a signature.
* Encrypt::                       Encrypting a plaintext.

Sign

* Selecting Signers::             How to choose the keys to sign with.
* Creating a Signature::          How to create a signature.
* Signature Notation Data::       How to add notation data to a signature.

Encrypt

* Encrypting a Plaintext::        How to encrypt a plaintext.

Miscellaneous

* Running other Programs::        Running other Programs.
* Using the Assuan protocol::     Using the Assuan protocol.
* Checking for updates::          How to check for software updates.

Run Control

* Waiting For Completion::        Waiting until an operation is completed.
* Using External Event Loops::    Advanced control over what happens when.
* Cancellation::                  How to end pending operations prematurely.

Using External Event Loops

* I/O Callback Interface::        How I/O callbacks are registered.
* Registering I/O Callbacks::     How to use I/O callbacks for a context.
* I/O Callback Example::          An example how to use I/O callbacks.
* I/O Callback Example GTK+::     How to integrate GPGME in GTK+.
* I/O Callback Example GDK::      How to integrate GPGME in GDK.
* I/O Callback Example Qt::       How to integrate GPGME in Qt.



File: gpgme.info,  Node: Introduction,  Next: Preparation,  Prev: Top,  Up: Top

1 Introduction
**************

‘GnuPG Made Easy’ (GPGME) is a C language library that allows to add
support for cryptography to a program.  It is designed to make access to
public key crypto engines like GnuPG or GpgSM easier for applications.
GPGME provides a high-level crypto API for encryption, decryption,
signing, signature verification and key management.

   GPGME uses GnuPG and GpgSM as its backends to support OpenPGP and the
Cryptographic Message Syntax (CMS).

* Menu:

* Getting Started::               Purpose of the manual, and how to use it.
* Features::                      Reasons to install and use GPGME.
* Overview::                      Basic architecture of the GPGME library.


File: gpgme.info,  Node: Getting Started,  Next: Features,  Up: Introduction

1.1 Getting Started
===================

This manual documents the GPGME library programming interface.  All
functions and data types provided by the library are explained.

   The reader is assumed to possess basic knowledge about cryptography
in general, and public key cryptography in particular.  The underlying
cryptographic engines that are used by the library are not explained,
but where necessary, special features or requirements by an engine are
mentioned as far as they are relevant to GPGME or its users.

   This manual can be used in several ways.  If read from the beginning
to the end, it gives a good introduction into the library and how it can
be used in an application.  Forward references are included where
necessary.  Later on, the manual can be used as a reference manual to
get just the information needed about any particular interface of the
library.  Experienced programmers might want to start looking at the
examples at the end of the manual, and then only read up those parts of
the interface which are unclear.

   The documentation for the language bindings is currently not included
in this manual.  Those languages bindings follow the general programming
model of GPGME but may provide some extra high level abstraction on top
of the GPGME style API. For now please see the README files in the
‘lang/’ directory of the source distribution.


File: gpgme.info,  Node: Features,  Next: Overview,  Prev: Getting Started,  Up: Introduction

1.2 Features
============

GPGME has a couple of advantages over other libraries doing a similar
job, and over implementing support for GnuPG or other crypto engines
into your application directly.

it’s free software
     Anybody can use, modify, and redistribute it under the terms of the
     GNU Lesser General Public License (*note Library Copying::).

it’s flexible
     GPGME provides transparent support for several cryptographic
     protocols by different engines.  Currently, GPGME supports the
     OpenPGP protocol using GnuPG as the backend, and the Cryptographic
     Message Syntax using GpgSM as the backend.

it’s easy
     GPGME hides the differences between the protocols and engines from
     the programmer behind an easy-to-use interface.  This way the
     programmer can focus on the other parts of the program, and still
     integrate strong cryptography in his application.  Once support for
     GPGME has been added to a program, it is easy to add support for
     other crypto protocols once GPGME backends provide them.

it’s language friendly
     GPGME comes with languages bindings for several common programming
     languages: Common Lisp, C++, Python 2, and Python 3.


File: gpgme.info,  Node: Overview,  Prev: Features,  Up: Introduction

1.3 Overview
============

GPGME provides a data abstraction that is used to pass data to the
crypto engine, and receive returned data from it.  Data can be read from
memory or from files, but it can also be provided by a callback
function.

   The actual cryptographic operations are always set within a context.
A context provides configuration parameters that define the behaviour of
all operations performed within it.  Only one operation per context is
allowed at any time, but when one operation is finished, you can run the
next operation in the same context.  There can be more than one context,
and all can run different operations at the same time.

   Furthermore, GPGME has rich key management facilities including
listing keys, querying their attributes, generating, importing,
exporting and deleting keys, and acquiring information about the trust
path.

   With some precautions, GPGME can be used in a multi-threaded
environment, although it is not completely thread safe and thus needs
the support of the application.


File: gpgme.info,  Node: Preparation,  Next: Protocols and Engines,  Prev: Introduction,  Up: Top

2 Preparation
*************

To use GPGME, you have to perform some changes to your sources and the
build system.  The necessary changes are small and explained in the
following sections.  At the end of this chapter, it is described how the
library is initialized, and how the requirements of the library are
verified.

* Menu:

* Header::                        What header file you need to include.
* Building the Source::           Compiler options to be used.
* Largefile Support (LFS)::       How to use GPGME with LFS.
* Using Automake::                Compiler options to be used the easy way.
* Using Libtool::                 Avoiding compiler options entirely.
* Library Version Check::         Getting and verifying the library version.
* Signal Handling::               How GPGME affects signal handling.
* Multi-Threading::               How GPGME can be used in an MT environment.


File: gpgme.info,  Node: Header,  Next: Building the Source,  Up: Preparation

2.1 Header
==========

All interfaces (data types and functions) of the library are defined in
the header file ‘gpgme.h’.  You must include this in all programs using
the library, either directly or through some other header file, like
this:

     #include <gpgme.h>

   The name space of GPGME is ‘gpgme_*’ for function names and data
types and ‘GPGME_*’ for other symbols.  Symbols internal to GPGME take
the form ‘_gpgme_*’ and ‘_GPGME_*’.

   Because GPGME makes use of the GPG Error library, using GPGME will
also use the ‘GPG_ERR_*’ name space directly, and the ‘gpg_err*’,
‘gpg_str*’, and ‘gpgrt_*’ name space indirectly.


File: gpgme.info,  Node: Building the Source,  Next: Largefile Support (LFS),  Prev: Header,  Up: Preparation

2.2 Building the Source
=======================

If you want to compile a source file including the ‘gpgme.h’ header
file, you must make sure that the compiler can find it in the directory
hierarchy.  This is accomplished by adding the path to the directory in
which the header file is located to the compilers include file search
path (via the ‘-I’ option).

   However, the path to the include file is determined at the time the
source is configured.  To solve this problem, gpgme ships with a small
helper program ‘gpgme-config’ that knows about the path to the include
file and other configuration options.  The options that need to be added
to the compiler invocation at compile time are output by the ‘--cflags’
option to ‘gpgme-config’.  The following example shows how it can be
used at the command line:

     gcc -c foo.c `gpgme-config --cflags`

   Adding the output of ‘gpgme-config --cflags’ to the compiler command
line will ensure that the compiler can find the GPGME header file.

   A similar problem occurs when linking the program with the library.
Again, the compiler has to find the library files.  For this to work,
the path to the library files has to be added to the library search path
(via the ‘-L’ option).  For this, the option ‘--libs’ to ‘gpgme-config’
can be used.  For convenience, this option also outputs all other
options that are required to link the program with GPGME (in particular,
the ‘-lgpgme’ option).  The example shows how to link ‘foo.o’ with the
GPGME library to a program ‘foo’.

     gcc -o foo foo.o `gpgme-config --libs`

   Of course you can also combine both examples to a single command by
specifying both options to ‘gpgme-config’:

     gcc -o foo foo.c `gpgme-config --cflags --libs`

   If you need to detect the installed language bindings you can use
list them using:

     gpgme-config --print-lang

   or test for the availability using

     gpgme-config --have-lang=python && echo 'Bindings for Pythons available'


File: gpgme.info,  Node: Largefile Support (LFS),  Next: Using Automake,  Prev: Building the Source,  Up: Preparation

2.3 Largefile Support (LFS)
===========================

GPGME is compiled with largefile support by default, if it is available
on the system.  This means that GPGME supports files larger than two
gigabyte in size, if the underlying operating system can.  On some
systems, largefile support is already the default.  On such systems,
nothing special is required.  However, some systems provide only support
for files up to two gigabyte in size by default.  Support for larger
file sizes has to be specifically enabled.

   To make a difficult situation even more complex, such systems provide
two different types of largefile support.  You can either get all
relevant functions replaced with alternatives that are largefile
capable, or you can get new functions and data types for largefile
support added.  Those new functions have the same name as their
smallfile counterparts, but with a suffix of 64.

   An example: The data type ‘off_t’ is 32 bit wide on GNU/Linux PC
systems.  To address offsets in large files, you can either enable
largefile support add-on.  Then a new data type ‘off64_t’ is provided,
which is 64 bit wide.  Or you can replace the existing ‘off_t’ data type
with its 64 bit wide counterpart.  All occurences of ‘off_t’ are then
automagically replaced.

   As if matters were not complex enough, there are also two different
types of file descriptors in such systems.  This is important because if
file descriptors are exchanged between programs that use a different
maximum file size, certain errors must be produced on some file
descriptors to prevent subtle overflow bugs from occuring.

   As you can see, supporting two different maximum file sizes at the
same time is not at all an easy task.  However, the maximum file size
does matter for GPGME, because some data types it uses in its interfaces
are affected by that.  For example, the ‘off_t’ data type is used in the
‘gpgme_data_seek’ function, to match its POSIX counterpart.  This
affects the call-frame of the function, and thus the ABI of the library.
Furthermore, file descriptors can be exchanged between GPGME and the
application.

   For you as the user of the library, this means that your program must
be compiled in the same file size mode as the library.  Luckily, there
is absolutely no valid reason for new programs to not enable largefile
support by default and just use that.  The compatibility modes (small
file sizes or dual mode) can be considered an historic artefact, only
useful to allow for a transitional period.

   On POSIX platforms GPGME is compiled using largefile support by
default.  This means that your application must do the same, at least as
far as it is relevant for using the ‘gpgme.h’ header file.  All types in
this header files refer to their largefile counterparts, if they are
different from any default types on the system.

   On 32 and 64 bit Windows platforms ‘off_t’ is declared as 32 bit
signed integer.  There is no specific support for LFS in the C library.
The recommendation from Microsoft is to use the native interface
(‘CreateFile’ et al.)  for large files.  Released binary versions of
GPGME (libgpgme-11.dll) have always been build with a 32 bit ‘off_t’.
To avoid an ABI break we stick to this convention for 32 bit Windows by
using ‘long’ there.  GPGME versions for 64 bit Windows have never been
released and thus we are able to use ‘int64_t’ instead of ‘off_t’ there.
For easier migration the typedef ‘gpgme_off_t’ has been defined.  The
reason we cannot use ‘off_t’ directly is that some toolchains (e.g.
mingw64) introduce a POSIX compatible hack for ‘off_t’.  Some widely
used toolkits make use of this hack and in turn GPGME would need to use
it also.  However, this would introduce an ABI break and existing
software making use of libgpgme might suffer from a severe break.  Thus
with version 1.4.2 we redefined all functions using ‘off_t’ to use
‘gpgme_off_t’ which is defined as explained above.  This way we keep the
ABI well defined and independent of any toolchain hacks.  The bottom
line is that LFS support in GPGME is only available on 64 bit versions
of Windows.

   On POSIX platforms you can enable largefile support, if it is
different from the default on the system the application is compiled on,
by using the Autoconf macro ‘AC_SYS_LARGEFILE’.  If you do this, then
you don’t need to worry about anything else: It will just work.  In this
case you might also want to use ‘AC_FUNC_FSEEKO’ to take advantage of
some new interfaces, and ‘AC_TYPE_OFF_T’ (just in case).

   If you do not use Autoconf, you can define the preprocessor symbol
‘_FILE_OFFSET_BITS’ to 64 _before_ including any header files, for
example by specifying the option ‘-D_FILE_OFFSET_BITS=64’ on the
compiler command line.  You will also want to define the preprocessor
symbol ‘LARGEFILE_SOURCE’ to 1 in this case, to take advantage of some
new interfaces.

   If you do not want to do either of the above, you probably know
enough about the issue to invent your own solution.  Just keep in mind
that the GPGME header file expects that largefile support is enabled, if
it is available.  In particular, we do not support dual mode
(‘_LARGEFILE64_SOURCE’).


File: gpgme.info,  Node: Using Automake,  Next: Using Libtool,  Prev: Largefile Support (LFS),  Up: Preparation

2.4 Using Automake
==================

It is much easier if you use GNU Automake instead of writing your own
Makefiles.  If you do that you do not have to worry about finding and
invoking the ‘gpgme-config’ script at all.  GPGME provides an extension
to Automake that does all the work for you.

 -- Macro: AM_PATH_GPGME ([MINIMUM-VERSION], [ACTION-IF-FOUND],
          [ACTION-IF-NOT-FOUND])
 -- Macro: AM_PATH_GPGME_PTH ([MINIMUM-VERSION], [ACTION-IF-FOUND],
          [ACTION-IF-NOT-FOUND])
 -- Macro: AM_PATH_GPGME_PTHREAD ([MINIMUM-VERSION], [ACTION-IF-FOUND],
          [ACTION-IF-NOT-FOUND])
     Check whether GPGME (at least version MINIMUM-VERSION, if given)
     exists on the host system.  If it is found, execute
     ACTION-IF-FOUND, otherwise do ACTION-IF-NOT-FOUND, if given.

     Additionally, the function defines ‘GPGME_CFLAGS’ to the flags
     needed for compilation of the program to find the ‘gpgme.h’ header
     file, and ‘GPGME_LIBS’ to the linker flags needed to link the
     program to the GPGME library.  If the used helper script does not
     match the target type you are building for a warning is printed and
     the string ‘libgcrypt’ is appended to the variable
     ‘gpg_config_script_warn’.

     ‘AM_PATH_GPGME_PTH’ checks for the version of GPGME that can be
     used with GNU Pth, and defines ‘GPGME_PTH_CFLAGS’ and
     ‘GPGME_PTH_LIBS’.

     ‘AM_PATH_GPGME_PTHREAD’ checks for the version of GPGME that can be
     used with the native pthread implementation, and defines
     ‘GPGME_PTHREAD_CFLAGS’ and ‘GPGME_PTHREAD_LIBS’.  Since version
     1.8.0 this is no longer required to GPGME_PTHREAD as GPGME itself
     is thread safe.

     This macro searches for ‘gpgme-config’ along the PATH. If you are
     cross-compiling, it is useful to set the environment variable
     ‘SYSROOT’ to the top directory of your target.  The macro will then
     first look for the helper program in the ‘bin’ directory below that
     top directory.  An absolute directory name must be used for
     ‘SYSROOT’.  Finally, if the configure command line option
     ‘--with-gpgme-prefix’ is used, only its value is used for the top
     directory below which the helper script is expected.

   You can use the defined Autoconf variables like this in your
‘Makefile.am’:

     AM_CPPFLAGS = $(GPGME_CFLAGS)
     LDADD = $(GPGME_LIBS)


File: gpgme.info,  Node: Using Libtool,  Next: Library Version Check,  Prev: Using Automake,  Up: Preparation

2.5 Using Libtool
=================

The easiest way is to just use GNU Libtool.  If you use libtool, and
link to ‘libgpgme.la’, ‘libgpgme-pth.la’ or ‘libgpgme-pthread.la’
respectively, everything will be done automatically by Libtool.


File: gpgme.info,  Node: Library Version Check,  Next: Signal Handling,  Prev: Using Libtool,  Up: Preparation

2.6 Library Version Check
=========================

 -- Function: const char * gpgme_check_version
          (const char *REQUIRED_VERSION)
     The function ‘gpgme_check_version’ has four purposes.  It can be
     used to retrieve the version number of the library.  In addition it
     can verify that the version number is higher than a certain
     required version number.  In either case, the function initializes
     some sub-systems, and for this reason alone it must be invoked
     early in your program, before you make use of the other functions
     in GPGME.  The last purpose is to run selftests.

     As a side effect for W32 based systems, the socket layer will get
     initialized.

     If REQUIRED_VERSION is ‘NULL’, the function returns a pointer to a
     statically allocated string containing the version number of the
     library.

     If REQUIRED_VERSION is not ‘NULL’, it should point to a string
     containing a version number, and the function checks that the
     version of the library is at least as high as the version number
     provided.  In this case, the function returns a pointer to a
     statically allocated string containing the version number of the
     library.  If REQUIRED_VERSION is not a valid version number, or if
     the version requirement is not met, the function returns ‘NULL’.

     If you use a version of a library that is backwards compatible with
     older releases, but contains additional interfaces which your
     program uses, this function provides a run-time check if the
     necessary features are provided by the installed version of the
     library.

     If a selftest fails, the function may still succeed.  Selftest
     errors are returned later when invoking ‘gpgme_new’, so that a
     detailed error code can be returned (historically,
     ‘gpgme_check_version’ does not return a detailed error code).

 -- Function: int gpgme_set_global_flag (const char *NAME,
          const char *VALUE)

     On some systems it is not easy to set environment variables and
     thus hard to use GPGME’s internal trace facility for debugging.
     This function has been introduced as an alternative way to enable
     debugging and for a couple of other rarely used tweaks.  It is
     important to assure that only one thread accesses GPGME functions
     between a call to this function and after the return from the call
     to ‘gpgme_check_version’.

     All currently supported features require that this function is
     called as early as possible — even before ‘gpgme_check_version’.
     The features are identified by the following values for NAME:

     ‘debug’
          To enable debugging use the string “debug” for NAME and VALUE
          identical to the value used with the environment variable
          ‘GPGME_DEBUG’.

     ‘disable-gpgconf’
          Using this feature with any VALUE disables the detection of
          the gpgconf program and thus forces GPGME to fallback into the
          simple OpenPGP only mode.  It may be used to force the use of
          GnuPG-1 on systems which have both GPG versions installed.
          Note that in general the use of ‘gpgme_set_engine_info’ is a
          better way to select a specific engine version.

     ‘gpgconf-name’
     ‘gpg-name’
          Set the name of the gpgconf respective gpg binary.  The
          defaults are ‘GNU/GnuPG/gpgconf’ and ‘GNU/GnuPG/gpg’.  Under
          Unix the leading directory part is ignored.  Under Windows the
          leading directory part is used as the default installation
          directory; the ‘.exe’ suffix is added by GPGME. Use forward
          slashed even under Windows.

     ‘require-gnupg’
          Set the mimimum version of the required GnuPG engine.  If that
          version is not met, GPGME fails early instead of trying to use
          the existant version.  The given version must be a string with
          major, minor, and micro number.  Example: "2.1.0".

     ‘w32-inst-dir’
          On Windows GPGME needs to know its installation directory to
          find its spawn helper.  This is in general no problem because
          a DLL has this information.  Some applications however link
          statically to GPGME and thus GPGME can only figure out the
          installation directory of this application which may be wrong
          in certain cases.  By supplying an installation directory as
          value to this flag, GPGME will assume that that directory is
          the installation directory.  This flag has no effect on
          non-Windows platforms.

     This function returns ‘0’ on success.  In contrast to other
     functions the non-zero return value on failure does not convey any
     error code.  For setting “debug” the only possible error cause is
     an out of memory condition; which would exhibit itself later
     anyway.  Thus the return value may be ignored.

   After initializing GPGME, you should set the locale information to
the locale required for your output terminal.  This locale information
is needed for example for the curses and Gtk pinentry.  Here is an
example of a complete initialization:

     #include <locale.h>
     #include <gpgme.h>

     void
     init_gpgme (void)
     {
       /* Initialize the locale environment.  */
       setlocale (LC_ALL, "");
       gpgme_check_version (NULL);
       gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
     #ifdef LC_MESSAGES
       gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
     #endif
     }

   Note that you are highly recommended to initialize the locale
settings like this.  GPGME can not do this for you because it would not
be thread safe.  The conditional on LC_MESSAGES is only necessary for
portability to W32 systems.


File: gpgme.info,  Node: Signal Handling,  Next: Multi-Threading,  Prev: Library Version Check,  Up: Preparation

2.7 Signal Handling
===================

The GPGME library communicates with child processes (the crypto
engines).  If a child process dies unexpectedly, for example due to a
bug, or system problem, a ‘SIGPIPE’ signal will be delivered to the
application.  The default action is to abort the program.  To protect
against this, ‘gpgme_check_version’ sets the ‘SIGPIPE’ signal action to
‘SIG_IGN’, which means that the signal will be ignored.

   GPGME will only do that if the signal action for ‘SIGPIPE’ is
‘SIG_DEF’ at the time ‘gpgme_check_version’ is called.  If it is
something different, ‘GPGME’ will take no action.

   This means that if your application does not install any signal
handler for ‘SIGPIPE’, you don’t need to take any precautions.  If you
do install a signal handler for ‘SIGPIPE’, you must be prepared to
handle any ‘SIGPIPE’ events that occur due to GPGME writing to a defunct
pipe.  Furthermore, if your application is multi-threaded, and you
install a signal action for ‘SIGPIPE’, you must make sure you do this
either before ‘gpgme_check_version’ is called or afterwards.


File: gpgme.info,  Node: Multi-Threading,  Prev: Signal Handling,  Up: Preparation

2.8 Multi-Threading
===================

The GPGME library is mostly thread-safe, and can be used in a
multi-threaded environment but there are some requirements for
multi-threaded use:

   • The function ‘gpgme_check_version’ must be called before any other
     function in the library, because it initializes the thread support
     subsystem in GPGME.  To achieve this in multi-threaded programs,
     you must synchronize the memory with respect to other threads that
     also want to use GPGME.  For this, it is sufficient to call
     ‘gpgme_check_version’ before creating the other threads using
     GPGME(1).

   • Any ‘gpgme_data_t’ and ‘gpgme_ctx_t’ object must only be accessed
     by one thread at a time.  If multiple threads want to deal with the
     same object, the caller has to make sure that operations on that
     object are fully synchronized.

   • Only one thread at any time is allowed to call ‘gpgme_wait’.  If
     multiple threads call this function, the caller must make sure that
     all invocations are fully synchronized.  It is safe to start
     asynchronous operations while a thread is running in gpgme_wait.

   • The function ‘gpgme_strerror’ is not thread safe.  You have to use
     ‘gpgme_strerror_r’ instead.

   ---------- Footnotes ----------

   (1) At least this is true for POSIX threads, as ‘pthread_create’ is a
function that synchronizes memory with respects to other threads.  There
are many functions which have this property, a complete list can be
found in POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
definition of the term “Memory Synchronization”.  For other thread
packages other, more relaxed or more strict rules may apply.


File: gpgme.info,  Node: Protocols and Engines,  Next: Algorithms,  Prev: Preparation,  Up: Top

3 Protocols and Engines
***********************

GPGME supports several cryptographic protocols, however, it does not
implement them.  Rather it uses backends (also called engines) which
implement the protocol.  GPGME uses inter-process communication to pass
data back and forth between the application and the backend, but the
details of the communication protocol and invocation of the backend is
completely hidden by the interface.  All complexity is handled by GPGME.
Where an exchange of information between the application and the backend
is necessary, GPGME provides the necessary callback function hooks and
further interfaces.

 -- Data type: enum gpgme_protocol_t
     The ‘gpgme_protocol_t’ type specifies the set of possible protocol
     values that are supported by GPGME.  The following protocols are
     supported:

     ‘GPGME_PROTOCOL_OpenPGP’
          This specifies the OpenPGP protocol.

     ‘GPGME_PROTOCOL_CMS’
          This specifies the Cryptographic Message Syntax.

     ‘GPGME_PROTOCOL_GPGCONF’
          Under development.  Please ask on <gnupg-devel@gnupg.org> for
          help.

     ‘GPGME_PROTOCOL_ASSUAN’
          This specifies the raw Assuan protocol.

     ‘GPGME_PROTOCOL_G13’
          Under development.  Please ask on <gnupg-devel@gnupg.org> for
          help.

     ‘GPGME_PROTOCOL_UISERVER’
          Under development.  Please ask on <gnupg-devel@gnupg.org> for
          help.

     ‘GPGME_PROTOCOL_SPAWN’
          Special protocol for use with ‘gpgme_op_spawn’.

     ‘GPGME_PROTOCOL_UNKNOWN’
          Reserved for future extension.  You may use this to indicate
          that the used protocol is not known to the application.
          Currently, GPGME does not accept this value in any operation,
          though, except for ‘gpgme_get_protocol_name’.

 -- Function: const char * gpgme_get_protocol_name
          (gpgme_protocol_t PROTOCOL)
     The function ‘gpgme_get_protocol_name’ returns a statically
     allocated string describing the protocol PROTOCOL, or ‘NULL’ if the
     protocol number is not valid.

* Menu:

* Engine Version Check::          Verifying the engine version.
* Engine Information::            Obtaining more information about the engines.
* Engine Configuration::          Changing the engine configuration.
* OpenPGP::                       Support for the OpenPGP protocol.
* Cryptographic Message Syntax::  Support for the CMS.
* Assuan::                        Support for the raw Assuan protocol.


File: gpgme.info,  Node: Engine Version Check,  Next: Engine Information,  Up: Protocols and Engines

3.1 Engine Version Check
========================

 -- Function: const char * gpgme_get_dirinfo (cons char *WHAT)
     The function ‘gpgme_get_dirinfo’ returns a statically allocated
     string with the value associated to WHAT.  The returned values are
     the defaults and won’t change even after ‘gpgme_set_engine_info’
     has been used to configure a different engine.  ‘NULL’ is returned
     if no value is available.  Commonly supported values for WHAT are:

     ‘homedir’
          Return the default home directory.

     ‘sysconfdir’
          Return the name of the system configuration directory

     ‘bindir’
          Return the name of the directory with GnuPG program files.

     ‘libdir’
          Return the name of the directory with GnuPG related library
          files.

     ‘libexecdir’
          Return the name of the directory with GnuPG helper program
          files.

     ‘datadir’
          Return the name of the directory with GnuPG shared data.

     ‘localedir’
          Return the name of the directory with GnuPG locale data.

     ‘agent-socket’
          Return the name of the socket to connect to the gpg-agent.

     ‘agent-ssh-socket’
          Return the name of the socket to connect to the ssh-agent
          component of gpg-agent.

     ‘dirmngr-socket’
          Return the name of the socket to connect to the dirmngr.

     ‘uiserver-socket’
          Return the name of the socket to connect to the user interface
          server.

     ‘gpgconf-name’
          Return the file name of the engine configuration tool.

     ‘gpg-name’
          Return the file name of the OpenPGP engine.

     ‘gpgsm-name’
          Return the file name of the CMS engine.

     ‘g13-name’
          Return the name of the file container encryption engine.

 -- Function: gpgme_error_t gpgme_engine_check_version
          (gpgme_protocol_t PROTOCOL)
     The function ‘gpgme_engine_check_version’ verifies that the engine
     implementing the protocol PROTOCOL is installed in the expected
     path and meets the version requirement of GPGME.

     This function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     engine is available and ‘GPG_ERR_INV_ENGINE’ if it is not.


File: gpgme.info,  Node: Engine Information,  Next: Engine Configuration,  Prev: Engine Version Check,  Up: Protocols and Engines

3.2 Engine Information
======================

 -- Data type: gpgme_engine_info_t
     The ‘gpgme_engine_info_t’ type specifies a pointer to a structure
     describing a crypto engine.  The structure contains the following
     elements:

     ‘gpgme_engine_info_t next’
          This is a pointer to the next engine info structure in the
          linked list, or ‘NULL’ if this is the last element.

     ‘gpgme_protocol_t protocol’
          This is the protocol for which the crypto engine is used.  You
          can convert this to a string with ‘gpgme_get_protocol_name’
          for printing.

     ‘const char *file_name’
          This is a string holding the file name of the executable of
          the crypto engine.  Currently, it is never ‘NULL’, but using
          ‘NULL’ is reserved for future use, so always check before you
          use it.

     ‘const char *home_dir’
          This is a string holding the directory name of the crypto
          engine’s configuration directory.  If it is ‘NULL’, then the
          default directory is used.  See ‘gpgme_get_dirinfo’ on how to
          get the default directory.

     ‘const char *version’
          This is a string containing the version number of the crypto
          engine.  It might be ‘NULL’ if the version number can not be
          determined, for example because the executable doesn’t exist
          or is invalid.

     ‘const char *req_version’
          This is a string containing the minimum required version
          number of the crypto engine for GPGME to work correctly.  This
          is the version number that ‘gpgme_engine_check_version’
          verifies against.  Currently, it is never ‘NULL’, but using
          ‘NULL’ is reserved for future use, so always check before you
          use it.

 -- Function: gpgme_error_t gpgme_get_engine_info
          (gpgme_engine_info_t *INFO)
     The function ‘gpgme_get_engine_info’ returns a linked list of
     engine info structures in INFO.  Each info structure describes the
     defaults of one configured backend.

     The memory for the info structures is allocated the first time this
     function is invoked, and must not be freed by the caller.

     This function returns the error code ‘GPG_ERR_NO_ERROR’ if
     successful, and a system error if the memory could not be
     allocated.

   Here is an example how you can provide more diagnostics if you
receive an error message which indicates that the crypto engine is
invalid.

     gpgme_ctx_t ctx;
     gpgme_error_t err;

     [...]

     if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
       {
         gpgme_engine_info_t info;
         err = gpgme_get_engine_info (&info);
         if (!err)
           {
             while (info && info->protocol != gpgme_get_protocol (ctx))
               info = info->next;
             if (!info)
               fprintf (stderr, "GPGME compiled without support for protocol %s",
                        gpgme_get_protocol_name (info->protocol));
             else if (info->file_name && !info->version)
               fprintf (stderr, "Engine %s not installed properly",
                        info->file_name);
             else if (info->file_name && info->version && info->req_version)
               fprintf (stderr, "Engine %s version %s installed, "
                        "but at least version %s required", info->file_name,
                        info->version, info->req_version);
             else
               fprintf (stderr, "Unknown problem with engine for protocol %s",
                        gpgme_get_protocol_name (info->protocol));
           }
       }


File: gpgme.info,  Node: Engine Configuration,  Next: OpenPGP,  Prev: Engine Information,  Up: Protocols and Engines

3.3 Engine Configuration
========================

You can change the configuration of a backend engine, and thus change
the executable program and configuration directory to be used.  You can
make these changes the default or set them for some contexts
individually.

 -- Function: gpgme_error_t gpgme_set_engine_info
          (gpgme_protocol_t PROTO, const char *FILE_NAME,
          const char *HOME_DIR)
     The function ‘gpgme_set_engine_info’ changes the default
     configuration of the crypto engine implementing the protocol PROTO.

     FILE_NAME is the file name of the executable program implementing
     this protocol, and HOME_DIR is the directory name of the
     configuration directory for this crypto engine.  If HOME_DIR is
     ‘NULL’, the engine’s default will be used.

     The new defaults are not applied to already created GPGME contexts.

     This function returns the error code ‘GPG_ERR_NO_ERROR’ if
     successful, or an eror code on failure.

   The functions ‘gpgme_ctx_get_engine_info’ and
‘gpgme_ctx_set_engine_info’ can be used to change the engine
configuration per context.  *Note Crypto Engine::.


File: gpgme.info,  Node: OpenPGP,  Next: Cryptographic Message Syntax,  Prev: Engine Configuration,  Up: Protocols and Engines

3.4 OpenPGP
===========

OpenPGP is implemented by GnuPG, the GNU Privacy Guard.  This is the
first protocol that was supported by GPGME.

   The OpenPGP protocol is specified by ‘GPGME_PROTOCOL_OpenPGP’.


File: gpgme.info,  Node: Cryptographic Message Syntax,  Next: Assuan,  Prev: OpenPGP,  Up: Protocols and Engines

3.5 Cryptographic Message Syntax
================================

CMS is implemented by GpgSM, the S/MIME implementation for GnuPG.

   The CMS protocol is specified by ‘GPGME_PROTOCOL_CMS’.


File: gpgme.info,  Node: Assuan,  Prev: Cryptographic Message Syntax,  Up: Protocols and Engines

3.6 Assuan
==========

Assuan is the RPC library used by the various GnuPG components.  The
Assuan protocol allows one to talk to arbitrary Assuan servers using
GPGME.  *Note Using the Assuan protocol::.

   The ASSUAN protocol is specified by ‘GPGME_PROTOCOL_ASSUAN’.


File: gpgme.info,  Node: Algorithms,  Next: Error Handling,  Prev: Protocols and Engines,  Up: Top

4 Algorithms
************

The crypto backends support a variety of algorithms used in public key
cryptography.(1)  The following sections list the identifiers used to
denote such an algorithm.

* Menu:

* Public Key Algorithms::         A list of all public key algorithms.
* Hash Algorithms::               A list of all hash algorithms.

   ---------- Footnotes ----------

   (1) Some engines also provide symmetric only encryption; see the
description of the encryption function on how to use this.


File: gpgme.info,  Node: Public Key Algorithms,  Next: Hash Algorithms,  Up: Algorithms

4.1 Public Key Algorithms
=========================

Public key algorithms are used for encryption, decryption, signing and
verification of signatures.

 -- Data type: enum gpgme_pubkey_algo_t
     The ‘gpgme_pubkey_algo_t’ type specifies the set of all public key
     algorithms that are supported by GPGME.  Possible values are:

     ‘GPGME_PK_RSA’
          This value indicates the RSA (Rivest, Shamir, Adleman)
          algorithm.

     ‘GPGME_PK_RSA_E’
          Deprecated.  This value indicates the RSA (Rivest, Shamir,
          Adleman) algorithm for encryption and decryption only.

     ‘GPGME_PK_RSA_S’
          Deprecated.  This value indicates the RSA (Rivest, Shamir,
          Adleman) algorithm for signing and verification only.

     ‘GPGME_PK_DSA’
          This value indicates DSA, the Digital Signature Algorithm.

     ‘GPGME_PK_ELG’
          This value indicates ElGamal.

     ‘GPGME_PK_ELG_E’
          This value also indicates ElGamal and is used specifically in
          GnuPG.

     ‘GPGME_PK_ECC’
          This value is a generic indicator for ellipic curve
          algorithms.

     ‘GPGME_PK_ECDSA’
          This value indicates ECDSA, the Elliptic Curve Digital
          Signature Algorithm as defined by FIPS 186-2 and RFC-6637.

     ‘GPGME_PK_ECDH’
          This value indicates ECDH, the Eliptic Curve Diffie-Hellmann
          encryption algorithm as defined by RFC-6637.

     ‘GPGME_PK_EDDSA’
          This value indicates the EdDSA algorithm.

 -- Function: const char * gpgme_pubkey_algo_name
          (gpgme_pubkey_algo_t ALGO)
     The function ‘gpgme_pubkey_algo_name’ returns a pointer to a
     statically allocated string containing a description of the public
     key algorithm ALGO.  This string can be used to output the name of
     the public key algorithm to the user.

     If ALGO is not a valid public key algorithm, ‘NULL’ is returned.

 -- Function: char * gpgme_pubkey_algo_string (gpgme_subkey_t KEY)
     The function ‘gpgme_pubkey_algo_string’ is a convenience function
     to build and return an algorithm string in the same way GnuPG does
     (e.g.  “rsa2048” or “ed25519”).  The caller must free the result
     using ‘gpgme_free’.  On error (e.g.  invalid argument or memory
     exhausted), the function returns NULL and sets ‘ERRNO’.


File: gpgme.info,  Node: Hash Algorithms,  Prev: Public Key Algorithms,  Up: Algorithms

4.2 Hash Algorithms
===================

Hash (message digest) algorithms are used to compress a long message to
make it suitable for public key cryptography.

 -- Data type: enum gpgme_hash_algo_t
     The ‘gpgme_hash_algo_t’ type specifies the set of all hash
     algorithms that are supported by GPGME.  Possible values are:

     ‘GPGME_MD_MD5’
     ‘GPGME_MD_SHA1’
     ‘GPGME_MD_RMD160’
     ‘GPGME_MD_MD2’
     ‘GPGME_MD_TIGER’
     ‘GPGME_MD_HAVAL’
     ‘GPGME_MD_SHA256’
     ‘GPGME_MD_SHA384’
     ‘GPGME_MD_SHA512’
     ‘GPGME_MD_SHA224’
     ‘GPGME_MD_MD4’
     ‘GPGME_MD_CRC32’
     ‘GPGME_MD_CRC32_RFC1510’
     ‘GPGME_MD_CRC24_RFC2440’

 -- Function: const char * gpgme_hash_algo_name (gpgme_hash_algo_t ALGO)
     The function ‘gpgme_hash_algo_name’ returns a pointer to a
     statically allocated string containing a description of the hash
     algorithm ALGO.  This string can be used to output the name of the
     hash algorithm to the user.

     If ALGO is not a valid hash algorithm, ‘NULL’ is returned.


File: gpgme.info,  Node: Error Handling,  Next: Exchanging Data,  Prev: Algorithms,  Up: Top

5 Error Handling
****************

Many functions in GPGME can return an error if they fail.  For this
reason, the application should always catch the error condition and take
appropriate measures, for example by releasing the resources and passing
the error up to the caller, or by displaying a descriptive message to
the user and cancelling the operation.

   Some error values do not indicate a system error or an error in the
operation, but the result of an operation that failed properly.  For
example, if you try to decrypt a tempered message, the decryption will
fail.  Another error value actually means that the end of a data buffer
or list has been reached.  The following descriptions explain for many
error codes what they mean usually.  Some error values have specific
meanings if returned by a certain functions.  Such cases are described
in the documentation of those functions.

   GPGME uses the ‘libgpg-error’ library.  This allows to share the
error codes with other components of the GnuPG system, and thus pass
error values transparently from the crypto engine, or some helper
application of the crypto engine, to the user.  This way no information
is lost.  As a consequence, GPGME does not use its own identifiers for
error codes, but uses those provided by ‘libgpg-error’.  They usually
start with ‘GPG_ERR_’.

   However, GPGME does provide aliases for the functions defined in
libgpg-error, which might be preferred for name space consistency.

* Menu:

* Error Values::                  The error value and what it means.
* Error Sources::                 A list of important error sources.
* Error Codes::                   A list of important error codes.
* Error Strings::                 How to get a descriptive string from a value.


File: gpgme.info,  Node: Error Values,  Next: Error Sources,  Up: Error Handling

5.1 Error Values
================

 -- Data type: gpgme_err_code_t
     The ‘gpgme_err_code_t’ type is an alias for the ‘libgpg-error’ type
     ‘gpg_err_code_t’.  The error code indicates the type of an error,
     or the reason why an operation failed.

     A list of important error codes can be found in the next section.

 -- Data type: gpgme_err_source_t
     The ‘gpgme_err_source_t’ type is an alias for the ‘libgpg-error’
     type ‘gpg_err_source_t’.  The error source has not a precisely
     defined meaning.  Sometimes it is the place where the error
     happened, sometimes it is the place where an error was encoded into
     an error value.  Usually the error source will give an indication
     to where to look for the problem.  This is not always true, but it
     is attempted to achieve this goal.

     A list of important error sources can be found in the next section.

 -- Data type: gpgme_error_t
     The ‘gpgme_error_t’ type is an alias for the ‘libgpg-error’ type
     ‘gpg_error_t’.  An error value like this has always two components,
     an error code and an error source.  Both together form the error
     value.

     Thus, the error value can not be directly compared against an error
     code, but the accessor functions described below must be used.
     However, it is guaranteed that only 0 is used to indicate success
     (‘GPG_ERR_NO_ERROR’), and that in this case all other parts of the
     error value are set to 0, too.

     Note that in GPGME, the error source is used purely for
     diagnostical purposes.  Only the error code should be checked to
     test for a certain outcome of a function.  The manual only
     documents the error code part of an error value.  The error source
     is left unspecified and might be anything.

 -- Function: static inline gpgme_err_code_t gpgme_err_code
          (gpgme_error_t ERR)
     The static inline function ‘gpgme_err_code’ returns the
     ‘gpgme_err_code_t’ component of the error value ERR.  This function
     must be used to extract the error code from an error value in order
     to compare it with the ‘GPG_ERR_*’ error code macros.

 -- Function: static inline gpgme_err_source_t gpgme_err_source
          (gpgme_error_t ERR)
     The static inline function ‘gpgme_err_source’ returns the
     ‘gpgme_err_source_t’ component of the error value ERR.  This
     function must be used to extract the error source from an error
     value in order to compare it with the ‘GPG_ERR_SOURCE_*’ error
     source macros.

 -- Function: static inline gpgme_error_t gpgme_err_make
          (gpgme_err_source_t SOURCE, gpgme_err_code_t CODE)
     The static inline function ‘gpgme_err_make’ returns the error value
     consisting of the error source SOURCE and the error code CODE.

     This function can be used in callback functions to construct an
     error value to return it to the library.

 -- Function: static inline gpgme_error_t gpgme_error
          (gpgme_err_code_t CODE)
     The static inline function ‘gpgme_error’ returns the error value
     consisting of the default error source and the error code CODE.

     For GPGME applications, the default error source is
     ‘GPG_ERR_SOURCE_USER_1’.  You can define ‘GPGME_ERR_SOURCE_DEFAULT’
     before including ‘gpgme.h’ to change this default.

     This function can be used in callback functions to construct an
     error value to return it to the library.

   The ‘libgpg-error’ library provides error codes for all system error
numbers it knows about.  If ERR is an unknown error number, the error
code ‘GPG_ERR_UNKNOWN_ERRNO’ is used.  The following functions can be
used to construct error values from system errnor numbers.

 -- Function: gpgme_error_t gpgme_err_make_from_errno
          (gpgme_err_source_t SOURCE, int ERR)
     The function ‘gpgme_err_make_from_errno’ is like ‘gpgme_err_make’,
     but it takes a system error like ‘errno’ instead of a
     ‘gpgme_err_code_t’ error code.

 -- Function: gpgme_error_t gpgme_error_from_errno (int ERR)
     The function ‘gpgme_error_from_errno’ is like ‘gpgme_error’, but it
     takes a system error like ‘errno’ instead of a ‘gpgme_err_code_t’
     error code.

   Sometimes you might want to map system error numbers to error codes
directly, or map an error code representing a system error back to the
system error number.  The following functions can be used to do that.

 -- Function: gpgme_err_code_t gpgme_err_code_from_errno (int ERR)
     The function ‘gpgme_err_code_from_errno’ returns the error code for
     the system error ERR.  If ERR is not a known system error, the
     function returns ‘GPG_ERR_UNKNOWN_ERRNO’.

 -- Function: int gpgme_err_code_to_errno (gpgme_err_code_t ERR)
     The function ‘gpgme_err_code_to_errno’ returns the system error for
     the error code ERR.  If ERR is not an error code representing a
     system error, or if this system error is not defined on this
     system, the function returns ‘0’.


File: gpgme.info,  Node: Error Sources,  Next: Error Codes,  Prev: Error Values,  Up: Error Handling

5.2 Error Sources
=================

The library ‘libgpg-error’ defines an error source for every component
of the GnuPG system.  The error source part of an error value is not
well defined.  As such it is mainly useful to improve the diagnostic
error message for the user.

   If the error code part of an error value is ‘0’, the whole error
value will be ‘0’.  In this case the error source part is of course
‘GPG_ERR_SOURCE_UNKNOWN’.

   The list of error sources that might occur in applications using
GPGME is:

‘GPG_ERR_SOURCE_UNKNOWN’
     The error source is not known.  The value of this error source is
     ‘0’.

‘GPG_ERR_SOURCE_GPGME’
     The error source is GPGME itself.  This is the default for errors
     that occur in the GPGME library.

‘GPG_ERR_SOURCE_GPG’
     The error source is GnuPG, which is the crypto engine used for the
     OpenPGP protocol.

‘GPG_ERR_SOURCE_GPGSM’
     The error source is GPGSM, which is the crypto engine used for the
     CMS protocol.

‘GPG_ERR_SOURCE_GCRYPT’
     The error source is ‘libgcrypt’, which is used by crypto engines to
     perform cryptographic operations.

‘GPG_ERR_SOURCE_GPGAGENT’
     The error source is ‘gpg-agent’, which is used by crypto engines to
     perform operations with the secret key.

‘GPG_ERR_SOURCE_PINENTRY’
     The error source is ‘pinentry’, which is used by ‘gpg-agent’ to
     query the passphrase to unlock a secret key.

‘GPG_ERR_SOURCE_SCD’
     The error source is the SmartCard Daemon, which is used by
     ‘gpg-agent’ to delegate operations with the secret key to a
     SmartCard.

‘GPG_ERR_SOURCE_KEYBOX’
     The error source is ‘libkbx’, a library used by the crypto engines
     to manage local keyrings.

‘GPG_ERR_SOURCE_USER_1’
‘GPG_ERR_SOURCE_USER_2’
‘GPG_ERR_SOURCE_USER_3’
‘GPG_ERR_SOURCE_USER_4’
     These error sources are not used by any GnuPG component and can be
     used by other software.  For example, applications using GPGME can
     use them to mark error values coming from callback handlers.  Thus
     ‘GPG_ERR_SOURCE_USER_1’ is the default for errors created with
     ‘gpgme_error’ and ‘gpgme_error_from_errno’, unless you define
     ‘GPGME_ERR_SOURCE_DEFAULT’ before including ‘gpgme.h’.


File: gpgme.info,  Node: Error Codes,  Next: Error Strings,  Prev: Error Sources,  Up: Error Handling

5.3 Error Codes
===============

The library ‘libgpg-error’ defines many error values.  Most of them are
not used by ‘GPGME’ directly, but might be returned by GPGME because it
received them from the crypto engine.  The below list only includes such
error codes that have a specific meaning in ‘GPGME’, or which are so
common that you should know about them.

‘GPG_ERR_EOF’
     This value indicates the end of a list, buffer or file.

‘GPG_ERR_NO_ERROR’
     This value indicates success.  The value of this error code is ‘0’.
     Also, it is guaranteed that an error value made from the error code
     ‘0’ will be ‘0’ itself (as a whole).  This means that the error
     source information is lost for this error code, however, as this
     error code indicates that no error occured, this is generally not a
     problem.

‘GPG_ERR_GENERAL’
     This value means that something went wrong, but either there is not
     enough information about the problem to return a more useful error
     value, or there is no separate error value for this type of
     problem.

‘GPG_ERR_ENOMEM’
     This value means that an out-of-memory condition occurred.

‘GPG_ERR_E...’
     System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
     the system error.

‘GPG_ERR_INV_VALUE’
     This value means that some user provided data was out of range.
     This can also refer to objects.  For example, if an empty
     ‘gpgme_data_t’ object was expected, but one containing data was
     provided, this error value is returned.

‘GPG_ERR_UNUSABLE_PUBKEY’
     This value means that some recipients for a message were invalid.

‘GPG_ERR_UNUSABLE_SECKEY’
     This value means that some signers were invalid.

‘GPG_ERR_NO_DATA’
     This value means that a ‘gpgme_data_t’ object which was expected to
     have content was found empty.

‘GPG_ERR_CONFLICT’
     This value means that a conflict of some sort occurred.

‘GPG_ERR_NOT_IMPLEMENTED’
     This value indicates that the specific function (or operation) is
     not implemented.  This error should never happen.  It can only
     occur if you use certain values or configuration options which do
     not work, but for which we think that they should work at some
     later time.

‘GPG_ERR_DECRYPT_FAILED’
     This value indicates that a decryption operation was unsuccessful.

‘GPG_ERR_BAD_PASSPHRASE’
     This value means that the user did not provide a correct passphrase
     when requested.

‘GPG_ERR_CANCELED’
     This value means that the operation was canceled.

‘GPG_ERR_INV_ENGINE’
     This value means that the engine that implements the desired
     protocol is currently not available.  This can either be because
     the sources were configured to exclude support for this engine, or
     because the engine is not installed properly.

‘GPG_ERR_AMBIGUOUS_NAME’
     This value indicates that a user ID or other specifier did not
     specify a unique key.

‘GPG_ERR_WRONG_KEY_USAGE’
     This value indicates that a key is not used appropriately.

‘GPG_ERR_CERT_REVOKED’
     This value indicates that a key signature was revoced.

‘GPG_ERR_CERT_EXPIRED’
     This value indicates that a key signature expired.

‘GPG_ERR_NO_CRL_KNOWN’
     This value indicates that no certificate revocation list is known
     for the certificate.

‘GPG_ERR_NO_POLICY_MATCH’
     This value indicates that a policy issue occured.

‘GPG_ERR_NO_SECKEY’
     This value indicates that no secret key for the user ID is
     available.

‘GPG_ERR_MISSING_CERT’
     This value indicates that a key could not be imported because the
     issuer certificate is missing.

‘GPG_ERR_BAD_CERT_CHAIN’
     This value indicates that a key could not be imported because its
     certificate chain is not good, for example it could be too long.

‘GPG_ERR_UNSUPPORTED_ALGORITHM’
     This value means a verification failed because the cryptographic
     algorithm is not supported by the crypto backend.

‘GPG_ERR_BAD_SIGNATURE’
     This value means a verification failed because the signature is
     bad.

‘GPG_ERR_NO_PUBKEY’
     This value means a verification failed because the public key is
     not available.

‘GPG_ERR_USER_1’
‘GPG_ERR_USER_2’
‘...’
‘GPG_ERR_USER_16’
     These error codes are not used by any GnuPG component and can be
     freely used by other software.  Applications using GPGME might use
     them to mark specific errors returned by callback handlers if no
     suitable error codes (including the system errors) for these errors
     exist already.


File: gpgme.info,  Node: Error Strings,  Prev: Error Codes,  Up: Error Handling

5.4 Error Strings
=================

 -- Function: const char * gpgme_strerror (gpgme_error_t ERR)
     The function ‘gpgme_strerror’ returns a pointer to a statically
     allocated string containing a description of the error code
     contained in the error value ERR.  This string can be used to
     output a diagnostic message to the user.

     This function is not thread safe.  Use ‘gpgme_strerror_r’ in
     multi-threaded programs.

 -- Function: int gpgme_strerror_r (gpgme_error_t ERR, char *BUF,
          size_t BUFLEN)
     The function ‘gpgme_strerror_r’ returns the error string for ERR in
     the user-supplied buffer BUF of size BUFLEN.  This function is, in
     contrast to ‘gpgme_strerror’, thread-safe if a thread-safe
     ‘strerror_r’ function is provided by the system.  If the function
     succeeds, 0 is returned and BUF contains the string describing the
     error.  If the buffer was not large enough, ERANGE is returned and
     BUF contains as much of the beginning of the error string as fits
     into the buffer.

 -- Function: const char * gpgme_strsource (gpgme_error_t ERR)
     The function ‘gpgme_strerror’ returns a pointer to a statically
     allocated string containing a description of the error source
     contained in the error value ERR.  This string can be used to
     output a diagnostic message to the user.

   The following example illustrates the use of ‘gpgme_strerror’:

     gpgme_ctx_t ctx;
     gpgme_error_t err = gpgme_new (&ctx);
     if (err)
       {
         fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
                  argv[0], gpgme_strsource (err), gpgme_strerror (err));
         exit (1);
       }


File: gpgme.info,  Node: Exchanging Data,  Next: Contexts,  Prev: Error Handling,  Up: Top

6 Exchanging Data
*****************

A lot of data has to be exchanged between the user and the crypto
engine, like plaintext messages, ciphertext, signatures and information
about the keys.  The technical details about exchanging the data
information are completely abstracted by GPGME.  The user provides and
receives the data via ‘gpgme_data_t’ objects, regardless of the
communication protocol between GPGME and the crypto engine in use.

 -- Data type: gpgme_data_t
     The ‘gpgme_data_t’ type is a handle for a container for generic
     data, which is used by GPGME to exchange data with the user.

   ‘gpgme_data_t’ objects do not provide notifications on events.  It is
assumed that read and write operations are blocking until data is
available.  If this is undesirable, the application must ensure that all
GPGME data operations always have data available, for example by using
memory buffers or files rather than pipes or sockets.  This might be
relevant, for example, if the external event loop mechanism is used.

 -- Data type: gpgme_off_t
     On POSIX platforms the ‘gpgme_off_t’ type is an alias for ‘off_t’;
     it may be used interchangeable.  On Windows platforms ‘gpgme_off_t’
     is defined as a long (i.e.  32 bit) for 32 bit Windows and as a 64
     bit signed integer for 64 bit Windows.

 -- Data type: gpgme_ssize_t
     The ‘gpgme_ssize_t’ type is an alias for ‘ssize_t’.  It has only
     been introduced to overcome portability problems pertaining to the
     declaration of ‘ssize_t’ by different toolchains.

* Menu:

* Creating Data Buffers::         Creating new data buffers.
* Destroying Data Buffers::       Releasing data buffers.
* Manipulating Data Buffers::     Operations on data buffers.


File: gpgme.info,  Node: Creating Data Buffers,  Next: Destroying Data Buffers,  Up: Exchanging Data

6.1 Creating Data Buffers
=========================

Data objects can be based on memory, files, or callback functions
provided by the user.  Not all operations are supported by all objects.

* Menu:

* Memory Based Data Buffers::     Creating memory based data buffers.
* File Based Data Buffers::       Creating file based data buffers.
* Callback Based Data Buffers::   Creating callback based data buffers.


File: gpgme.info,  Node: Memory Based Data Buffers,  Next: File Based Data Buffers,  Up: Creating Data Buffers

6.1.1 Memory Based Data Buffers
-------------------------------

Memory based data objects store all data in allocated memory.  This is
convenient, but only practical for an amount of data that is a fraction
of the available physical memory.  The data has to be copied from its
source and to its destination, which can often be avoided by using one
of the other data object

 -- Function: gpgme_error_t gpgme_data_new (gpgme_data_t *DH)
     The function ‘gpgme_data_new’ creates a new ‘gpgme_data_t’ object
     and returns a handle for it in DH.  The data object is memory based
     and initially empty.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the data
     object was successfully created, ‘GPG_ERR_INV_VALUE’ if DH is not a
     valid pointer, and ‘GPG_ERR_ENOMEM’ if not enough memory is
     available.

 -- Function: gpgme_error_t gpgme_data_new_from_mem (gpgme_data_t *DH,
          const char *BUFFER, size_t SIZE, int COPY)
     The function ‘gpgme_data_new_from_mem’ creates a new ‘gpgme_data_t’
     object and fills it with SIZE bytes starting from BUFFER.

     If COPY is not zero, a private copy of the data is made.  If COPY
     is zero, the data is taken from the specified buffer as needed, and
     the user has to ensure that the buffer remains valid for the whole
     life span of the data object.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the data
     object was successfully created, ‘GPG_ERR_INV_VALUE’ if DH or
     BUFFER is not a valid pointer, and ‘GPG_ERR_ENOMEM’ if not enough
     memory is available.

 -- Function: gpgme_error_t gpgme_data_new_from_file (gpgme_data_t *DH,
          const char *FILENAME, int COPY)
     The function ‘gpgme_data_new_from_file’ creates a new
     ‘gpgme_data_t’ object and fills it with the content of the file
     FILENAME.

     If COPY is not zero, the whole file is read in at initialization
     time and the file is not used anymore after that.  This is the only
     mode supported currently.  Later, a value of zero for COPY might
     cause all reads to be delayed until the data is needed, but this is
     not yet implemented.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the data
     object was successfully created, ‘GPG_ERR_INV_VALUE’ if DH or
     FILENAME is not a valid pointer, ‘GPG_ERR_NOT_IMPLEMENTED’ if CODE
     is zero, and ‘GPG_ERR_ENOMEM’ if not enough memory is available.

 -- Function: gpgme_error_t gpgme_data_new_from_filepart
          (gpgme_data_t *DH, const char *FILENAME, FILE *FP,
          off_t OFFSET, size_t LENGTH)
     The function ‘gpgme_data_new_from_filepart’ creates a new
     ‘gpgme_data_t’ object and fills it with a part of the file
     specified by FILENAME or FP.

     Exactly one of FILENAME and FP must be non-zero, the other must be
     zero.  The argument that is not zero specifies the file from which
     LENGTH bytes are read into the data object, starting from OFFSET.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the data
     object was successfully created, ‘GPG_ERR_INV_VALUE’ if DH and
     exactly one of FILENAME and FP is not a valid pointer, and
     ‘GPG_ERR_ENOMEM’ if not enough memory is available.


File: gpgme.info,  Node: File Based Data Buffers,  Next: Callback Based Data Buffers,  Prev: Memory Based Data Buffers,  Up: Creating Data Buffers

6.1.2 File Based Data Buffers
-----------------------------

File based data objects operate directly on file descriptors or streams.
Only a small amount of data is stored in core at any time, so the size
of the data objects is not limited by GPGME.

 -- Function: gpgme_error_t gpgme_data_new_from_fd (gpgme_data_t *DH,
          int FD)
     The function ‘gpgme_data_new_from_fd’ creates a new ‘gpgme_data_t’
     object and uses the file descriptor FD to read from (if used as an
     input data object) and write to (if used as an output data object).

     When using the data object as an input buffer, the function might
     read a bit more from the file descriptor than is actually needed by
     the crypto engine in the desired operation because of internal
     buffering.

     Note that GPGME assumes that the file descriptor is set to blocking
     mode.  Errors during I/O operations, except for EINTR, are usually
     fatal for crypto operations.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the data
     object was successfully created, and ‘GPG_ERR_ENOMEM’ if not enough
     memory is available.

 -- Function: gpgme_error_t gpgme_data_new_from_stream
          (gpgme_data_t *DH, FILE *STREAM)
     The function ‘gpgme_data_new_from_stream’ creates a new
     ‘gpgme_data_t’ object and uses the I/O stream STREAM to read from
     (if used as an input data object) and write to (if used as an
     output data object).

     When using the data object as an input buffer, the function might
     read a bit more from the stream than is actually needed by the
     crypto engine in the desired operation because of internal
     buffering.

     Note that GPGME assumes that the stream is in blocking mode.
     Errors during I/O operations, except for EINTR, are usually fatal
     for crypto operations.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the data
     object was successfully created, and ‘GPG_ERR_ENOMEM’ if not enough
     memory is available.


File: gpgme.info,  Node: Callback Based Data Buffers,  Prev: File Based Data Buffers,  Up: Creating Data Buffers

6.1.3 Callback Based Data Buffers
---------------------------------

If neither memory nor file based data objects are a good fit for your
application, you can implement the functions a data object provides
yourself and create a data object from these callback functions.

 -- Data type: ssize_t (*gpgme_data_read_cb_t) (void *HANDLE,
          void *BUFFER, size_t SIZE)
     The ‘gpgme_data_read_cb_t’ type is the type of functions which
     GPGME calls if it wants to read data from a user-implemented data
     object.  The function should read up to SIZE bytes from the current
     read position into the space starting at BUFFER.  The HANDLE is
     provided by the user at data object creation time.

     Note that GPGME assumes that the read blocks until data is
     available.  Errors during I/O operations, except for EINTR, are
     usually fatal for crypto operations.

     The function should return the number of bytes read, 0 on EOF, and
     -1 on error.  If an error occurs, ERRNO should be set to describe
     the type of the error.

 -- Data type: ssize_t (*gpgme_data_write_cb_t) (void *HANDLE,
          const void *BUFFER, size_t SIZE)
     The ‘gpgme_data_write_cb_t’ type is the type of functions which
     GPGME calls if it wants to write data to a user-implemented data
     object.  The function should write up to SIZE bytes to the current
     write position from the space starting at BUFFER.  The HANDLE is
     provided by the user at data object creation time.

     Note that GPGME assumes that the write blocks until data is
     available.  Errors during I/O operations, except for EINTR, are
     usually fatal for crypto operations.

     The function should return the number of bytes written, and -1 on
     error.  If an error occurs, ERRNO should be set to describe the
     type of the error.

 -- Data type: off_t (*gpgme_data_seek_cb_t) (void *HANDLE,
          off_t OFFSET, int WHENCE)
     The ‘gpgme_data_seek_cb_t’ type is the type of functions which
     GPGME calls if it wants to change the current read/write position
     in a user-implemented data object, just like the ‘lseek’ function.

     The function should return the new read/write position, and -1 on
     error.  If an error occurs, ERRNO should be set to describe the
     type of the error.

 -- Data type: void (*gpgme_data_release_cb_t) (void *HANDLE)
     The ‘gpgme_data_release_cb_t’ type is the type of functions which
     GPGME calls if it wants to destroy a user-implemented data object.
     The HANDLE is provided by the user at data object creation time.

 -- Data type: struct gpgme_data_cbs
     This structure is used to store the data callback interface
     functions described above.  It has the following members:

     ‘gpgme_data_read_cb_t read’
          This is the function called by GPGME to read data from the
          data object.  It is only required for input data object.

     ‘gpgme_data_write_cb_t write’
          This is the function called by GPGME to write data to the data
          object.  It is only required for output data object.

     ‘gpgme_data_seek_cb_t seek’
          This is the function called by GPGME to change the current
          read/write pointer in the data object (if available).  It is
          optional.

     ‘gpgme_data_release_cb_t release’
          This is the function called by GPGME to release a data object.
          It is optional.

 -- Function: gpgme_error_t gpgme_data_new_from_cbs (gpgme_data_t *DH,
          gpgme_data_cbs_t CBS, void *HANDLE)
     The function ‘gpgme_data_new_from_cbs’ creates a new ‘gpgme_data_t’
     object and uses the user-provided callback functions to operate on
     the data object.

     The handle HANDLE is passed as first argument to the callback
     functions.  This can be used to identify this data object.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the data
     object was successfully created, and ‘GPG_ERR_ENOMEM’ if not enough
     memory is available.


File: gpgme.info,  Node: Destroying Data Buffers,  Next: Manipulating Data Buffers,  Prev: Creating Data Buffers,  Up: Exchanging Data

6.2 Destroying Data Buffers
===========================

 -- Function: void gpgme_data_release (gpgme_data_t DH)
     The function ‘gpgme_data_release’ destroys the data object with the
     handle DH.  It releases all associated resources that were not
     provided by the user in the first place.

 -- Function: char * gpgme_data_release_and_get_mem (gpgme_data_t DH,
          size_t *LENGTH)
     The function ‘gpgme_data_release_and_get_mem’ is like
     ‘gpgme_data_release’, except that it returns the data buffer and
     its length that was provided by the object.

     The user has to release the buffer with ‘gpgme_free’.  In case the
     user provided the data buffer in non-copy mode, a copy will be made
     for this purpose.

     In case an error returns, or there is no suitable data buffer that
     can be returned to the user, the function will return ‘NULL’.  In
     any case, the data object DH is destroyed.

 -- Function: void gpgme_free (void *BUFFER)
     The function ‘gpgme_free’ releases the memory returned by
     ‘gpgme_data_release_and_get_mem’ and ‘gpgme_pubkey_algo_string’.
     It should be used instead of the system libraries ‘free’ function
     in case different allocators are used by a program.  This is often
     the case if gpgme is used under Windows as a DLL.


File: gpgme.info,  Node: Manipulating Data Buffers,  Prev: Destroying Data Buffers,  Up: Exchanging Data

6.3 Manipulating Data Buffers
=============================

Data buffers contain data and meta-data.  The following operations can
be used to manipulate both.

* Menu:

* Data Buffer I/O Operations::    I/O operations on data buffers.
* Data Buffer Meta-Data::         Meta-data manipulation of data buffers.
* Data Buffer Convenience::       Convenience function for data buffers.


File: gpgme.info,  Node: Data Buffer I/O Operations,  Next: Data Buffer Meta-Data,  Up: Manipulating Data Buffers

6.3.1 Data Buffer I/O Operations
--------------------------------

 -- Function: ssize_t gpgme_data_read (gpgme_data_t DH, void *BUFFER,
          size_t LENGTH)
     The function ‘gpgme_data_read’ reads up to LENGTH bytes from the
     data object with the handle DH into the space starting at BUFFER.

     If no error occurs, the actual amount read is returned.  If the end
     of the data object is reached, the function returns 0.

     In all other cases, the function returns -1 and sets ERRNO.

 -- Function: ssize_t gpgme_data_write (gpgme_data_t DH,
          const void *BUFFER, size_t SIZE)
     The function ‘gpgme_data_write’ writes up to SIZE bytes starting
     from BUFFER into the data object with the handle DH at the current
     write position.

     The function returns the number of bytes actually written, or -1 if
     an error occurs.  If an error occurs, ERRNO is set.

 -- Function: off_t gpgme_data_seek (gpgme_data_t DH, off_t OFFSET,
          int WHENCE)
     The function ‘gpgme_data_seek’ changes the current read/write
     position.

     The WHENCE argument specifies how the OFFSET should be interpreted.
     It must be one of the following symbolic constants:

     ‘SEEK_SET’
          Specifies that OFFSET is a count of characters from the
          beginning of the data object.

     ‘SEEK_CUR’
          Specifies that OFFSET is a count of characters from the
          current file position.  This count may be positive or
          negative.

     ‘SEEK_END’
          Specifies that OFFSET is a count of characters from the end of
          the data object.  A negative count specifies a position within
          the current extent of the data object; a positive count
          specifies a position past the current end.  If you set the
          position past the current end, and actually write data, you
          will extend the data object with zeros up to that position.

     If successful, the function returns the resulting file position,
     measured in bytes from the beginning of the data object.  You can
     use this feature together with ‘SEEK_CUR’ to read the current
     read/write position.

     If the function fails, -1 is returned and ERRNO is set.


File: gpgme.info,  Node: Data Buffer Meta-Data,  Next: Data Buffer Convenience,  Prev: Data Buffer I/O Operations,  Up: Manipulating Data Buffers

6.3.2 Data Buffer Meta-Data
---------------------------

 -- Function: char * gpgme_data_get_file_name (gpgme_data_t DH)
     The function ‘gpgme_data_get_file_name’ returns a pointer to a
     string containing the file name associated with the data object.
     The file name will be stored in the output when encrypting or
     signing the data and will be returned to the user when decrypting
     or verifying the output data.

     If no error occurs, the string containing the file name is
     returned.  Otherwise, ‘NULL’ will be returned.

 -- Function: gpgme_error_t gpgme_data_set_file_name (gpgme_data_t DH,
          const char *FILE_NAME)
     The function ‘gpgme_data_set_file_name’ sets the file name
     associated with the data object.  The file name will be stored in
     the output when encrypting or signing the data and will be returned
     to the user when decrypting or verifying the output data.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if DH is
     not a valid pointer and ‘GPG_ERR_ENOMEM’ if not enough memory is
     available.

 -- Data type: enum gpgme_data_encoding_t
     The ‘gpgme_data_encoding_t’ type specifies the encoding of a
     ‘gpgme_data_t’ object.  For input data objects, the encoding is
     useful to give the backend a hint on the type of data.  For output
     data objects, the encoding can specify the output data format on
     certain operations.  Please note that not all backends support all
     encodings on all operations.  The following data types are
     available:

     ‘GPGME_DATA_ENCODING_NONE’
          This specifies that the encoding is not known.  This is the
          default for a new data object.  The backend will try its best
          to detect the encoding automatically.

     ‘GPGME_DATA_ENCODING_BINARY’
          This specifies that the data is encoding in binary form; i.e.
          there is no special encoding.

     ‘GPGME_DATA_ENCODING_BASE64’
          This specifies that the data is encoded using the Base-64
          encoding scheme as used by MIME and other protocols.

     ‘GPGME_DATA_ENCODING_ARMOR’
          This specifies that the data is encoded in an armored form as
          used by OpenPGP and PEM.

     ‘GPGME_DATA_ENCODING_MIME’
          This specifies that the data is encoded as a MIME part.

     ‘GPGME_DATA_ENCODING_URL’
          The data is a list of linefeed delimited URLs.  This is only
          useful with ‘gpgme_op_import’.

     ‘GPGME_DATA_ENCODING_URL0’
          The data is a list of binary zero delimited URLs.  This is
          only useful with ‘gpgme_op_import’.

     ‘GPGME_DATA_ENCODING_URLESC’
          The data is a list of linefeed delimited URLs with all control
          and space characters percent escaped.  This mode is is not yet
          implemented.

 -- Function: gpgme_data_encoding_t gpgme_data_get_encoding
          (gpgme_data_t DH)
     The function ‘gpgme_data_get_encoding’ returns the encoding of the
     data object with the handle DH.  If DH is not a valid pointer (e.g.
     ‘NULL’) ‘GPGME_DATA_ENCODING_NONE’ is returned.

 -- Function: gpgme_error_t gpgme_data_set_encoding
          (gpgme_data_t DH, gpgme_data_encoding_t ENC)
     The function ‘gpgme_data_set_encoding’ changes the encoding of the
     data object with the handle DH to ENC.

 -- Function: gpgme_error_t gpgme_data_set_flag (gpgme_data_t DH,
          const char *NAME, const char *VALUE)

     Some minor properties of the data object can be controlled with
     flags set by this function.  The properties are identified by the
     following values for NAME:

     ‘size-hint’
          The value is a decimal number with the length gpgme shall
          assume for this data object.  This is useful if the data is
          provided by callbacks or via file descriptors but the
          applications knows the total size of the data.  If this is set
          the OpenPGP engine may use this to decide on buffer allocation
          strategies and to provide a total value for its progress
          information.

     This function returns ‘0’ on success.


File: gpgme.info,  Node: Data Buffer Convenience,  Prev: Data Buffer Meta-Data,  Up: Manipulating Data Buffers

6.3.3 Data Buffer Convenience Functions
---------------------------------------

 -- Data type: enum gpgme_data_type_t
     The ‘gpgme_data_type_t’ type is used to return the detected type of
     the content of a data buffer.

‘GPGME_DATA_TYPE_INVALID’
     This is returned by ‘gpgme_data_identify’ if it was not possible to
     identify the data.  Reasons for this might be a non-seekable stream
     or a memory problem.  The value is 0.
‘GPGME_DATA_TYPE_UNKNOWN’
     The type of the data is not known.
‘GPGME_DATA_TYPE_PGP_SIGNED’
     The data is an OpenPGP signed message.  This may be a binary
     signature, a detached one or a cleartext signature.
‘GPGME_DATA_TYPE_PGP_OTHER’
     This is a generic OpenPGP message.  In most cases this will be
     encrypted data.
‘GPGME_DATA_TYPE_PGP_KEY’
     This is an OpenPGP key (private or public).
‘GPGME_DATA_TYPE_CMS_SIGNED’
     This is a CMS signed message.
‘GPGME_DATA_TYPE_CMS_ENCRYPTED’
     This is a CMS encrypted (enveloped data) message.
‘GPGME_DATA_TYPE_CMS_OTHER’
     This is used for other CMS message types.
‘GPGME_DATA_TYPE_X509_CERT’
     The data is a X.509 certificate
‘GPGME_DATA_TYPE_PKCS12’
     The data is a PKCS#12 message.  This is commonly used to exchange
     private keys for X.509.

 -- Function: gpgme_data_type_t gpgme_data_identify (gpgme_data_t DH)
     The function ‘gpgme_data_identify’ returns the type of the data
     with the handle DH.  If it is not possible to perform the
     identification, the function returns zero
     (‘GPGME_DATA_TYPE_INVALID’).  Note that depending on how the data
     object has been created the identification may not be possible or
     the data object may change its internal state (file pointer moved).
     For file or memory based data object, the state should not change.


File: gpgme.info,  Node: Contexts,  Next: UI Server Protocol,  Prev: Exchanging Data,  Up: Top

7 Contexts
**********

All cryptographic operations in GPGME are performed within a context,
which contains the internal state of the operation as well as
configuration parameters.  By using several contexts you can run several
cryptographic operations in parallel, with different configuration.

 -- Data type: gpgme_ctx_t
     The ‘gpgme_ctx_t’ type is a handle for a GPGME context, which is
     used to hold the configuration, status and result of cryptographic
     operations.

* Menu:

* Creating Contexts::             Creating new GPGME contexts.
* Destroying Contexts::           Releasing GPGME contexts.
* Result Management::             Managing the result of crypto operations.
* Context Attributes::            Setting properties of a context.
* Key Management::                Managing keys with GPGME.
* Trust Item Management::         Managing trust items with GPGME.
* Crypto Operations::             Using a context for cryptography.
* Miscellaneous::                 Miscellaneous operations
* Run Control::                   Controlling how operations are run.


File: gpgme.info,  Node: Creating Contexts,  Next: Destroying Contexts,  Up: Contexts

7.1 Creating Contexts
=====================

 -- Function: gpgme_error_t gpgme_new (gpgme_ctx_t *CTX)
     The function ‘gpgme_new’ creates a new ‘gpgme_ctx_t’ object and
     returns a handle for it in CTX.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     context was successfully created, ‘GPG_ERR_INV_VALUE’ if CTX is not
     a valid pointer, and ‘GPG_ERR_ENOMEM’ if not enough memory is
     available.  Also, it returns ‘GPG_ERR_NOT_OPERATIONAL’ if
     ‘gpgme_check_version’ was not called to initialize GPGME, and
     ‘GPG_ERR_SELFTEST_FAILED’ if a selftest failed.  Currently, the
     only selftest is for Windows MingW32 targets to see if
     ‘-mms-bitfields’ was used (as required).


File: gpgme.info,  Node: Destroying Contexts,  Next: Result Management,  Prev: Creating Contexts,  Up: Contexts

7.2 Destroying Contexts
=======================

 -- Function: void gpgme_release (gpgme_ctx_t CTX)
     The function ‘gpgme_release’ destroys the context with the handle
     CTX and releases all associated resources.


File: gpgme.info,  Node: Result Management,  Next: Context Attributes,  Prev: Destroying Contexts,  Up: Contexts

7.3 Result Management
=====================

The detailed result of an operation is returned in operation-specific
structures such as ‘gpgme_decrypt_result_t’.  The corresponding
retrieval functions such as ‘gpgme_op_decrypt_result’ provide static
access to the results after an operation completes.  Those structures
shall be considered read-only and an application must not allocate such
a structure on its own.  The following interfaces make it possible to
detach a result structure from its associated context and give it a
lifetime beyond that of the current operation or context.

 -- Function: void gpgme_result_ref (void *RESULT)
     The function ‘gpgme_result_ref’ acquires an additional reference
     for the result RESULT, which may be of any type ‘gpgme_*_result_t’.
     As long as the user holds a reference, the result structure is
     guaranteed to be valid and unmodified.

 -- Function: void gpgme_result_unref (void *RESULT)
     The function ‘gpgme_result_unref’ releases a reference for the
     result RESULT.  If this was the last reference, the result
     structure will be destroyed and all resources associated to it will
     be released.

   Note that a context may hold its own references to result structures,
typically until the context is destroyed or the next operation is
started.  In fact, these references are accessed through the
‘gpgme_op_*_result’ functions.


File: gpgme.info,  Node: Context Attributes,  Next: Key Management,  Prev: Result Management,  Up: Contexts

7.4 Context Attributes
======================

* Menu:

* Protocol Selection::            Selecting the protocol used by a context.
* Crypto Engine::                 Configuring the crypto engine.
* Setting the Sender::            How to tell the engine the sender.
* ASCII Armor::                   Requesting ASCII armored output.
* Text Mode::                     Choosing canonical text mode.
* Offline Mode::                  Choosing offline mode.
* Pinentry Mode::                 Choosing the pinentry mode.
* Included Certificates::         Including a number of certificates.
* Key Listing Mode::              Selecting key listing mode.
* Passphrase Callback::           Getting the passphrase from the user.
* Progress Meter Callback::       Being informed about the progress.
* Status Message Callback::       Status messages received from gpg.
* Locale::                        Setting the locale of a context.


File: gpgme.info,  Node: Protocol Selection,  Next: Crypto Engine,  Up: Context Attributes

7.4.1 Protocol Selection
------------------------

 -- Function: gpgme_error_t gpgme_set_protocol (gpgme_ctx_t CTX,
          gpgme_protocol_t PROTO)
     The function ‘gpgme_set_protocol’ sets the protocol used within the
     context CTX to PROTO.  All crypto operations will be performed by
     the crypto engine configured for that protocol.  *Note Protocols
     and Engines::.

     Setting the protocol with ‘gpgme_set_protocol’ does not check if
     the crypto engine for that protocol is available and installed
     correctly.  *Note Engine Version Check::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     protocol could be set successfully, and ‘GPG_ERR_INV_VALUE’ if
     PROTOCOL is not a valid protocol.

 -- Function: gpgme_protocol_t gpgme_get_protocol (gpgme_ctx_t CTX)
     The function ‘gpgme_get_protocol’ retrieves the protocol currently
     use with the context CTX.


File: gpgme.info,  Node: Crypto Engine,  Next: Setting the Sender,  Prev: Protocol Selection,  Up: Context Attributes

7.4.2 Crypto Engine
-------------------

The following functions can be used to set and retrieve the
configuration of the crypto engines of a specific context.  The default
can also be retrieved without any particular context.  *Note Engine
Information::.  The default can also be changed globally.  *Note Engine
Configuration::.

 -- Function: gpgme_engine_info_t gpgme_ctx_get_engine_info
          (gpgme_ctx_t CTX)
     The function ‘gpgme_ctx_get_engine_info’ returns a linked list of
     engine info structures.  Each info structure describes the
     configuration of one configured backend, as used by the context
     CTX.

     The result is valid until the next invocation of
     ‘gpgme_ctx_set_engine_info’ for this particular context.

     This function can not fail.

 -- Function: gpgme_error_t gpgme_ctx_set_engine_info (gpgme_ctx_t CTX,
          gpgme_protocol_t PROTO, const char *FILE_NAME,
          const char *HOME_DIR)
     The function ‘gpgme_ctx_set_engine_info’ changes the configuration
     of the crypto engine implementing the protocol PROTO for the
     context CTX.

     FILE_NAME is the file name of the executable program implementing
     this protocol, and HOME_DIR is the directory name of the
     configuration directory for this crypto engine.  If HOME_DIR is
     ‘NULL’, the engine’s default will be used.

     Currently this function must be used before starting the first
     crypto operation.  It is unspecified if and when the changes will
     take effect if the function is called after starting the first
     operation on the context CTX.

     This function returns the error code ‘GPG_ERR_NO_ERROR’ if
     successful, or an eror code on failure.


File: gpgme.info,  Node: Setting the Sender,  Next: ASCII Armor,  Prev: Crypto Engine,  Up: Context Attributes

7.4.3 How to tell the engine the sender.
----------------------------------------

Some engines can make use of the sender’s address, for example to figure
out the best user id in certain trust models.  For verification and
signing of mails, it is thus suggested to let the engine know the sender
("From:") address.  GPGME provides two functions to accomplish that.
Note that the esoteric use of multiple "From:" addresses is not
supported.

 -- Function: gpgme_error_t gpgme_set_sender (gpgme_ctx_t CTX,
          int ADDRESS)

     The function ‘gpgme_set_sender’ specifies the sender address for
     use in sign and verify operations.  ADDRESS is expected to be the
     “addr-spec” part of an address but my also be a complete mailbox
     address, in which case this function extracts the “addr-spec” from
     it.  Using ‘NULL’ for ADDRESS clears the sender address.

     The function returns 0 on success or an error code on failure.  The
     most likely failure is that no valid “addr-spec” was found in
     ADDRESS.

 -- Function: const char * gpgme_get_sender (gpgme_ctx_t CTX)

     The function ‘gpgme_get_sender’ returns the current sender address
     from the context, or NULL if none was set.  The returned value is
     valid as long as the CTX is valid and ‘gpgme_set_sender’ has not
     been called again.


File: gpgme.info,  Node: ASCII Armor,  Next: Text Mode,  Prev: Setting the Sender,  Up: Context Attributes

7.4.4 ASCII Armor
-----------------

 -- Function: void gpgme_set_armor (gpgme_ctx_t CTX, int YES)
     The function ‘gpgme_set_armor’ specifies if the output should be
     ASCII armored.  By default, output is not ASCII armored.

     ASCII armored output is disabled if YES is zero, and enabled
     otherwise.

 -- Function: int gpgme_get_armor (gpgme_ctx_t CTX)
     The function ‘gpgme_get_armor’ returns 1 if the output is ASCII
     armored, and ‘0’ if it is not, or if CTX is not a valid pointer.


File: gpgme.info,  Node: Text Mode,  Next: Offline Mode,  Prev: ASCII Armor,  Up: Context Attributes

7.4.5 Text Mode
---------------

 -- Function: void gpgme_set_textmode (gpgme_ctx_t CTX, int YES)
     The function ‘gpgme_set_textmode’ specifies if canonical text mode
     should be used.  By default, text mode is not used.

     Text mode is for example used for the RFC2015 signatures; note that
     the updated RFC 3156 mandates that the mail user agent does some
     preparations so that text mode is not needed anymore.

     This option is only relevant to the OpenPGP crypto engine, and
     ignored by all other engines.

     Canonical text mode is disabled if YES is zero, and enabled
     otherwise.

 -- Function: int gpgme_get_textmode (gpgme_ctx_t CTX)
     The function ‘gpgme_get_textmode’ returns 1 if canonical text mode
     is enabled, and ‘0’ if it is not, or if CTX is not a valid pointer.


File: gpgme.info,  Node: Offline Mode,  Next: Pinentry Mode,  Prev: Text Mode,  Up: Context Attributes

7.4.6 Offline Mode
------------------

 -- Function: void gpgme_set_offline (gpgme_ctx_t CTX, int YES)
     The function ‘gpgme_set_offline’ specifies if offline mode should
     be used.  By default, offline mode is not used.

     The offline mode specifies if dirmngr should be used to do
     additional validation that might require connections to external
     services.  (e.g.  CRL / OCSP checks).

     Offline mode only affects the keylist mode
     ‘GPGME_KEYLIST_MODE_VALIDATE’ and is only relevant to the CMS
     crypto engine.  Offline mode is ignored otherwise.

     This option may be extended in the future to completely disable the
     use of dirmngr for any engine.

     Offline mode is disabled if YES is zero, and enabled otherwise.

 -- Function: int gpgme_get_offline (gpgme_ctx_t CTX)
     The function ‘gpgme_get_offline’ returns 1 if offline mode is
     enabled, and ‘0’ if it is not, or if CTX is not a valid pointer.


File: gpgme.info,  Node: Pinentry Mode,  Next: Included Certificates,  Prev: Offline Mode,  Up: Context Attributes

7.4.7 Pinentry Mode
-------------------

 -- Function: gpgme_error_t gpgme_set_pinentry_mode (gpgme_ctx_t CTX,
     gpgme_pinentry_mode_t MODE) The function ‘gpgme_set_pinentry_mode’
     specifies the pinentry mode to be used.

     For GnuPG >= 2.1 this option is required to be set to
     ‘GPGME_PINENTRY_MODE_LOOPBACK’ to enable the passphrase callback
     mechanism in GPGME through ‘gpgme_set_passphrase_cb’.

 -- Function: gpgme_pinentry_mode_t gpgme_get_pinentry_mode
          (gpgme_ctx_t CTX)
     The function ‘gpgme_get_pinenty_mode’ returns the mode set for the
     context.

 -- Data type: enum gpgme_pinentry_mode_t
     The ‘gpgme_minentry_mode_t’ type specifies the set of possible
     pinentry modes that are supported by GPGME if GnuPG >= 2.1 is used.
     The following modes are supported:

     ‘GPGME_PINENTRY_MODE_DEFAULT’
          Use the default of the agent, which is ask.

     ‘GPGME_PINENTRY_MODE_ASK’
          Force the use of the Pinentry.

     ‘GPGME_PINENTRY_MODE_CANCEL’
          Emulate use of Pinentry’s cancel button.

     ‘GPGME_PINENTRY_MODE_ERROR’
          Return a Pinentry error ‘No Pinentry’.

     ‘GPGME_PINENTRY_MODE_LOOPBACK’
          Redirect Pinentry queries to the caller.  This enables the use
          of ‘gpgme_set_passphrase_cb’ whis pinentry queries redirected
          to gpgme.

          Note: This mode requires ‘allow-loopback-pinentry’ to be
          enabled in the ‘gpg-agent.conf’ or an agent started with that
          option.


File: gpgme.info,  Node: Included Certificates,  Next: Key Listing Mode,  Prev: Pinentry Mode,  Up: Context Attributes

7.4.8 Included Certificates
---------------------------

 -- Function: void gpgme_set_include_certs (gpgme_ctx_t CTX,
          int NR_OF_CERTS)
     The function ‘gpgme_set_include_certs’ specifies how many
     certificates should be included in an S/MIME signed message.  By
     default, only the sender’s certificate is included.  The possible
     values of NR_OF_CERTS are:

     ‘GPGME_INCLUDE_CERTS_DEFAULT’
          Fall back to the default of the crypto backend.  This is the
          default for GPGME.
     ‘-2’
          Include all certificates except the root certificate.
     ‘-1’
          Include all certificates.
     ‘0’
          Include no certificates.
     ‘1’
          Include the sender’s certificate only.
     ‘n’
          Include the first n certificates of the certificates path,
          starting from the sender’s certificate.  The number ‘n’ must
          be positive.

     Values of NR_OF_CERTS smaller than -2 are undefined.

     This option is only relevant to the CMS crypto engine, and ignored
     by all other engines.

 -- Function: int gpgme_get_include_certs (gpgme_ctx_t CTX)
     The function ‘gpgme_get_include_certs’ returns the number of
     certificates to include into an S/MIME signed message.


File: gpgme.info,  Node: Key Listing Mode,  Next: Passphrase Callback,  Prev: Included Certificates,  Up: Context Attributes

7.4.9 Key Listing Mode
----------------------

 -- Function: gpgme_error_t gpgme_set_keylist_mode (gpgme_ctx_t CTX,
          gpgme_keylist_mode_t MODE)
     The function ‘gpgme_set_keylist_mode’ changes the default behaviour
     of the key listing functions.  The value in MODE is a bitwise-or
     combination of one or multiple of the following bit values:

     ‘GPGME_KEYLIST_MODE_LOCAL’
          The ‘GPGME_KEYLIST_MODE_LOCAL’ symbol specifies that the local
          keyring should be searched for keys in the keylisting
          operation.  This is the default.

     ‘GPGME_KEYLIST_MODE_EXTERN’
          The ‘GPGME_KEYLIST_MODE_EXTERN’ symbol specifies that an
          external source should be searched for keys in the keylisting
          operation.  The type of external source is dependant on the
          crypto engine used and whether it is combined with
          ‘GPGME_KEYLIST_MODE_LOCAL’.  For example, it can be a remote
          keyserver or LDAP certificate server.

     ‘GPGME_KEYLIST_MODE_SIGS’
          The ‘GPGME_KEYLIST_MODE_SIGS’ symbol specifies that the key
          signatures should be included in the listed keys.

     ‘GPGME_KEYLIST_MODE_SIG_NOTATIONS’
          The ‘GPGME_KEYLIST_MODE_SIG_NOTATIONS’ symbol specifies that
          the signature notations on key signatures should be included
          in the listed keys.  This only works if
          ‘GPGME_KEYLIST_MODE_SIGS’ is also enabled.

     ‘GPGME_KEYLIST_MODE_WITH_TOFU’
          The ‘GPGME_KEYLIST_MODE_WITH_TOFU’ symbol specifies that
          information pertaining to the TOFU trust model should be
          included in the listed keys.

     ‘GPGME_KEYLIST_MODE_WITH_SECRET’
          The ‘GPGME_KEYLIST_MODE_WITH_SECRET’ returns information about
          the presence of a corresponding secret key in a public key
          listing.  A public key listing with this mode is slower than a
          standard listing but can be used instead of a second run to
          list the secret keys.  This is only supported for GnuPG
          versions >= 2.1.

     ‘GPGME_KEYLIST_MODE_EPHEMERAL’
          The ‘GPGME_KEYLIST_MODE_EPHEMERAL’ symbol specifies that keys
          flagged as ephemeral are included in the listing.

     ‘GPGME_KEYLIST_MODE_VALIDATE’
          The ‘GPGME_KEYLIST_MODE_VALIDATE’ symbol specifies that the
          backend should do key or certificate validation and not just
          get the validity information from an internal cache.  This
          might be an expensive operation and is in general not useful.
          Currently only implemented for the S/MIME backend and ignored
          for other backends.

     At least one of ‘GPGME_KEYLIST_MODE_LOCAL’ and
     ‘GPGME_KEYLIST_MODE_EXTERN’ must be specified.  For future binary
     compatibility, you should get the current mode with
     ‘gpgme_get_keylist_mode’ and modify it by setting or clearing the
     appropriate bits, and then using that calculated value in the
     ‘gpgme_set_keylisting_mode’ operation.  This will leave all other
     bits in the mode value intact (in particular those that are not
     used in the current version of the library).

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the mode
     could be set correctly, and ‘GPG_ERR_INV_VALUE’ if CTX is not a
     valid pointer or MODE is not a valid mode.

 -- Function: gpgme_keylist_mode_t gpgme_get_keylist_mode
          (gpgme_ctx_t CTX)
     The function ‘gpgme_get_keylist_mode’ returns the current key
     listing mode of the context CTX.  This value can then be modified
     and used in a subsequent ‘gpgme_set_keylist_mode’ operation to only
     affect the desired bits (and leave all others intact).

     The function returns 0 if CTX is not a valid pointer, and the
     current mode otherwise.  Note that 0 is not a valid mode value.


File: gpgme.info,  Node: Passphrase Callback,  Next: Progress Meter Callback,  Prev: Key Listing Mode,  Up: Context Attributes

7.4.10 Passphrase Callback
--------------------------

 -- Data type: gpgme_error_t (*gpgme_passphrase_cb_t)(void *HOOK, const
          char *UID_HINT, const char *PASSPHRASE_INFO, int PREV_WAS_BAD,
          int FD)
     The ‘gpgme_passphrase_cb_t’ type is the type of functions usable as
     passphrase callback function.

     The argument UID_HINT might contain a string that gives an
     indication for which user ID the passphrase is required.  If this
     is not available, or not applicable (in the case of symmetric
     encryption, for example), UID_HINT will be ‘NULL’.

     The argument PASSPHRASE_INFO, if not ‘NULL’, will give further
     information about the context in which the passphrase is required.
     This information is engine and operation specific.

     If this is the repeated attempt to get the passphrase, because
     previous attempts failed, then PREV_WAS_BAD is 1, otherwise it will
     be 0.

     The user must write the passphrase, followed by a newline
     character, to the file descriptor FD.  The function
     ‘gpgme_io_writen’ should be used for the write operation.  Note
     that if the user returns 0 to indicate success, the user must at
     least write a newline character before returning from the callback.

     If an error occurs, return the corresponding ‘gpgme_error_t’ value.
     You can use the error code ‘GPG_ERR_CANCELED’ to abort the
     operation.  Otherwise, return ‘0’.

 -- Function: void gpgme_set_passphrase_cb (gpgme_ctx_t CTX,
          gpgme_passphrase_cb_t PASSFUNC, void *HOOK_VALUE)
     The function ‘gpgme_set_passphrase_cb’ sets the function that is
     used when a passphrase needs to be provided by the user to
     PASSFUNC.  The function PASSFUNC needs to implemented by the user,
     and whenever it is called, it is called with its first argument
     being HOOK_VALUE.  By default, no passphrase callback function is
     set.

     Not all crypto engines require this callback to retrieve the
     passphrase.  It is better if the engine retrieves the passphrase
     from a trusted agent (a daemon process), rather than having each
     user to implement their own passphrase query.  Some engines do not
     even support an external passphrase callback at all, in this case
     the error code ‘GPG_ERR_NOT_SUPPORTED’ is returned.

     For GnuPG >= 2.1 the pinentry mode has to be set to
     ‘GPGME_PINENTRY_MODE_LOOPBACK’ to enable the passphrase callback.
     See ‘gpgme_set_pinentry_mode’.

     The user can disable the use of a passphrase callback function by
     calling ‘gpgme_set_passphrase_cb’ with PASSFUNC being ‘NULL’.

 -- Function: void gpgme_get_passphrase_cb (gpgme_ctx_t CTX,
          gpgme_passphrase_cb_t *PASSFUNC, void **HOOK_VALUE)
     The function ‘gpgme_get_passphrase_cb’ returns the function that is
     used when a passphrase needs to be provided by the user in
     *PASSFUNC, and the first argument for this function in *HOOK_VALUE.
     If no passphrase callback is set, or CTX is not a valid pointer,
     ‘NULL’ is returned in both variables.

     PASSFUNC or HOOK_VALUE can be ‘NULL’.  In this case, the
     corresponding value will not be returned.


File: gpgme.info,  Node: Progress Meter Callback,  Next: Status Message Callback,  Prev: Passphrase Callback,  Up: Context Attributes

7.4.11 Progress Meter Callback
------------------------------

 -- Data type: void (*gpgme_progress_cb_t)(void *HOOK, const char *WHAT,
          int TYPE, int CURRENT, int TOTAL)
     The ‘gpgme_progress_cb_t’ type is the type of functions usable as
     progress callback function.

     The arguments are specific to the crypto engine.  More information
     about the progress information returned from the GnuPG engine can
     be found in the GnuPG source code in the file ‘doc/DETAILS’ in the
     section PROGRESS.

 -- Function: void gpgme_set_progress_cb (gpgme_ctx_t CTX,
          gpgme_progress_cb_t PROGFUNC, void *HOOK_VALUE)
     The function ‘gpgme_set_progress_cb’ sets the function that is used
     when progress information about a cryptographic operation is
     available.  The function PROGFUNC needs to implemented by the user,
     and whenever it is called, it is called with its first argument
     being HOOK_VALUE.  By default, no progress callback function is
     set.

     Setting a callback function allows an interactive program to
     display progress information about a long operation to the user.

     The user can disable the use of a progress callback function by
     calling ‘gpgme_set_progress_cb’ with PROGFUNC being ‘NULL’.

 -- Function: void gpgme_get_progress_cb (gpgme_ctx_t CTX,
          gpgme_progress_cb_t *PROGFUNC, void **HOOK_VALUE)
     The function ‘gpgme_get_progress_cb’ returns the function that is
     used to inform the user about the progress made in *PROGFUNC, and
     the first argument for this function in *HOOK_VALUE.  If no
     progress callback is set, or CTX is not a valid pointer, ‘NULL’ is
     returned in both variables.

     PROGFUNC or HOOK_VALUE can be ‘NULL’.  In this case, the
     corresponding value will not be returned.


File: gpgme.info,  Node: Status Message Callback,  Next: Locale,  Prev: Progress Meter Callback,  Up: Context Attributes

7.4.12 Status Message Callback
------------------------------

 -- Data type: gpgme_error_t (*gpgme_status_cb_t)(void *HOOK, const char
          *KEYWORD, const char *ARGS)
     The ‘gpgme_status_cb_t’ type is the type of function usable as a
     status message callback function.

     The argument KEYWORD is the name of the status message while the
     ARGS argument contains any arguments for the status message.

     If an error occurs, return the corresponding ‘gpgme_error_t’ value.
     Otherwise, return ‘0’.

 -- Function: void gpgme_set_status_cb (gpgme_ctx_t CTX,
          gpgme_status_cb_t STATUSFUNC, void *HOOK_VALUE)
     The function ‘gpgme_set_status_cb’ sets the function that is used
     when a status message is received from gpg to STATUSFUNC.  The
     function STATUSFUNC needs to be implemented by the user, and
     whenever it is called, it is called with its first argument being
     HOOK_VALUE.  By default, no status message callback function is
     set.

     The user can disable the use of a status message callback function
     by calling ‘gpgme_set_status_cb’ with STATUSFUNC being ‘NULL’.

 -- Function: void gpgme_get_status_cb (gpgme_ctx_t CTX,
          gpgme_status_cb_t *STATUSFUNC, void **HOOK_VALUE)
     The function ‘gpgme_get_status_cb’ returns the function that is
     used to process status messages from gpg in *STATUSFUNC, and the
     first argument for this function in *HOOK_VALUE.  If no status
     message callback is set, or CTX is not a valid pointer, ‘NULL’ is
     returned in both variables.

 -- Function: gpgme_error_t gpgme_set_ctx_flag (gpgme_ctx_t CTX,
          const char *NAME, const char *VALUE)

     Some minor properties of the context can be controlled with flags
     set by this function.  The properties are identified by the
     following values for NAME:

     ‘"full-status"’
          Using a VALUE of "1" the status callback set by
          gpgme_set_status_cb returns all status lines with the
          exception of PROGRESS lines.  With the default of "0" the
          status callback is only called in certain situations.

     ‘"raw-description"’
          Setting the VALUE to "1" returns human readable strings in a
          raw format.  For example the non breaking space characters
          ("~") will not be removed from the ‘description’ field of the
          ‘gpgme_tofu_info_t’ object.

     ‘"export-session-key"’
          Using a VALUE of "1" specifies that the context should try to
          export the symmetric session key when decrypting data.  By
          default, or when using an empty string or "0" for VALUE,
          session keys are not exported.

     ‘"override-session-key"’
          The string given in VALUE is passed to the GnuPG engine to
          override the session key for decryption.  The format of that
          session key is specific to GnuPG and can be retrieved during a
          decrypt operation when the context flag "export-session-key"
          is enabled.  Please be aware that using this feature with
          GnuPG < 2.1.16 will leak the session key on many platforms via
          ps(1).

     This function returns ‘0’ on success.

 -- Function: const char * gpgme_get_ctx_flag (gpgme_ctx_t CTX,
          const char *NAME)

     The value of flags settable by ‘gpgme_set_ctx_flag’ can be
     retrieved by this function.  If NAME is unknown the function
     returns ‘NULL’.  For boolean flags an empty string is returned for
     False and the string "1" is returned for True; either atoi(3) or a
     test for an empty string can be used to get the boolean value.


File: gpgme.info,  Node: Locale,  Prev: Status Message Callback,  Up: Context Attributes

7.4.13 Locale
-------------

A locale setting can be associated with a context.  This locale is
passed to the crypto engine, and used for applications like the PIN
entry, which is displayed to the user when entering a passphrase is
required.

   The default locale is used to initialize the locale setting of all
contexts created afterwards.

 -- Function: gpgme_error_t gpgme_set_locale (gpgme_ctx_t CTX,
          int CATEGORY, const char *VALUE)
     The function ‘gpgme_set_locale’ sets the locale of the context CTX,
     or the default locale if CTX is a null pointer.

     The locale settings that should be changed are specified by
     CATEGORY.  Supported categories are ‘LC_CTYPE’, ‘LC_MESSAGES’, and
     ‘LC_ALL’, which is a wildcard you can use if you want to change all
     the categories at once.

     The value to be used for the locale setting is VALUE, which will be
     copied to GPGME’s internal data structures.  VALUE can be a null
     pointer, which disables setting the locale, and will make PIN entry
     and other applications use their default setting, which is usually
     not what you want.

     Note that the settings are only used if the application runs on a
     text terminal, and that the settings should fit the configuration
     of the output terminal.  Normally, it is sufficient to initialize
     the default value at startup.

     The function returns an error if not enough memory is available.


File: gpgme.info,  Node: Key Management,  Next: Trust Item Management,  Prev: Context Attributes,  Up: Contexts

7.5 Key Management
==================

Some of the cryptographic operations require that recipients or signers
are specified.  This is always done by specifying the respective keys
that should be used for the operation.  The following section describes
how such keys can be selected and manipulated.

* Menu:

* Key objects::                   Description of the key structures.
* Listing Keys::                  Browsing the list of available keys.
* Information About Keys::        Requesting detailed information about keys.
* Manipulating Keys::             Operations on keys.
* Generating Keys::               Creating new key pairs.
* Signing Keys::                  Adding key signatures to public keys.
* Exporting Keys::                Retrieving key data from the key ring.
* Importing Keys::                Adding keys to the key ring.
* Deleting Keys::                 Removing keys from the key ring.
* Changing Passphrases::          Change the passphrase of a key.
* Changing TOFU Data::            Changing data pertaining to TOFU.
* Advanced Key Editing::          Advanced key edit operation.


File: gpgme.info,  Node: Key objects,  Next: Listing Keys,  Up: Key Management

7.5.1 Key objects
-----------------

The keys are represented in GPGME by structures which may only be read
by the application but never be allocated or changed.  They are valid as
long as the key object itself is valid.

 -- Data type: gpgme_key_t

     The ‘gpgme_key_t’ type is a pointer to a key object.  It has the
     following members:

     ‘gpgme_keylist_mode_t keylist_mode’
          The keylist mode that was active when the key was retrieved.

     ‘unsigned int revoked : 1’
          This is true if the key is revoked.

     ‘unsigned int expired : 1’
          This is true if the key is expired.

     ‘unsigned int disabled : 1’
          This is true if the key is disabled.

     ‘unsigned int invalid : 1’
          This is true if the key is invalid.  This might have several
          reasons, for a example for the S/MIME backend, it will be set
          during key listings if the key could not be validated due to
          missing certificates or unmatched policies.

     ‘unsigned int can_encrypt : 1’
          This is true if the key (ie one of its subkeys) can be used
          for encryption.

     ‘unsigned int can_sign : 1’
          This is true if the key (ie one of its subkeys) can be used to
          create data signatures.

     ‘unsigned int can_certify : 1’
          This is true if the key (ie one of its subkeys) can be used to
          create key certificates.

     ‘unsigned int can_authenticate : 1’
          This is true if the key (ie one of its subkeys) can be used
          for authentication.

     ‘unsigned int is_qualified : 1’
          This is true if the key can be used for qualified signatures
          according to local government regulations.

     ‘unsigned int secret : 1’
          This is true if the key is a secret key.  Note, that this will
          always be true even if the corresponding subkey flag may be
          false (offline/stub keys).  This is only set if a listing of
          secret keys has been requested or if
          ‘GPGME_KEYLIST_MODE_WITH_SECRET’ is active.

     ‘gpgme_protocol_t protocol’
          This is the protocol supported by this key.

     ‘char *issuer_serial’
          If ‘protocol’ is ‘GPGME_PROTOCOL_CMS’, then this is the issuer
          serial.

     ‘char *issuer_name’
          If ‘protocol’ is ‘GPGME_PROTOCOL_CMS’, then this is the issuer
          name.

     ‘char *chain_id’
          If ‘protocol’ is ‘GPGME_PROTOCOL_CMS’, then this is the chain
          ID, which can be used to built the certificate chain.

     ‘gpgme_validity_t owner_trust’
          If ‘protocol’ is ‘GPGME_PROTOCOL_OpenPGP’, then this is the
          owner trust.

     ‘gpgme_subkey_t subkeys’
          This is a linked list with the subkeys of the key.  The first
          subkey in the list is the primary key and usually available.

     ‘gpgme_user_id_t uids’
          This is a linked list with the user IDs of the key.  The first
          user ID in the list is the main (or primary) user ID.

     ‘char *fpr’
          This field gives the fingerprint of the primary key.  Note
          that this is a copy of the fingerprint of the first subkey.
          For an incomplete key (for example from a verification result)
          a subkey may be missing but this field may be set
          nevertheless.

 -- Data type: gpgme_subkey_t

     The ‘gpgme_subkey_t’ type is a pointer to a subkey structure.
     Subkeys are one component of a ‘gpgme_key_t’ object.  In fact,
     subkeys are those parts that contains the real information about
     the individual cryptographic keys that belong to the same key
     object.  One ‘gpgme_key_t’ can contain several subkeys.  The first
     subkey in the linked list is also called the primary key.

     The subkey structure has the following members:

     ‘gpgme_subkey_t next’
          This is a pointer to the next subkey structure in the linked
          list, or ‘NULL’ if this is the last element.

     ‘unsigned int revoked : 1’
          This is true if the subkey is revoked.

     ‘unsigned int expired : 1’
          This is true if the subkey is expired.

     ‘unsigned int disabled : 1’
          This is true if the subkey is disabled.

     ‘unsigned int invalid : 1’
          This is true if the subkey is invalid.

     ‘unsigned int can_encrypt : 1’
          This is true if the subkey can be used for encryption.

     ‘unsigned int can_sign : 1’
          This is true if the subkey can be used to create data
          signatures.

     ‘unsigned int can_certify : 1’
          This is true if the subkey can be used to create key
          certificates.

     ‘unsigned int can_authenticate : 1’
          This is true if the subkey can be used for authentication.

     ‘unsigned int is_qualified : 1’
          This is true if the subkey can be used for qualified
          signatures according to local government regulations.

     ‘unsigned int secret : 1’
          This is true if the subkey is a secret key.  Note that it will
          be false if the key is actually a stub key; i.e.  a secret key
          operation is currently not possible (offline-key).  This is
          only set if a listing of secret keys has been requested or if
          ‘GPGME_KEYLIST_MODE_WITH_SECRET’ is active.

     ‘gpgme_pubkey_algo_t pubkey_algo’
          This is the public key algorithm supported by this subkey.

     ‘unsigned int length’
          This is the length of the subkey (in bits).

     ‘char *keyid’
          This is the key ID of the subkey in hexadecimal digits.

     ‘char *fpr’
          This is the fingerprint of the subkey in hexadecimal digits,
          if available.

     ‘char *keygrip’
          The keygrip of the subkey in hex digit form or ‘NULL’ if not
          availabale.

     ‘long int timestamp’
          This is the creation timestamp of the subkey.  This is -1 if
          the timestamp is invalid, and 0 if it is not available.

     ‘long int expires’
          This is the expiration timestamp of the subkey, or 0 if the
          subkey does not expire.

     ‘unsigned int is_cardkey : 1’
          True if the secret key is stored on a smart card.

     ‘char *card_number’
          The serial number of a smart card holding this key or ‘NULL’.

     ‘char *curve’
          For ECC algorithms the name of the curve.

 -- Data type: gpgme_user_id_t

     A user ID is a component of a ‘gpgme_key_t’ object.  One key can
     have many user IDs.  The first one in the list is the main (or
     primary) user ID.

     The user ID structure has the following members.

     ‘gpgme_user_id_t next’
          This is a pointer to the next user ID structure in the linked
          list, or ‘NULL’ if this is the last element.

     ‘unsigned int revoked : 1’
          This is true if the user ID is revoked.

     ‘unsigned int invalid : 1’
          This is true if the user ID is invalid.

     ‘gpgme_validity_t validity’
          This specifies the validity of the user ID.

     ‘char *uid’
          This is the user ID string.

     ‘char *name’
          This is the name component of ‘uid’, if available.

     ‘char *comment’
          This is the comment component of ‘uid’, if available.

     ‘char *email’
          This is the email component of ‘uid’, if available.

     ‘char *address;’
          The mail address (addr-spec from RFC-5322) of the user ID
          string.  This is general the same as the ‘email’ part of this
          structure but might be slightly different.  If no mail address
          is available ‘NULL’ is stored.

     ‘gpgme_tofu_info_t tofu’
          If not ‘NULL’ information from the TOFU database pertaining to
          this user id.

     ‘gpgme_key_sig_t signatures’
          This is a linked list with the signatures on this user ID.

 -- Data type: gpgme_key_sig_t

     The ‘gpgme_key_sig_t’ type is a pointer to a key signature
     structure.  Key signatures are one component of a ‘gpgme_key_t’
     object, and validate user IDs on the key in the OpenPGP protocol.

     The signatures on a key are only available if the key was retrieved
     via a listing operation with the ‘GPGME_KEYLIST_MODE_SIGS’ mode
     enabled, because it can be expensive to retrieve all signatures of
     a key.

     The signature notations on a key signature are only available if
     the key was retrieved via a listing operation with the
     ‘GPGME_KEYLIST_MODE_SIG_NOTATIONS’ mode enabled, because it can be
     expensive to retrieve all signature notations.

     The key signature structure has the following members:

     ‘gpgme_key_sig_t next’
          This is a pointer to the next key signature structure in the
          linked list, or ‘NULL’ if this is the last element.

     ‘unsigned int revoked : 1’
          This is true if the key signature is a revocation signature.

     ‘unsigned int expired : 1’
          This is true if the key signature is expired.

     ‘unsigned int invalid : 1’
          This is true if the key signature is invalid.

     ‘unsigned int exportable : 1’
          This is true if the key signature is exportable.

     ‘gpgme_pubkey_algo_t pubkey_algo’
          This is the public key algorithm used to create the signature.

     ‘char *keyid’
          This is the key ID of the key (in hexadecimal digits) used to
          create the signature.

     ‘long int timestamp’
          This is the creation timestamp of the key signature.  This is
          -1 if the timestamp is invalid, and 0 if it is not available.

     ‘long int expires’
          This is the expiration timestamp of the key signature, or 0 if
          the key signature does not expire.

     ‘gpgme_error_t status’
          This is the status of the signature and has the same meaning
          as the member of the same name in a ‘gpgme_signature_t’
          object.

     ‘unsigned int sig_class’
          This specifies the signature class of the key signature.  The
          meaning is specific to the crypto engine.

     ‘char *uid’
          This is the main user ID of the key used to create the
          signature.

     ‘char *name’
          This is the name component of ‘uid’, if available.

     ‘char *comment’
          This is the comment component of ‘uid’, if available.

     ‘char *email’
          This is the email component of ‘uid’, if available.

     ‘gpgme_sig_notation_t notations’
          This is a linked list with the notation data and policy URLs.


File: gpgme.info,  Node: Listing Keys,  Next: Information About Keys,  Prev: Key objects,  Up: Key Management

7.5.2 Listing Keys
------------------

 -- Function: gpgme_error_t gpgme_op_keylist_start (gpgme_ctx_t CTX,
          const char *PATTERN, int SECRET_ONLY)
     The function ‘gpgme_op_keylist_start’ initiates a key listing
     operation inside the context CTX.  It sets everything up so that
     subsequent invocations of ‘gpgme_op_keylist_next’ return the keys
     in the list.

     If PATTERN is ‘NULL’, all available keys are returned.  Otherwise,
     PATTERN contains an engine specific expression that is used to
     limit the list to all keys matching the pattern.  Note that the
     total length of the pattern is restricted to an engine-specific
     maximum (a couple of hundred characters are usually accepted).  The
     pattern should be used to restrict the search to a certain common
     name or user, not to list many specific keys at once by listing
     their fingerprints or key IDs.

     If SECRET_ONLY is not ‘0’, the list is restricted to secret keys
     only.

     The context will be busy until either all keys are received (and
     ‘gpgme_op_keylist_next’ returns ‘GPG_ERR_EOF’), or
     ‘gpgme_op_keylist_end’ is called to finish the operation.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if CTX is
     not a valid pointer, and passes through any errors that are
     reported by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_keylist_ext_start (gpgme_ctx_t CTX,
          const char *PATTERN[], int SECRET_ONLY, int RESERVED)
     The function ‘gpgme_op_keylist_ext_start’ initiates an extended key
     listing operation inside the context CTX.  It sets everything up so
     that subsequent invocations of ‘gpgme_op_keylist_next’ return the
     keys in the list.

     If PATTERN or *PATTERN is ‘NULL’, all available keys are returned.
     Otherwise, PATTERN is a ‘NULL’ terminated array of strings that are
     used to limit the list to all keys matching at least one of the
     patterns verbatim.  Note that the total length of all patterns is
     restricted to an engine-specific maximum (the exact limit also
     depends on the number of patterns and amount of quoting required,
     but a couple of hundred characters are usually accepted).  Patterns
     should be used to restrict the search to a certain common name or
     user, not to list many specific keys at once by listing their
     fingerprints or key IDs.

     If SECRET_ONLY is not ‘0’, the list is restricted to secret keys
     only.

     The value of RESERVED must be ‘0’.

     The context will be busy until either all keys are received (and
     ‘gpgme_op_keylist_next’ returns ‘GPG_ERR_EOF’), or
     ‘gpgme_op_keylist_end’ is called to finish the operation.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if CTX is
     not a valid pointer, and passes through any errors that are
     reported by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_keylist_next (gpgme_ctx_t CTX,
          gpgme_key_t *R_KEY)
     The function ‘gpgme_op_keylist_next’ returns the next key in the
     list created by a previous ‘gpgme_op_keylist_start’ operation in
     the context CTX.  The key will have one reference for the user.
     *Note Manipulating Keys::.

     This is the only way to get at ‘gpgme_key_t’ objects in GPGME.

     If the last key in the list has already been returned,
     ‘gpgme_op_keylist_next’ returns ‘GPG_ERR_EOF’.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if CTX or
     R_KEY is not a valid pointer, and ‘GPG_ERR_ENOMEM’ if there is not
     enough memory for the operation.

 -- Function: gpgme_error_t gpgme_op_keylist_end (gpgme_ctx_t CTX)
     The function ‘gpgme_op_keylist_end’ ends a pending key list
     operation in the context CTX.

     After the operation completed successfully, the result of the key
     listing operation can be retrieved with ‘gpgme_op_keylist_result’.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if CTX is
     not a valid pointer, and ‘GPG_ERR_ENOMEM’ if at some time during
     the operation there was not enough memory available.

   The following example illustrates how all keys containing a certain
string (‘g10code’) can be listed with their key ID and the name and
e-mail address of the main user ID:

     gpgme_ctx_t ctx;
     gpgme_key_t key;
     gpgme_error_t err = gpgme_new (&ctx);

     if (!err)
       {
         err = gpgme_op_keylist_start (ctx, "g10code", 0);
         while (!err)
           {
             err = gpgme_op_keylist_next (ctx, &key);
             if (err)
               break;
             printf ("%s:", key->subkeys->keyid);
             if (key->uids && key->uids->name)
               printf (" %s", key->uids->name);
             if (key->uids && key->uids->email)
               printf (" <%s>", key->uids->email);
             putchar ('\n');
             gpgme_key_release (key);
           }
         gpgme_release (ctx);
       }
     if (gpg_err_code (err) != GPG_ERR_EOF)
       {
         fprintf (stderr, "can not list keys: %s\n", gpgme_strerror (err));
         exit (1);
       }

 -- Data type: gpgme_keylist_result_t
     This is a pointer to a structure used to store the result of a
     ‘gpgme_op_keylist_*’ operation.  After successfully ending a key
     listing operation, you can retrieve the pointer to the result with
     ‘gpgme_op_keylist_result’.  The structure contains the following
     member:

     ‘unsigned int truncated : 1’
          This is true if the crypto backend had to truncate the result,
          and less than the desired keys could be listed.

 -- Function: gpgme_keylist_result_t gpgme_op_keylist_result
          (gpgme_ctx_t CTX)
     The function ‘gpgme_op_keylist_result’ returns a
     ‘gpgme_keylist_result_t’ pointer to a structure holding the result
     of a ‘gpgme_op_keylist_*’ operation.  The pointer is only valid if
     the last operation on the context was a key listing operation, and
     if this operation finished successfully.  The returned pointer is
     only valid until the next operation is started on the context.

   In a simple program, for which a blocking operation is acceptable,
the following function can be used to retrieve a single key.

 -- Function: gpgme_error_t gpgme_get_key (gpgme_ctx_t CTX,
          const char *FPR, gpgme_key_t *R_KEY, int SECRET)
     The function ‘gpgme_get_key’ gets the key with the fingerprint (or
     key ID) FPR from the crypto backend and return it in R_KEY.  If
     SECRET is true, get the secret key.  The currently active keylist
     mode is used to retrieve the key.  The key will have one reference
     for the user.

     If the key is not found in the keyring, ‘gpgme_get_key’ returns the
     error code ‘GPG_ERR_EOF’ and *R_KEY will be set to ‘NULL’.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if CTX or
     R_KEY is not a valid pointer or FPR is not a fingerprint or key ID,
     ‘GPG_ERR_AMBIGUOUS_NAME’ if the key ID was not a unique specifier
     for a key, and ‘GPG_ERR_ENOMEM’ if at some time during the
     operation there was not enough memory available.


File: gpgme.info,  Node: Information About Keys,  Next: Manipulating Keys,  Prev: Listing Keys,  Up: Key Management

7.5.3 Information About Keys
----------------------------

Please see the beginning of this section for more information about
‘gpgme_key_t’ objects.

 -- Data type: gpgme_validity_t
     The ‘gpgme_validity_t’ type is used to specify the validity of a
     user ID in a key.  The following validities are defined:

     ‘GPGME_VALIDITY_UNKNOWN’
          The user ID is of unknown validity.  The string representation
          of this validity is “?”.

     ‘GPGME_VALIDITY_UNDEFINED’
          The validity of the user ID is undefined.  The string
          representation of this validity is “q”.

     ‘GPGME_VALIDITY_NEVER’
          The user ID is never valid.  The string representation of this
          validity is “n”.

     ‘GPGME_VALIDITY_MARGINAL’
          The user ID is marginally valid.  The string representation of
          this validity is “m”.

     ‘GPGME_VALIDITY_FULL’
          The user ID is fully valid.  The string representation of this
          validity is “f”.

     ‘GPGME_VALIDITY_ULTIMATE’
          The user ID is ultimately valid.  The string representation of
          this validity is “u”.


File: gpgme.info,  Node: Manipulating Keys,  Next: Generating Keys,  Prev: Information About Keys,  Up: Key Management

7.5.4 Manipulating Keys
-----------------------

 -- Function: void gpgme_key_ref (gpgme_key_t KEY)
     The function ‘gpgme_key_ref’ acquires an additional reference for
     the key KEY.

 -- Function: void gpgme_key_unref (gpgme_key_t KEY)
     The function ‘gpgme_key_unref’ releases a reference for the key
     KEY.  If this was the last reference, the key will be destroyed and
     all resources associated to it will be released.


File: gpgme.info,  Node: Generating Keys,  Next: Signing Keys,  Prev: Manipulating Keys,  Up: Key Management

7.5.5 Generating Keys
---------------------

GPGME provides a set of functions to create public key pairs.  Most of
these functions require the use of GnuPG 2.1 and later; for older GnuPG
versions the ‘gpgme_op_genkey’ function can be used.  Existing code
which wants to update to the new functions or new code which shall
supports older GnuPG versions may try the new functions first and
provide a fallback to the old function if the error code
‘GPG_ERR_NOT_SUPPORTED’ is received.

 -- Function: gpgme_error_t gpgme_op_createkey (gpgme_ctx_t CTX,
          const char *USERID, const char *ALGO, unsigned long RESERVED,
          unsigned long EXPIRES, gpgme_key_t EXTRAKEY,
          unsigned int FLAGS);

     The function ‘gpgme_op_createkey’ generates a new key for the
     procotol active in the context CTX.  As of now this function does
     only work for OpenPGP and requires at least version 2.1.13 of
     GnuPG.

     USERID is commonly the mail address associated with the key.  GPGME
     does not require a specificy syntax but if more than a mail address
     is given, RFC-822 style format is suggested.  The value is expected
     to be in UTF-8 encoding (i.e.  no IDN encoding for mail addresses).
     This is a required parameter.

     ALGO specifies the algorithm for the new key (actually a keypair of
     public and private key).  For a list of supported algorithms, see
     the GnuPG manual.  If ALGO is ‘NULL’ or the string "default", the
     key is generated using the default algorithm of the engine.  If the
     string "future-default" is used the engine may use an algorithm
     which is planned to be the default in a future release of the
     engine; however existing implementation of the protocol may not be
     able to already handle such future algorithms.  For the OpenPGP
     protocol, the specification of a default algorithm, without
     requesting a non-default usage via FLAGS, triggers the creation of
     a primary key plus a secondary key (subkey).

     RESERVED must be set to zero.

     EXPIRES can be set to the number of seconds since Epoch of the
     desired expiration date in UTC for the new key.  Using 0 does not
     set an expiration date.  Note that this parameter takes an unsigned
     long value and not a ‘time_t’ to avoid problems on systems which
     use a signed 32 bit ‘time_t’.  Note further that the OpenPGP
     protocol uses 32 bit values for timestamps and thus can only encode
     dates up to the year 2106.

     EXTRAKEY is currently not used and must be set to ‘NULL’.  A future
     version of GPGME may use this parameter to create X.509 keys.

     FLAGS can be set to the bit-wise OR of the following flags:

     ‘GPGME_CREATE_SIGN’
     ‘GPGME_CREATE_ENCR’
     ‘GPGME_CREATE_CERT’
     ‘GPGME_CREATE_AUTH’
          Do not create the key with the default capabilities (key
          usage) of the requested algorithm but use those explicitly
          given by these flags: “signing”, “encryption”,
          “certification”, or “authentication”.  The allowed
          combinations depend on the algorithm.

          If any of these flags are set and a default algorithm has been
          selected only one key is created in the case of the OpenPGP
          protocol.

     ‘GPGME_CREATE_NOPASSWD’
          Request generation of the key without password protection.

     ‘GPGME_CREATE_SELFSIGNED’
          For an X.509 key do not create a CSR but a self-signed
          certificate.  This has not yet been implemented.

     ‘GPGME_CREATE_NOSTORE’
          Do not store the created key in the local key database.  This
          has not yet been implemented.

     ‘GPGME_CREATE_WANTPUB’
     ‘GPGME_CREATE_WANTSEC’
          Return the public or secret key as part of the result
          structure.  This has not yet been implemented.

     ‘GPGME_CREATE_FORCE’
          The engine does not allow the creation of a key with a user ID
          already existing in the local key database.  This flag can be
          used to override this check.

     After the operation completed successfully, information about the
     created key can be retrieved with ‘gpgme_op_genkey_result’.

     The function returns zero on success, ‘GPG_ERR_NOT_SUPPORTED’ if
     the engine does not support the command, or a bunch of other error
     codes.

 -- Function: gpgme_error_t gpgme_op_createkey_start (gpgme_ctx_t CTX,
          const char *USERID, const char *ALGO, unsigned long RESERVED,
          unsigned long EXPIRES, gpgme_key_t EXTRAKEY,
          unsigned int FLAGS);

     The function ‘gpgme_op_createkey_start’ initiates a
     ‘gpgme_op_createkey’ operation; see there for details.  It must be
     completed by calling ‘gpgme_wait’ on the context.  *Note Waiting
     For Completion::.

 -- Function: gpgme_error_t gpgme_op_createsubkey (gpgme_ctx_t CTX,
          gpgme_key_t KEY, const char *ALGO, unsigned long RESERVED,
          unsigned long EXPIRES, unsigned int FLAGS);

     The function ‘gpgme_op_createsubkey’ creates and adds a new subkey
     to the primary OpenPGP key given by KEY.  The only allowed protocol
     in CTX is ‘GPGME_PROTOCOL_OPENPGP’.  Subkeys (aka secondary keys)
     are a concept in the OpenPGP protocol to bind several keys to a
     primary key.  As of now this function requires at least version
     2.1.13 of GnuPG.

     KEY specifies the key to operate on.

     ALGO specifies the algorithm for the new subkey.  For a list of
     supported algorithms, see the GnuPG manual.  If ALGO is ‘NULL’ or
     the string "default", the subkey is generated using the default
     algorithm for an encryption subkey of the engine.  If the string
     "future-default" is used the engine may use an encryption algorithm
     which is planned to be the default in a future release of the
     engine; however existing implementation of the protocol may not be
     able to already handle such future algorithms.

     RESERVED must be set to zero.

     EXPIRES can be set to the number of seconds since Epoch of the
     desired expiration date in UTC for the new subkey.  Using 0 does
     not set an expiration date.  Note that this parameter takes an
     unsigned long value and not a ‘time_t’ to avoid problems on systems
     which use a signed 32 bit ‘time_t’.  Note further that the OpenPGP
     protocol uses 32 bit values for timestamps and thus can only encode
     dates up to the year 2106.

     FLAGS takes the same values as described above for
     ‘gpgme_op_createkey’.

     After the operation completed successfully, information about the
     created key can be retrieved with ‘gpgme_op_genkey_result’.

     The function returns zero on success, ‘GPG_ERR_NOT_SUPPORTED’ if
     the engine does not support the command, or a bunch of other error
     codes.

 -- Function: gpgme_error_t gpgme_op_createsubkey_start
          (gpgme_ctx_t CTX, gpgme_key_t KEY, const char *ALGO,
          unsigned long RESERVED, unsigned long EXPIRES,
          unsigned int FLAGS);

     The function ‘gpgme_op_createsubkey_start’ initiates a
     ‘gpgme_op_createsubkey’ operation; see there for details.  It must
     be completed by calling ‘gpgme_wait’ on the context.  *Note Waiting
     For Completion::.

 -- Function: gpgme_error_t gpgme_op_adduid (gpgme_ctx_t CTX,
          gpgme_key_t KEY, const char *USERID, unsigned int FLAGS);

     The function ‘gpgme_op_adduid’ adds a new user ID to the OpenPGP
     key given by KEY.  Adding additional user IDs after key creation is
     a feature of the OpenPGP protocol and thus the protocol for the
     context CTX must be set to OpenPGP. As of now this function
     requires at least version 2.1.13 of GnuPG.

     KEY specifies the key to operate on.

     USERID is the user ID to add to the key.  A user ID is commonly the
     mail address to be associated with the key.  GPGME does not require
     a specificy syntax but if more than a mail address is given,
     RFC-822 style format is suggested.  The value is expected to be in
     UTF-8 encoding (i.e.  no IDN encoding for mail addresses).  This is
     a required parameter.

     FLAGS are currently not used and must be set to zero.

     The function returns zero on success, ‘GPG_ERR_NOT_SUPPORTED’ if
     the engine does not support the command, or a bunch of other error
     codes.

 -- Function: gpgme_error_t gpgme_op_adduid_start (gpgme_ctx_t CTX,
          gpgme_key_t KEY, const char *USERID, unsigned int FLAGS);

     The function ‘gpgme_op_adduid_start’ initiates a ‘gpgme_op_adduid’
     operation; see there for details.  It must be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

 -- Function: gpgme_error_t gpgme_op_revuid (gpgme_ctx_t CTX,
          gpgme_key_t KEY, const char *USERID, unsigned int FLAGS);

     The function ‘gpgme_op_revuid’ revokes a user ID from the OpenPGP
     key given by KEY.  Revoking user IDs after key creation is a
     feature of the OpenPGP protocol and thus the protocol for the
     context CTX must be set to OpenPGP. As of now this function
     requires at least version 2.1.13 of GnuPG.

     KEY specifies the key to operate on.

     USERID is the user ID to be revoked from the key.  The user ID must
     be given verbatim because the engine does an exact and case
     sensitive match.  Thus the ‘uid’ field from the user ID object
     (‘gpgme_user_id_t’) is to be used.  This is a required parameter.

     FLAGS are currently not used and must be set to zero.

     Note that the engine won’t allow to revoke the last valid user ID.
     To change a user ID is better to first add the new user ID, then
     revoke the old one, and finally publish the key.

     The function returns zero on success, ‘GPG_ERR_NOT_SUPPORTED’ if
     the engine does not support the command, or a bunch of other error
     codes.

 -- Function: gpgme_error_t gpgme_op_revuid_start (gpgme_ctx_t CTX,
          gpgme_key_t KEY, const char *USERID, unsigned int FLAGS);

     The function ‘gpgme_op_revuid_start’ initiates a ‘gpgme_op_revuid’
     operation; see there for details.  It must be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

 -- Function: gpgme_error_t gpgme_op_genkey (gpgme_ctx_t CTX,
          const char *PARMS, gpgme_data_t PUBLIC, gpgme_data_t SECRET)

     The function ‘gpgme_op_genkey’ generates a new key pair in the
     context CTX.  The meaning of PUBLIC and SECRET depends on the
     crypto backend.

     GPG does not support PUBLIC and SECRET, they should be ‘NULL’.
     GnuPG will generate a key pair and add it to the standard key ring.
     The fingerprint of the generated key is available with
     ‘gpgme_op_genkey_result’.

     GpgSM requires PUBLIC to be a writable data object.  GpgSM will
     generate a secret key (which will be stored by ‘gpg-agent’, and
     return a certificate request in PUBLIC, which then needs to be
     signed by the certification authority and imported before it can be
     used.  GpgSM does not make the fingerprint available.

     The argument PARMS specifies parameters for the key in an XML
     string.  The details about the format of PARMS are specific to the
     crypto engine used by CTX.  Here is an example for GnuPG as the
     crypto engine (all parameters of OpenPGP key generation are
     documented in the GPG manual):

          <GnupgKeyParms format="internal">
          Key-Type: default
          Subkey-Type: default
          Name-Real: Joe Tester
          Name-Comment: with stupid passphrase
          Name-Email: joe@foo.bar
          Expire-Date: 0
          Passphrase: abc
          </GnupgKeyParms>

     Here is an example for GpgSM as the crypto engine (all parameters
     of OpenPGP key generation are documented in the GPGSM manual):

          <GnupgKeyParms format="internal">
          Key-Type: RSA
          Key-Length: 1024
          Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
          Name-Email: joe@foo.bar
          </GnupgKeyParms>

     Strings should be given in UTF-8 encoding.  The only format
     supported for now is “internal”.  The content of the
     ‘GnupgKeyParms’ container is passed verbatim to the crypto backend.
     Control statements are not allowed.

     After the operation completed successfully, the result can be
     retrieved with ‘gpgme_op_genkey_result’.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, ‘GPG_ERR_INV_VALUE’ if
     PARMS is not a valid XML string, ‘GPG_ERR_NOT_SUPPORTED’ if PUBLIC
     or SECRET is not valid, and ‘GPG_ERR_GENERAL’ if no key was created
     by the backend.

 -- Function: gpgme_error_t gpgme_op_genkey_start (gpgme_ctx_t CTX,
          const char *PARMS, gpgme_data_t PUBLIC, gpgme_data_t SECRET)

     The function ‘gpgme_op_genkey_start’ initiates a ‘gpgme_op_genkey’
     operation.  It can be completed by calling ‘gpgme_wait’ on the
     context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, ‘GPG_ERR_INV_VALUE’ if
     PARMS is not a valid XML string, and ‘GPG_ERR_NOT_SUPPORTED’ if
     PUBLIC or SECRET is not ‘NULL’.

 -- Data type: gpgme_genkey_result_t

     This is a pointer to a structure used to store the result of a
     ‘gpgme_op_genkey’ operation.  After successfully generating a key,
     you can retrieve the pointer to the result with
     ‘gpgme_op_genkey_result’.  The structure contains the following
     members:

     ‘unsigned int primary : 1’
          This flag is set to 1 if a primary key was created and to 0 if
          not.

     ‘unsigned int sub : 1’
          This flag is set to 1 if a subkey was created and to 0 if not.

     ‘unsigned int uid : 1’
          This flag is set to 1 if a user ID was created and to 0 if
          not.

     ‘char *fpr’
          This is the fingerprint of the key that was created.  If both
          a primary and a subkey were generated, the fingerprint of the
          primary key will be returned.  If the crypto engine does not
          provide the fingerprint, ‘fpr’ will be a null pointer.

     ‘gpgme_data_t pubkey’
          This will eventually be used to return the public key.  It is
          currently not used.

     ‘gpgme_data_t seckey’
          This will eventually be used to return the secret key.  It is
          currently not used.

 -- Function: gpgme_genkey_result_t gpgme_op_genkey_result
          (gpgme_ctx_t CTX)

     The function ‘gpgme_op_genkey_result’ returns a
     ‘gpgme_genkey_result_t’ pointer to a structure holding the result
     of a ‘gpgme_op_genkey’ operation.  The pointer is only valid if the
     last operation on the context was a ‘gpgme_op_genkey’ or
     ‘gpgme_op_genkey_start’ operation, and if this operation finished
     successfully.  The returned pointer is only valid until the next
     operation is started on the context.


File: gpgme.info,  Node: Signing Keys,  Next: Exporting Keys,  Prev: Generating Keys,  Up: Key Management

7.5.6 Signing Keys
------------------

Key signatures are a unique concept of the OpenPGP protocol.  They can
be used to certify the validity of a key and are used to create the
Web-of-Trust (WoT). Instead of using the ‘gpgme_op_interact’ function
along with a finite state machine, GPGME provides a convenient function
to create key signatures when using modern GnuPG versions.

 -- Function: gpgme_error_t gpgme_op_keysign (gpgme_ctx_t CTX,
          gpgme_key_t KEY, const char *USERID, unsigned long EXPIRES,
          unsigned int FLAGS);

     The function ‘gpgme_op_keysign’ adds a new key signature to the
     public key KEY.  This function requires at least version 2.1.12 of
     GnuPG.

     CTX is the usual context which describes the protocol to use (which
     must be OpenPGP) and has also the list of signer keys to be used
     for the signature.  The common case is to use the default key for
     signing other keys.  If another key or more than one key shall be
     used for a key signature, ‘gpgme_signers_add’ can be used.  *Note
     Selecting Signers::.

     KEY specifies the key to operate on.

     USERID selects the user ID or user IDs to be signed.  If USERID is
     set to ‘NULL’ all valid user IDs are signed.  The user ID must be
     given verbatim because the engine does an exact and case sensitive
     match.  Thus the ‘uid’ field from the user ID object
     (‘gpgme_user_id_t’) is to be used.  To select more than one user ID
     put them all into one string separated by linefeeds characters
     (‘\n’) and set the flag ‘GPGME_KEYSIGN_LFSEP’.

     EXPIRES can be set to the number of seconds since Epoch of the
     desired expiration date in UTC for the new signature.  The common
     case is to use 0 to not set an expiration date.  However, if the
     configuration of the engine defines a default expiration for key
     signatures, that is still used unless the flag
     ‘GPGME_KEYSIGN_NOEXPIRE’ is used.  Note that this parameter takes
     an unsigned long value and not a ‘time_t’ to avoid problems on
     systems which use a signed 32 bit ‘time_t’.  Note further that the
     OpenPGP protocol uses 32 bit values for timestamps and thus can
     only encode dates up to the year 2106.

     FLAGS can be set to the bit-wise OR of the following flags:

     ‘GPGME_KEYSIGN_LOCAL’
          Instead of creating an exportable key signature, create a key
          signature which is is marked as non-exportable.

     ‘GPGME_KEYSIGN_LFSEP’
          Although linefeeds are uncommon in user IDs this flag is
          required to explicitly declare that USERID may contain several
          linefeed separated user IDs.

     ‘GPGME_KEYSIGN_NOEXPIRE’
          Force the creation of a key signature without an expiration
          date.  This overrides EXPIRE and any local configuration of
          the engine.

     The function returns zero on success, ‘GPG_ERR_NOT_SUPPORTED’ if
     the engine does not support the command, or a bunch of other error
     codes.

 -- Function: gpgme_error_t gpgme_op_keysign_start (gpgme_ctx_t CTX,
          gpgme_key_t KEY, const char *USERID, unsigned long EXPIRES,
          unsigned int FLAGS);

     The function ‘gpgme_op_keysign_start’ initiates a
     ‘gpgme_op_keysign’ operation; see there for details.  It must be
     completed by calling ‘gpgme_wait’ on the context.  *Note Waiting
     For Completion::.


File: gpgme.info,  Node: Exporting Keys,  Next: Importing Keys,  Prev: Signing Keys,  Up: Key Management

7.5.7 Exporting Keys
--------------------

Exporting keys means the same as running ‘gpg’ with the command
‘--export’.  However, a mode flag can be used to change the way the
export works.  The available mode flags are described below, they may be
or-ed together.

‘GPGME_EXPORT_MODE_EXTERN’
     If this bit is set, the output is send directly to the default
     keyserver.  This is currently only allowed for OpenPGP keys.  It is
     good practise to not send more than a few dozens key to a keyserver
     at one time.  Using this flag requires that the KEYDATA argument of
     the export function is set to ‘NULL’.

‘GPGME_EXPORT_MODE_MINIMAL’
     If this bit is set, the smallest possible key is exported.  For
     OpenPGP keys it removes all signatures except for the latest
     self-signatures.  For X.509 keys it has no effect.

‘GPGME_EXPORT_MODE_SECRET’
     Instead of exporting the public key, the secret key is exported.
     This may not be combined with ‘GPGME_EXPORT_MODE_EXTERN’.  For
     X.509 the export format is PKCS#8.

‘GPGME_EXPORT_MODE_RAW’
     If this flag is used with ‘GPGME_EXPORT_MODE_SECRET’ for an X.509
     key the export format will be changed to PKCS#1.  This flag may not
     be used with OpenPGP.

‘GPGME_EXPORT_MODE_PKCS12’
     If this flag is used with ‘GPGME_EXPORT_MODE_SECRET’ for an X.509
     key the export format will be changed to PKCS#12 which also
     includes the certificate.  This flag may not be used with OpenPGP.

 -- Function: gpgme_error_t gpgme_op_export (gpgme_ctx_t CTX,
          const char *PATTERN, gpgme_export_mode_t MODE,
          gpgme_data_t KEYDATA)
     The function ‘gpgme_op_export’ extracts public keys and returns
     them in the data buffer KEYDATA.  The output format of the key data
     returned is determined by the ASCII armor attribute set for the
     context CTX, or, if that is not set, by the encoding specified for
     KEYDATA.

     If PATTERN is ‘NULL’, all available keys are returned.  Otherwise,
     PATTERN contains an engine specific expression that is used to
     limit the list to all keys matching the pattern.

     MODE is usually 0; other values are described above.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation completed successfully, ‘GPG_ERR_INV_VALUE’ if KEYDATA is
     not a valid empty data buffer, and passes through any errors that
     are reported by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_export_start (gpgme_ctx_t CTX,
          const char *PATTERN, gpgme_export_mode_t MODE,
          gpgme_data_t KEYDATA)
     The function ‘gpgme_op_export_start’ initiates a ‘gpgme_op_export’
     operation.  It can be completed by calling ‘gpgme_wait’ on the
     context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, and ‘GPG_ERR_INV_VALUE’ if
     KEYDATA is not a valid empty data buffer.

 -- Function: gpgme_error_t gpgme_op_export_ext (gpgme_ctx_t CTX,
          const char *PATTERN[], gpgme_export_mode_t MODE,
          gpgme_data_t KEYDATA)
     The function ‘gpgme_op_export’ extracts public keys and returns
     them in the data buffer KEYDATA.  The output format of the key data
     returned is determined by the ASCII armor attribute set for the
     context CTX, or, if that is not set, by the encoding specified for
     KEYDATA.

     If PATTERN or *PATTERN is ‘NULL’, all available keys are returned.
     Otherwise, PATTERN is a ‘NULL’ terminated array of strings that are
     used to limit the list to all keys matching at least one of the
     patterns verbatim.

     MODE is usually 0; other values are described above.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation completed successfully, ‘GPG_ERR_INV_VALUE’ if KEYDATA is
     not a valid empty data buffer, and passes through any errors that
     are reported by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_export_ext_start (gpgme_ctx_t CTX,
          const char *PATTERN[], gpgme_export_mode_t MODE,
          gpgme_data_t KEYDATA)
     The function ‘gpgme_op_export_ext_start’ initiates a
     ‘gpgme_op_export_ext’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, and ‘GPG_ERR_INV_VALUE’ if
     KEYDATA is not a valid empty data buffer.

 -- Function: gpgme_error_t gpgme_op_export_keys (gpgme_ctx_t CTX,
          gpgme_key_t keys[], gpgme_export_mode_t MODE,
          gpgme_data_t KEYDATA)
     The function ‘gpgme_op_export_keys’ extracts public keys and
     returns them in the data buffer KEYDATA.  The output format of the
     key data returned is determined by the ASCII armor attribute set
     for the context CTX, or, if that is not set, by the encoding
     specified for KEYDATA.

     The keys to export are taken form the ‘NULL’ terminated array KEYS.
     Only keys of the currently selected protocol of CTX which do have a
     fingerprint set are considered for export.  Other keys specified by
     the KEYS are ignored.  In particular OpenPGP keys retrieved via an
     external key listing are not included.

     MODE is usually 0; other values are described above.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation completed successfully, ‘GPG_ERR_INV_VALUE’ if KEYDATA is
     not a valid empty data buffer, ‘GPG_ERR_NO_DATA’ if no useful keys
     are in KEYS and passes through any errors that are reported by the
     crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_export_keys_start (gpgme_ctx_t CTX,
          gpgme_key_t KEYS[], gpgme_export_mode_t MODE,
          gpgme_data_t KEYDATA)
     The function ‘gpgme_op_export_keys_start’ initiates a
     ‘gpgme_op_export_ext’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, and ‘GPG_ERR_INV_VALUE’ if
     KEYDATA is not a valid empty data buffer, ‘GPG_ERR_NO_DATA’ if no
     useful keys are in KEYS and passes through any errors that are
     reported by the crypto engine support routines.


File: gpgme.info,  Node: Importing Keys,  Next: Deleting Keys,  Prev: Exporting Keys,  Up: Key Management

7.5.8 Importing Keys
--------------------

Importing keys means the same as running ‘gpg’ with the command
‘--import’.

 -- Function: gpgme_error_t gpgme_op_import (gpgme_ctx_t CTX,
          gpgme_data_t KEYDATA)
     The function ‘gpgme_op_import’ adds the keys in the data buffer
     KEYDATA to the key ring of the crypto engine used by CTX.  The
     format of KEYDATA can be ASCII armored, for example, but the
     details are specific to the crypto engine.

     After the operation completed successfully, the result can be
     retrieved with ‘gpgme_op_import_result’.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     import was completed successfully, ‘GPG_ERR_INV_VALUE’ if KEYDATA
     if CTX or KEYDATA is not a valid pointer, and ‘GPG_ERR_NO_DATA’ if
     KEYDATA is an empty data buffer.

 -- Function: gpgme_error_t gpgme_op_import_start (gpgme_ctx_t CTX,
          gpgme_data_t KEYDATA)
     The function ‘gpgme_op_import_start’ initiates a ‘gpgme_op_import’
     operation.  It can be completed by calling ‘gpgme_wait’ on the
     context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     import could be started successfully, ‘GPG_ERR_INV_VALUE’ if
     KEYDATA if CTX or KEYDATA is not a valid pointer, and
     ‘GPG_ERR_NO_DATA’ if KEYDATA is an empty data buffer.

 -- Function: gpgme_error_t gpgme_op_import_keys (gpgme_ctx_t CTX,
          gpgme_key_t *KEYS)
     The function ‘gpgme_op_import_keys’ adds the keys described by the
     ‘NULL’ terminated array KEYS to the key ring of the crypto engine
     used by CTX.  This function is the general interface to move a key
     from one crypto engine to another as long as they are compatible.
     In particular it is used to actually import and make keys permanent
     which have been retrieved from an external source (i.e.  using
     ‘GPGME_KEYLIST_MODE_EXTERN’).  (1)

     Only keys of the currently selected protocol of CTX are considered
     for import.  Other keys specified by the KEYS are ignored.  As of
     now all considered keys must have been retrieved using the same
     method, that is the used key listing mode must be identical.

     After the operation completed successfully, the result can be
     retrieved with ‘gpgme_op_import_result’.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     import was completed successfully, ‘GPG_ERR_INV_VALUE’ if KEYDATA
     if CTX or KEYDATA is not a valid pointer, ‘GPG_ERR_CONFLICT’ if the
     key listing mode does not match, and ‘GPG_ERR_NO_DATA’ if no keys
     are considered for export.

 -- Function: gpgme_error_t gpgme_op_import_keys_start (gpgme_ctx_t CTX,
          gpgme_key_t *KEYS)
     The function ‘gpgme_op_import_keys_start’ initiates a
     ‘gpgme_op_import_keys’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     import was completed successfully, ‘GPG_ERR_INV_VALUE’ if KEYDATA
     if CTX or KEYDATA is not a valid pointer, ‘GPG_ERR_CONFLICT’ if the
     key listing mode does not match, and ‘GPG_ERR_NO_DATA’ if no keys
     are considered for export.

 -- Data type: gpgme_import_status_t
     This is a pointer to a structure used to store a part of the result
     of a ‘gpgme_op_import’ operation.  For each considered key one
     status is added that contains information about the result of the
     import.  The structure contains the following members:

     ‘gpgme_import_status_t next’
          This is a pointer to the next status structure in the linked
          list, or ‘NULL’ if this is the last element.

     ‘char *fpr’
          This is the fingerprint of the key that was considered.

     ‘gpgme_error_t result’
          If the import was not successful, this is the error value that
          caused the import to fail.  Otherwise the error code is
          ‘GPG_ERR_NO_ERROR’.

     ‘unsigned int status’
          This is a bit-wise OR of the following flags that give more
          information about what part of the key was imported.  If the
          key was already known, this might be 0.

          ‘GPGME_IMPORT_NEW’
               The key was new.

          ‘GPGME_IMPORT_UID’
               The key contained new user IDs.

          ‘GPGME_IMPORT_SIG’
               The key contained new signatures.

          ‘GPGME_IMPORT_SUBKEY’
               The key contained new sub keys.

          ‘GPGME_IMPORT_SECRET’
               The key contained a secret key.

 -- Data type: gpgme_import_result_t
     This is a pointer to a structure used to store the result of a
     ‘gpgme_op_import’ operation.  After a successful import operation,
     you can retrieve the pointer to the result with
     ‘gpgme_op_import_result’.  The structure contains the following
     members:

     ‘int considered’
          The total number of considered keys.

     ‘int no_user_id’
          The number of keys without user ID.

     ‘int imported’
          The total number of imported keys.

     ‘int imported_rsa’
          The number of imported RSA keys.

     ‘int unchanged’
          The number of unchanged keys.

     ‘int new_user_ids’
          The number of new user IDs.

     ‘int new_sub_keys’
          The number of new sub keys.

     ‘int new_signatures’
          The number of new signatures.

     ‘int new_revocations’
          The number of new revocations.

     ‘int secret_read’
          The total number of secret keys read.

     ‘int secret_imported’
          The number of imported secret keys.

     ‘int secret_unchanged’
          The number of unchanged secret keys.

     ‘int not_imported’
          The number of keys not imported.

     ‘gpgme_import_status_t imports’
          A list of gpgme_import_status_t objects which contain more
          information about the keys for which an import was attempted.

 -- Function: gpgme_import_result_t gpgme_op_import_result
          (gpgme_ctx_t CTX)
     The function ‘gpgme_op_import_result’ returns a
     ‘gpgme_import_result_t’ pointer to a structure holding the result
     of a ‘gpgme_op_import’ operation.  The pointer is only valid if the
     last operation on the context was a ‘gpgme_op_import’ or
     ‘gpgme_op_import_start’ operation, and if this operation finished
     successfully.  The returned pointer is only valid until the next
     operation is started on the context.

   ---------- Footnotes ----------

   (1) Thus it is a replacement for the usual workaround of exporting
and then importing a key to make an X.509 key permanent.


File: gpgme.info,  Node: Deleting Keys,  Next: Changing Passphrases,  Prev: Importing Keys,  Up: Key Management

7.5.9 Deleting Keys
-------------------

 -- Function: gpgme_error_t gpgme_op_delete (gpgme_ctx_t CTX,
          const gpgme_key_t KEY, int ALLOW_SECRET)
     The function ‘gpgme_op_delete’ deletes the key KEY from the key
     ring of the crypto engine used by CTX.  If ALLOW_SECRET is ‘0’,
     only public keys are deleted, otherwise secret keys are deleted as
     well, if that is supported.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the key
     was deleted successfully, ‘GPG_ERR_INV_VALUE’ if CTX or KEY is not
     a valid pointer, ‘GPG_ERR_NO_PUBKEY’ if KEY could not be found in
     the keyring, ‘GPG_ERR_AMBIGUOUS_NAME’ if the key was not specified
     unambiguously, and ‘GPG_ERR_CONFLICT’ if the secret key for KEY is
     available, but ALLOW_SECRET is zero.

 -- Function: gpgme_error_t gpgme_op_delete_start (gpgme_ctx_t CTX,
          const gpgme_key_t KEY, int ALLOW_SECRET)
     The function ‘gpgme_op_delete_start’ initiates a ‘gpgme_op_delete’
     operation.  It can be completed by calling ‘gpgme_wait’ on the
     context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation was started successfully, and ‘GPG_ERR_INV_VALUE’ if CTX
     or KEY is not a valid pointer.


File: gpgme.info,  Node: Changing Passphrases,  Next: Changing TOFU Data,  Prev: Deleting Keys,  Up: Key Management

7.5.10 Changing Passphrases
---------------------------

 -- Function: gpgme_error_t gpgme_op_passwd (gpgme_ctx_t CTX,
          const gpgme_key_t KEY, unsigned int FLAGS)

     The function ‘gpgme_op_passwd’ changes the passphrase of the
     private key associated with KEY.  The only allowed value for FLAGS
     is ‘0’.  The backend engine will usually popup a window to ask for
     the old and the new passphrase.  Thus this function is not useful
     in a server application (where passphrases are not required
     anyway).

     Note that old ‘gpg’ engines (before version 2.0.15) do not support
     this command and will silently ignore it.

 -- Function: gpgme_error_t gpgme_op_passwd_start (gpgme_ctx_t CTX,
          const gpgme_key_t KEY, unsigned int FLAGS)

     The function ‘gpgme_op_passwd_start’ initiates a ‘gpgme_op_passwd’
     operation.  It can be completed by calling ‘gpgme_wait’ on the
     context.  *Note Waiting For Completion::.

     The function returns ‘0’ if the operation was started successfully,
     and an error code if one of the arguments is not valid or the
     oepration could not be started.


File: gpgme.info,  Node: Changing TOFU Data,  Next: Advanced Key Editing,  Prev: Changing Passphrases,  Up: Key Management

7.5.11 Changing TOFU Data
-------------------------

The OpenPGP engine features a Trust-On-First-Use (TOFU) key validation
model.  For resolving clonflics it is necessary to declare the policy
for a key.  See the GnuPG manual for details on the TOFU implementation.

 -- Data type: enum gpgme_tofu_policy_t
     The ‘gpgme_tofu_policy_t’ type specifies the set of possible policy
     values that are supported by GPGME:

     ‘GPGME_TOFU_POLICY_AUTO’
          Set the policy to “auto”.
     ‘GPGME_TOFU_POLICY_GOOD’
          Set the policy to “goog”.
     ‘GPGME_TOFU_POLICY_BAD’
          Set the policy to “bad”.
     ‘GPGME_TOFU_POLICY_ASK’
          Set the policy to “ask”.
     ‘GPGME_TOFU_POLICY_UNKNOWN’
          Set the policy to “unknown”.

   To change the policy for a key the following functions can be used:

 -- Function: gpgme_error_t gpgme_op_tofu_policy (gpgme_ctx_t CTX,
          const gpgme_key_t KEY, gpgme_tofu_policy_t POLICY)

     The function ‘gpgme_op_tofu_policy’ changes the TOFU policy of KEY.
     The valid values for POLICY are listed above.  As of now this
     function does only work for OpenPGP and requires at least version
     2.1.10 of GnuPG.

     The function returns zero on success, ‘GPG_ERR_NOT_SUPPORTED’ if
     the engine does not support the command, or a bunch of other error
     codes.

 -- Function: gpgme_error_t gpgme_op_tofu_policy_start (gpgme_ctx_t CTX,
          const gpgme_key_t KEY, gpgme_tofu_policy_t POLICY)

     The function ‘gpgme_op_tofu_policy_start’ initiates a
     ‘gpgme_op_tofu_policy’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     The function returns ‘0’ if the operation was started successfully,
     and an error code if one of the arguments is not valid or the
     oepration could not be started.


File: gpgme.info,  Node: Advanced Key Editing,  Prev: Changing TOFU Data,  Up: Key Management

7.5.12 Advanced Key Editing
---------------------------

 -- Data type: gpgme_error_t (*gpgme_interact_cb_t) (void *HANDLE,
          const char *STATUS, const char *ARGS, int FD)
     The ‘gpgme_interact_cb_t’ type is the type of functions which GPGME
     calls if it a key interact operation is on-going.  The status
     keyword STATUS and the argument line ARGS are passed through by
     GPGME from the crypto engine.  An empty string represents EOF. The
     file descriptor FD is -1 for normal status messages.  If STATUS
     indicates a command rather than a status message, the response to
     the command should be written to FD.  The HANDLE is provided by the
     user at start of operation.

     The function should return ‘GPG_ERR_FALSE’ if it did not handle the
     status code, ‘0’ for success, or any other error value.

 -- Function: gpgme_error_t gpgme_op_interact (gpgme_ctx_t CTX,
          gpgme_key_t KEY, unsigned int FLAGS, gpgme_interact_cb_t FNC,
          void *HANDLE, gpgme_data_t OUT)
     The function ‘gpgme_op_interact’ processes the key KEY
     interactively, using the interact callback function FNC with the
     handle HANDLE.  The callback is invoked for every status and
     command request from the crypto engine.  The output of the crypto
     engine is written to the data object OUT.

     Note that the protocol between the callback function and the crypto
     engine is specific to the crypto engine and no further support in
     implementing this protocol correctly is provided by GPGME.

     FLAGS modifies the behaviour of the function; the only defined bit
     value is:

     ‘GPGME_INTERACT_CARD’
          This is used for smartcard based keys and uses gpg’s
          ‘--card-edit’ command.

     The function returns ‘0’ if the edit operation completes
     successfully, ‘GPG_ERR_INV_VALUE’ if CTX or KEY is not a valid
     pointer, and any error returned by the crypto engine or the edit
     callback handler.

 -- Function: gpgme_error_t gpgme_op_interact_start (gpgme_ctx_t CTX,
          gpgme_key_t KEY, unsigned int FLAGS, gpgme_interact_cb_t FNC,
          void *HANDLE, gpgme_data_t OUT)
     The function ‘gpgme_op_interact_start’ initiates a
     ‘gpgme_op_interact’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     The function returns ‘0’ if the operation was started successfully,
     and ‘GPG_ERR_INV_VALUE’ if CTX or KEY is not a valid pointer.


File: gpgme.info,  Node: Trust Item Management,  Next: Crypto Operations,  Prev: Key Management,  Up: Contexts

7.6 Trust Item Management
=========================

*Caution:* The trust items interface is experimental.

 -- Data type: gpgme_trust_item_t
     The ‘gpgme_trust_item_t’ type is a pointer to a trust item object.
     It has the following members:

     ‘char *keyid’
          This is a string describing the key to which this trust items
          belongs.

     ‘int type’
          This is the type of the trust item.  A value of 1 refers to a
          key, a value of 2 refers to a user ID.

     ‘int level’
          This is the trust level.

     ‘char *owner_trust’
          The owner trust if ‘type’ is 1.

     ‘char *validity’
          The calculated validity.

     ‘char *name’
          The user name if ‘type’ is 2.

* Menu:

* Listing Trust Items::           Browsing the list of available trust items.
* Manipulating Trust Items::      Operations on trust items.


File: gpgme.info,  Node: Listing Trust Items,  Next: Manipulating Trust Items,  Up: Trust Item Management

7.6.1 Listing Trust Items
-------------------------

 -- Function: gpgme_error_t gpgme_op_trustlist_start (gpgme_ctx_t CTX,
          const char *PATTERN, int MAX_LEVEL)
     The function ‘gpgme_op_trustlist_start’ initiates a trust item
     listing operation inside the context CTX.  It sets everything up so
     that subsequent invocations of ‘gpgme_op_trustlist_next’ return the
     trust items in the list.

     The string PATTERN contains an engine specific expression that is
     used to limit the list to all trust items matching the pattern.  It
     can not be the empty string.

     The argument MAX_LEVEL is currently ignored.

     The context will be busy until either all trust items are received
     (and ‘gpgme_op_trustlist_next’ returns ‘GPG_ERR_EOF’), or
     ‘gpgme_op_trustlist_end’ is called to finish the operation.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if CTX is
     not a valid pointer, and passes through any errors that are
     reported by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_trustlist_next (gpgme_ctx_t CTX,
          gpgme_trust_item_t *R_ITEM)
     The function ‘gpgme_op_trustlist_next’ returns the next trust item
     in the list created by a previous ‘gpgme_op_trustlist_start’
     operation in the context CTX.  The trust item can be destroyed with
     ‘gpgme_trust_item_release’.  *Note Manipulating Trust Items::.

     This is the only way to get at ‘gpgme_trust_item_t’ objects in
     GPGME.

     If the last trust item in the list has already been returned,
     ‘gpgme_op_trustlist_next’ returns ‘GPG_ERR_EOF’.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if CTX or
     R_ITEM is not a valid pointer, and ‘GPG_ERR_ENOMEM’ if there is not
     enough memory for the operation.

 -- Function: gpgme_error_t gpgme_op_trustlist_end (gpgme_ctx_t CTX)
     The function ‘gpgme_op_trustlist_end’ ends a pending trust list
     operation in the context CTX.

     The function returns the error code ‘GPG_ERR_INV_VALUE’ if CTX is
     not a valid pointer, and ‘GPG_ERR_ENOMEM’ if at some time during
     the operation there was not enough memory available.


File: gpgme.info,  Node: Manipulating Trust Items,  Prev: Listing Trust Items,  Up: Trust Item Management

7.6.2 Manipulating Trust Items
------------------------------

 -- Function: void gpgme_trust_item_ref (gpgme_trust_item_t ITEM)
     The function ‘gpgme_trust_item_ref’ acquires an additional
     reference for the trust item ITEM.

 -- Function: void gpgme_trust_item_unref (gpgme_trust_item_t ITEM)
     The function ‘gpgme_trust_item_unref’ releases a reference for the
     trust item ITEM.  If this was the last reference, the trust item
     will be destroyed and all resources associated to it will be
     released.


File: gpgme.info,  Node: Crypto Operations,  Next: Miscellaneous,  Prev: Trust Item Management,  Up: Contexts

7.7 Crypto Operations
=====================

Sometimes, the result of a crypto operation returns a list of invalid
keys encountered in processing the request.  The following structure is
used to hold information about such a key.

 -- Data type: gpgme_invalid_key_t
     This is a pointer to a structure used to store a part of the result
     of a crypto operation which takes user IDs as one input parameter.
     The structure contains the following members:

     ‘gpgme_invalid_key_t next’
          This is a pointer to the next invalid key structure in the
          linked list, or ‘NULL’ if this is the last element.

     ‘char *fpr’
          The fingerprint or key ID of the invalid key encountered.

     ‘gpgme_error_t reason’
          An error code describing the reason why the key was found
          invalid.

* Menu:

* Decrypt::                       Decrypting a ciphertext.
* Verify::                        Verifying a signature.
* Decrypt and Verify::            Decrypting a signed ciphertext.
* Sign::                          Creating a signature.
* Encrypt::                       Encrypting a plaintext.


File: gpgme.info,  Node: Decrypt,  Next: Verify,  Up: Crypto Operations

7.7.1 Decrypt
-------------

 -- Function: gpgme_error_t gpgme_op_decrypt (gpgme_ctx_t CTX,
          gpgme_data_t CIPHER, gpgme_data_t PLAIN)
     The function ‘gpgme_op_decrypt’ decrypts the ciphertext in the data
     object CIPHER and stores it into the data object PLAIN.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     ciphertext could be decrypted successfully, ‘GPG_ERR_INV_VALUE’ if
     CTX, CIPHER or PLAIN is not a valid pointer, ‘GPG_ERR_NO_DATA’ if
     CIPHER does not contain any data to decrypt,
     ‘GPG_ERR_DECRYPT_FAILED’ if CIPHER is not a valid cipher text,
     ‘GPG_ERR_BAD_PASSPHRASE’ if the passphrase for the secret key could
     not be retrieved, and passes through any errors that are reported
     by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_decrypt_start (gpgme_ctx_t CTX,
          gpgme_data_t CIPHER, gpgme_data_t PLAIN)
     The function ‘gpgme_op_decrypt_start’ initiates a
     ‘gpgme_op_decrypt’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, and ‘GPG_ERR_INV_VALUE’ if
     CIPHER or PLAIN is not a valid pointer.

 -- Data type: gpgme_recipient_t
     This is a pointer to a structure used to store information about
     the recipient of an encrypted text which is decrypted in a
     ‘gpgme_op_decrypt’ operation.  This information (except for the
     status field) is even available before the operation finished
     successfully, for example in a passphrase callback.  The structure
     contains the following members:

     ‘gpgme_recipient_t next’
          This is a pointer to the next recipient structure in the
          linked list, or ‘NULL’ if this is the last element.

     ‘gpgme_pubkey_algo_t’
          The public key algorithm used in the encryption.

     ‘char *keyid’
          This is the key ID of the key (in hexadecimal digits) used as
          recipient.

     ‘gpgme_error_t status’
          This is an error number with the error code GPG_ERR_NO_SECKEY
          if the secret key for this recipient is not available, and 0
          otherwise.

 -- Data type: gpgme_decrypt_result_t
     This is a pointer to a structure used to store the result of a
     ‘gpgme_op_decrypt’ operation.  After successfully decrypting data,
     you can retrieve the pointer to the result with
     ‘gpgme_op_decrypt_result’.  As with all result structures, it this
     structure shall be considered read-only and an application must not
     allocated such a strucure on its own.  The structure contains the
     following members:

     ‘char *unsupported_algorithm’
          If an unsupported algorithm was encountered, this string
          describes the algorithm that is not supported.

     ‘unsigned int wrong_key_usage : 1’
          This is true if the key was not used according to its policy.

     ‘gpgme_recipient_t recipients’
          This is a linked list of recipients to which this message was
          encrypted.

     ‘char *file_name’
          This is the filename of the original plaintext message file if
          it is known, otherwise this is a null pointer.

     ‘char *session_key’
          A textual representation (nul-terminated string) of the
          session key used in symmetric encryption of the message, if
          the context has been set to export session keys (see
          ‘gpgme_set_ctx_flag, "export-session-key"’), and a session key
          was available for the most recent decryption operation.
          Otherwise, this is a null pointer.

          You must not try to access this member of the struct unless
          ‘gpgme_set_ctx_flag (ctx, "export-session-key")’ returns
          success or ‘gpgme_get_ctx_flag (ctx, "export-session-key")’
          returns true (non-empty string).

 -- Function: gpgme_decrypt_result_t gpgme_op_decrypt_result
          (gpgme_ctx_t CTX)
     The function ‘gpgme_op_decrypt_result’ returns a
     ‘gpgme_decrypt_result_t’ pointer to a structure holding the result
     of a ‘gpgme_op_decrypt’ operation.  The pointer is only valid if
     the last operation on the context was a ‘gpgme_op_decrypt’ or
     ‘gpgme_op_decrypt_start’ operation.  If the operation failed this
     might be a ‘NULL’ pointer.  The returned pointer is only valid
     until the next operation is started on the context.


File: gpgme.info,  Node: Verify,  Next: Decrypt and Verify,  Prev: Decrypt,  Up: Crypto Operations

7.7.2 Verify
------------

 -- Function: gpgme_error_t gpgme_op_verify (gpgme_ctx_t CTX,
          gpgme_data_t SIG, gpgme_data_t SIGNED_TEXT,
          gpgme_data_t PLAIN)
     The function ‘gpgme_op_verify’ verifies that the signature in the
     data object SIG is a valid signature.  If SIG is a detached
     signature, then the signed text should be provided in SIGNED_TEXT
     and PLAIN should be a null pointer.  Otherwise, if SIG is a normal
     (or cleartext) signature, SIGNED_TEXT should be a null pointer and
     PLAIN should be a writable data object that will contain the
     plaintext after successful verification.

     The results of the individual signature verifications can be
     retrieved with ‘gpgme_op_verify_result’.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be completed successfully, ‘GPG_ERR_INV_VALUE’ if
     CTX, SIG or PLAIN is not a valid pointer, ‘GPG_ERR_NO_DATA’ if SIG
     does not contain any data to verify, and passes through any errors
     that are reported by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_verify_start (gpgme_ctx_t CTX,
          gpgme_data_t SIG, gpgme_data_t SIGNED_TEXT,
          gpgme_data_t PLAIN)
     The function ‘gpgme_op_verify_start’ initiates a ‘gpgme_op_verify’
     operation.  It can be completed by calling ‘gpgme_wait’ on the
     context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, ‘GPG_ERR_INV_VALUE’ if
     CTX, SIG or PLAIN is not a valid pointer, and ‘GPG_ERR_NO_DATA’ if
     SIG or PLAIN does not contain any data to verify.

 -- Data type: gpgme_sig_notation_t
     This is a pointer to a structure used to store a part of the result
     of a ‘gpgme_op_verify’ operation.  The structure contains the
     following members:

     ‘gpgme_sig_notation_t next’
          This is a pointer to the next new signature notation structure
          in the linked list, or ‘NULL’ if this is the last element.

     ‘char *name’
          The name of the notation field.  If this is ‘NULL’, then the
          member ‘value’ will contain a policy URL.

     ‘int name_len’
          The length of the ‘name’ field.  For strings the length is
          counted without the trailing binary zero.

     ‘char *value’
          The value of the notation field.  If ‘name’ is ‘NULL’, then
          this is a policy URL.

     ‘int value_len’
          The length of the ‘value’ field.  For strings the length is
          counted without the trailing binary zero.

     ‘gpgme_sig_notation_flags_t flags’
          The accumulated flags field.  This field contains the flags
          associated with the notation data in an accumulated form which
          can be used as an argument to the function
          ‘gpgme_sig_notation_add’.  The value ‘flags’ is a bitwise-or
          combination of one or multiple of the following bit values:

          ‘GPGME_SIG_NOTATION_HUMAN_READABLE’
               The ‘GPGME_SIG_NOTATION_HUMAN_READABLE’ symbol specifies
               that the notation data is in human readable form

          ‘GPGME_SIG_NOTATION_CRITICAL’
               The ‘GPGME_SIG_NOTATION_CRITICAL’ symbol specifies that
               the notation data is critical.

     ‘unsigned int human_readable : 1’
          This is true if the ‘GPGME_SIG_NOTATION_HUMAN_READABLE’ flag
          is set and false otherwise.  This flag is only valid for
          notation data, not for policy URLs.

     ‘unsigned int critical : 1’
          This is true if the ‘GPGME_SIG_NOTATION_CRITICAL’ flag is set
          and false otherwise.  This flag is valid for notation data and
          policy URLs.

 -- Data type: gpgme_signature_t
     This is a pointer to a structure used to store a part of the result
     of a ‘gpgme_op_verify’ operation.  The structure contains the
     following members:

     ‘gpgme_signature_t next’
          This is a pointer to the next new signature structure in the
          linked list, or ‘NULL’ if this is the last element.

     ‘gpgme_sigsum_t summary’
          This is a bit vector giving a summary of the signature status.
          It provides an easy interface to a defined semantic of the
          signature status.  Checking just one bit is sufficient to see
          whether a signature is valid without any restrictions.

          The defined bits are:
          ‘GPGME_SIGSUM_VALID’
               The signature is fully valid.

          ‘GPGME_SIGSUM_GREEN’
               The signature is good but one might want to display some
               extra information.  Check the other bits.

          ‘GPGME_SIGSUM_RED’
               The signature is bad.  It might be useful to check other
               bits and display more information, i.e.  a revoked
               certificate might not render a signature invalid when the
               message was received prior to the cause for the
               revocation.

          ‘GPGME_SIGSUM_KEY_REVOKED’
               The key or at least one certificate has been revoked.

          ‘GPGME_SIGSUM_KEY_EXPIRED’
               The key or one of the certificates has expired.  It is
               probably a good idea to display the date of the
               expiration.

          ‘GPGME_SIGSUM_SIG_EXPIRED’
               The signature has expired.

          ‘GPGME_SIGSUM_KEY_MISSING’
               Can’t verify due to a missing key or certificate.

          ‘GPGME_SIGSUM_CRL_MISSING’
               The CRL (or an equivalent mechanism) is not available.

          ‘GPGME_SIGSUM_CRL_TOO_OLD’
               Available CRL is too old.

          ‘GPGME_SIGSUM_BAD_POLICY’
               A policy requirement was not met.

          ‘GPGME_SIGSUM_SYS_ERROR’
               A system error occured.

     ‘char *fpr’
          This is the fingerprint or key ID of the signature.

     ‘gpgme_error_t status’
          This is the status of the signature.  In particular, the
          following status codes are of interest:

          ‘GPG_ERR_NO_ERROR’
               This status indicates that the signature is valid.  For
               the combined result this status means that all signatures
               are valid.

          ‘GPG_ERR_SIG_EXPIRED’
               This status indicates that the signature is valid but
               expired.  For the combined result this status means that
               all signatures are valid and expired.

          ‘GPG_ERR_KEY_EXPIRED’
               This status indicates that the signature is valid but the
               key used to verify the signature has expired.  For the
               combined result this status means that all signatures are
               valid and all keys are expired.

          ‘GPG_ERR_CERT_REVOKED’
               This status indicates that the signature is valid but the
               key used to verify the signature has been revoked.  For
               the combined result this status means that all signatures
               are valid and all keys are revoked.

          ‘GPG_ERR_BAD_SIGNATURE’
               This status indicates that the signature is invalid.  For
               the combined result this status means that all signatures
               are invalid.

          ‘GPG_ERR_NO_PUBKEY’
               This status indicates that the signature could not be
               verified due to a missing key.  For the combined result
               this status means that all signatures could not be
               checked due to missing keys.

          ‘GPG_ERR_GENERAL’
               This status indicates that there was some other error
               which prevented the signature verification.

     ‘gpgme_sig_notation_t notations’
          This is a linked list with the notation data and policy URLs.

     ‘unsigned long timestamp’
          The creation timestamp of this signature.

     ‘unsigned long exp_timestamp’
          The expiration timestamp of this signature, or 0 if the
          signature does not expire.

     ‘unsigned int wrong_key_usage : 1’
          This is true if the key was not used according to its policy.

     ‘unsigned int pka_trust : 2’
          This is set to the trust information gained by means of the
          PKA system.  Values are:
          ‘0’
               No PKA information available or verification not
               possible.
          ‘1’
               PKA verification failed.
          ‘2’
               PKA verification succeeded.
          ‘3’
               Reserved for future use.
          Depending on the configuration of the engine, this metric may
          also be reflected by the validity of the signature.

     ‘unsigned int chain_model : 1’
          This is true if the validity of the signature has been checked
          using the chain model.  In the chain model the time the
          signature has been created must be within the validity period
          of the certificate and the time the certificate itself has
          been created must be within the validity period of the issuing
          certificate.  In contrast the default validation model checks
          the validity of signature as well at the entire certificate
          chain at the current time.

     ‘gpgme_validity_t validity’
          The validity of the signature.

     ‘gpgme_error_t validity_reason’
          If a signature is not valid, this provides a reason why.

     ‘gpgme_pubkey_algo_t’
          The public key algorithm used to create this signature.

     ‘gpgme_hash_algo_t’
          The hash algorithm used to create this signature.

     ‘char *pka_address’
          The mailbox from the PKA information or ‘NULL’.

     ‘gpgme_key_t key’
          An object describing the key used to create the signature.
          This key object may be incomplete in that it only conveys
          information availabale directly with a signature.  It may also
          be ‘NULL’ if such information is not readily available.

 -- Data type: gpgme_verify_result_t
     This is a pointer to a structure used to store the result of a
     ‘gpgme_op_verify’ operation.  After verifying a signature, you can
     retrieve the pointer to the result with ‘gpgme_op_verify_result’.
     If the operation failed this might be a ‘NULL’ pointer.  The
     structure contains the following member:

     ‘gpgme_signature_t signatures’
          A linked list with information about all signatures for which
          a verification was attempted.

     ‘char *file_name’
          This is the filename of the original plaintext message file if
          it is known, otherwise this is a null pointer.

 -- Function: gpgme_verify_result_t gpgme_op_verify_result
          (gpgme_ctx_t CTX)
     The function ‘gpgme_op_verify_result’ returns a
     ‘gpgme_verify_result_t’ pointer to a structure holding the result
     of a ‘gpgme_op_verify’ operation.  The pointer is only valid if the
     last operation on the context was a ‘gpgme_op_verify’,
     ‘gpgme_op_verify_start’, ‘gpgme_op_decrypt_verify’ or
     ‘gpgme_op_decrypt_verify_start’ operation, and if this operation
     finished successfully (for ‘gpgme_op_decrypt_verify’ and
     ‘gpgme_op_decrypt_verify_start’, the error code ‘GPG_ERR_NO_DATA’
     counts as successful in this context).  The returned pointer is
     only valid until the next operation is started on the context.


File: gpgme.info,  Node: Decrypt and Verify,  Next: Sign,  Prev: Verify,  Up: Crypto Operations

7.7.3 Decrypt and Verify
------------------------

 -- Function: gpgme_error_t gpgme_op_decrypt_verify (gpgme_ctx_t CTX,
          gpgme_data_t CIPHER, gpgme_data_t PLAIN)
     The function ‘gpgme_op_decrypt_verify’ decrypts the ciphertext in
     the data object CIPHER and stores it into the data object PLAIN.
     If CIPHER contains signatures, they will be verified.

     After the operation completed, ‘gpgme_op_decrypt_result’ and
     ‘gpgme_op_verify_result’ can be used to retrieve more information
     about the signatures.

     If the error code ‘GPG_ERR_NO_DATA’ is returned, CIPHER does not
     contain any data to decrypt.  However, it might still be signed.
     The information about detected signatures is available with
     ‘gpgme_op_verify_result’ in this case.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     ciphertext could be decrypted successfully, ‘GPG_ERR_INV_VALUE’ if
     CTX, CIPHER or PLAIN is not a valid pointer, ‘GPG_ERR_NO_DATA’ if
     CIPHER does not contain any data to decrypt,
     ‘GPG_ERR_DECRYPT_FAILED’ if CIPHER is not a valid cipher text,
     ‘GPG_ERR_BAD_PASSPHRASE’ if the passphrase for the secret key could
     not be retrieved, and passes through any errors that are reported
     by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_decrypt_verify_start
          (gpgme_ctx_t CTX, gpgme_data_t CIPHER, gpgme_data_t PLAIN)
     The function ‘gpgme_op_decrypt_verify_start’ initiates a
     ‘gpgme_op_decrypt_verify’ operation.  It can be completed by
     calling ‘gpgme_wait’ on the context.  *Note Waiting For
     Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, ‘GPG_ERR_INV_VALUE’ if
     CTX, CIPHER, PLAIN or R_STAT is not a valid pointer, and
     ‘GPG_ERR_NO_DATA’ if CIPHER does not contain any data to decrypt.

   When processing mails it is sometimes useful to extract the actual
mail address (the “addr-spec”) from a string.  GPGME provides this
helper function which uses the same semantics as the internal functions
in GPGME and GnuPG:

 -- Function: char * gpgme_addrspec_from_uid (const char *UID)

     Return the mail address (called “addr-spec” in RFC-5322) from the
     string UID which is assumed to be a user id (called “address” in
     RFC-5322).  All plain ASCII characters (i.e.  those with bit 7
     cleared) in the result are converted to lowercase.  Caller must
     free the result using ‘gpgme_free’.  Returns ‘NULL’ if no valid
     address was found (in which case ‘ERRNO’ is set to ‘EINVAL’) or for
     other errors.


File: gpgme.info,  Node: Sign,  Next: Encrypt,  Prev: Decrypt and Verify,  Up: Crypto Operations

7.7.4 Sign
----------

A signature can contain signatures by one or more keys.  The set of keys
used to create a signatures is contained in a context, and is applied to
all following signing operations in this context (until the set is
changed).

* Menu:

* Selecting Signers::             How to choose the keys to sign with.
* Creating a Signature::          How to create a signature.
* Signature Notation Data::       How to add notation data to a signature.


File: gpgme.info,  Node: Selecting Signers,  Next: Creating a Signature,  Up: Sign

7.7.4.1 Selecting Signers
.........................

The key or the keys used to create a signature are stored in the
context.  The following functions can be used to manipulate this list.
If no signer has been set into the context a default key is used for
signing.

 -- Function: void gpgme_signers_clear (gpgme_ctx_t CTX)
     The function ‘gpgme_signers_clear’ releases a reference for each
     key on the signers list and removes the list of signers from the
     context CTX.

     Every context starts with an empty list.

 -- Function: gpgme_error_t gpgme_signers_add (gpgme_ctx_t CTX,
          const gpgme_key_t KEY)
     The function ‘gpgme_signers_add’ adds the key KEY to the list of
     signers in the context CTX.

     Calling this function acquires an additional reference for the key.

 -- Function: unsigned int gpgme_signers_count (const gpgme_ctx_t CTX)
     The function ‘gpgme_signers_count’ returns the number of signer
     keys in the context CTX.

 -- Function: gpgme_key_t gpgme_signers_enum (const gpgme_ctx_t CTX,
          int SEQ)
     The function ‘gpgme_signers_enum’ returns the SEQth key in the list
     of signers in the context CTX.  An additional reference is acquired
     for the user.

     If SEQ is out of range, ‘NULL’ is returned.


File: gpgme.info,  Node: Creating a Signature,  Next: Signature Notation Data,  Prev: Selecting Signers,  Up: Sign

7.7.4.2 Creating a Signature
............................

 -- Data type: enum gpgme_sig_mode_t
     The ‘gpgme_sig_mode_t’ type is used to specify the desired type of
     a signature.  The following modes are available:

     ‘GPGME_SIG_MODE_NORMAL’
          A normal signature is made, the output includes the plaintext
          and the signature.

     ‘GPGME_SIG_MODE_DETACH’
          A detached signature is made.

     ‘GPGME_SIG_MODE_CLEAR’
          A clear text signature is made.  The ASCII armor and text mode
          settings of the context are ignored.

 -- Function: gpgme_error_t gpgme_op_sign (gpgme_ctx_t CTX,
          gpgme_data_t PLAIN, gpgme_data_t SIG, gpgme_sig_mode_t MODE)
     The function ‘gpgme_op_sign’ creates a signature for the text in
     the data object PLAIN and returns it in the data object SIG.  The
     type of the signature created is determined by the ASCII armor (or,
     if that is not set, by the encoding specified for SIG), the text
     mode attributes set for the context CTX and the requested signature
     mode MODE.

     After the operation completed successfully, the result can be
     retrieved with ‘gpgme_op_sign_result’.

     If an S/MIME signed message is created using the CMS crypto engine,
     the number of certificates to include in the message can be
     specified with ‘gpgme_set_include_certs’.  *Note Included
     Certificates::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     signature could be created successfully, ‘GPG_ERR_INV_VALUE’ if
     CTX, PLAIN or SIG is not a valid pointer, ‘GPG_ERR_NO_DATA’ if the
     signature could not be created, ‘GPG_ERR_BAD_PASSPHRASE’ if the
     passphrase for the secret key could not be retrieved,
     ‘GPG_ERR_UNUSABLE_SECKEY’ if there are invalid signers, and passes
     through any errors that are reported by the crypto engine support
     routines.

 -- Function: gpgme_error_t gpgme_op_sign_start (gpgme_ctx_t CTX,
          gpgme_data_t PLAIN, gpgme_data_t SIG, gpgme_sig_mode_t MODE)
     The function ‘gpgme_op_sign_start’ initiates a ‘gpgme_op_sign’
     operation.  It can be completed by calling ‘gpgme_wait’ on the
     context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, and ‘GPG_ERR_INV_VALUE’ if
     CTX, PLAIN or SIG is not a valid pointer.

 -- Data type: gpgme_new_signature_t
     This is a pointer to a structure used to store a part of the result
     of a ‘gpgme_op_sign’ operation.  The structure contains the
     following members:

     ‘gpgme_new_signature_t next’
          This is a pointer to the next new signature structure in the
          linked list, or ‘NULL’ if this is the last element.

     ‘gpgme_sig_mode_t type’
          The type of this signature.

     ‘gpgme_pubkey_algo_t pubkey_algo’
          The public key algorithm used to create this signature.

     ‘gpgme_hash_algo_t hash_algo’
          The hash algorithm used to create this signature.

     ‘unsigned int sig_class’
          The signature class of this signature.

     ‘long int timestamp’
          The creation timestamp of this signature.

     ‘char *fpr’
          The fingerprint of the key which was used to create this
          signature.

 -- Data type: gpgme_sign_result_t
     This is a pointer to a structure used to store the result of a
     ‘gpgme_op_sign’ operation.  After successfully generating a
     signature, you can retrieve the pointer to the result with
     ‘gpgme_op_sign_result’.  The structure contains the following
     members:

     ‘gpgme_invalid_key_t invalid_signers’
          A linked list with information about all invalid keys for
          which a signature could not be created.

     ‘gpgme_new_signature_t signatures’
          A linked list with information about all signatures created.

 -- Function: gpgme_sign_result_t gpgme_op_sign_result (gpgme_ctx_t CTX)
     The function ‘gpgme_op_sign_result’ returns a ‘gpgme_sign_result_t’
     pointer to a structure holding the result of a ‘gpgme_op_sign’
     operation.  The pointer is only valid if the last operation on the
     context was a ‘gpgme_op_sign’, ‘gpgme_op_sign_start’,
     ‘gpgme_op_encrypt_sign’ or ‘gpgme_op_encrypt_sign_start’ operation.
     If that operation failed, the function might return a ‘NULL’
     pointer.  The returned pointer is only valid until the next
     operation is started on the context.


File: gpgme.info,  Node: Signature Notation Data,  Prev: Creating a Signature,  Up: Sign

7.7.4.3 Signature Notation Data
...............................

Using the following functions, you can attach arbitrary notation data to
a signature.  This information is then available to the user when the
signature is verified.

 -- Function: void gpgme_sig_notation_clear (gpgme_ctx_t CTX)
     The function ‘gpgme_sig_notation_clear’ removes the notation data
     from the context CTX.  Subsequent signing operations from this
     context will not include any notation data.

     Every context starts with an empty notation data list.

 -- Function: gpgme_error_t gpgme_sig_notation_add (gpgme_ctx_t CTX,
          const char *NAME, const char *VALUE,
          gpgme_sig_notation_flags_t FLAGS)
     The function ‘gpgme_sig_notation_add’ adds the notation data with
     the name NAME and the value VALUE to the context CTX.

     Subsequent signing operations will include this notation data, as
     well as any other notation data that was added since the creation
     of the context or the last ‘gpgme_sig_notation_clear’ operation.

     The arguments NAME and VALUE must be ‘NUL’-terminated strings in
     human-readable form.  The flag ‘GPGME_SIG_NOTATION_HUMAN_READABLE’
     is implied (non-human-readable notation data is currently not
     supported).  The strings must be in UTF-8 encoding.

     If NAME is ‘NULL’, then VALUE should be a policy URL.

     The function ‘gpgme_sig_notation_add’ returns the error code
     ‘GPG_ERR_NO_ERROR’ if the notation data could be added
     successfully, ‘GPG_ERR_INV_VALUE’ if CTX is not a valid pointer, or
     if NAME, VALUE and FLAGS are an invalid combination.  The function
     also passes through any errors that are reported by the crypto
     engine support routines.

 -- Function: gpgme_sig_notation_t gpgme_sig_notation_get
          (const gpgme_ctx_t CTX)
     The function ‘gpgme_sig_notation_get’ returns the linked list of
     notation data structures that are contained in the context CTX.

     If CTX is not a valid pointer, or there is no notation data added
     for this context, ‘NULL’ is returned.


File: gpgme.info,  Node: Encrypt,  Prev: Sign,  Up: Crypto Operations

7.7.5 Encrypt
-------------

One plaintext can be encrypted for several recipients at the same time.
The list of recipients is created independently of any context, and then
passed to the encryption operation.

* Menu:

* Encrypting a Plaintext::        How to encrypt a plaintext.


File: gpgme.info,  Node: Encrypting a Plaintext,  Up: Encrypt

7.7.5.1 Encrypting a Plaintext
..............................

 -- Function: gpgme_error_t gpgme_op_encrypt (gpgme_ctx_t CTX,
          gpgme_key_t RECP[], gpgme_encrypt_flags_t FLAGS,
          gpgme_data_t PLAIN, gpgme_data_t CIPHER)
     The function ‘gpgme_op_encrypt’ encrypts the plaintext in the data
     object PLAIN for the recipients RECP and stores the ciphertext in
     the data object CIPHER.  The type of the ciphertext created is
     determined by the ASCII armor (or, if that is not set, by the
     encoding specified for CIPHER) and the text mode attributes set for
     the context CTX.

     RECP must be a ‘NULL’-terminated array of keys.  The user must keep
     references for all keys during the whole duration of the call (but
     see ‘gpgme_op_encrypt_start’ for the requirements with the
     asynchronous variant).

     The value in FLAGS is a bitwise-or combination of one or multiple
     of the following bit values:

     ‘GPGME_ENCRYPT_ALWAYS_TRUST’
          The ‘GPGME_ENCRYPT_ALWAYS_TRUST’ symbol specifies that all the
          recipients in RECP should be trusted, even if the keys do not
          have a high enough validity in the keyring.  This flag should
          be used with care; in general it is not a good idea to use any
          untrusted keys.

     ‘GPGME_ENCRYPT_NO_ENCRYPT_TO’
          The ‘GPGME_ENCRYPT_NO_ENCRYPT_TO’ symbol specifies that no
          default or hidden default recipients as configured in the
          crypto backend should be included.  This can be useful for
          managing different user profiles.

     ‘GPGME_ENCRYPT_NO_COMPRESS’
          The ‘GPGME_ENCRYPT_NO_COMPRESS’ symbol specifies that the
          plaintext shall not be compressed before it is encrypted.
          This is in some cases useful if the length of the encrypted
          message may reveal information about the plaintext.

     ‘GPGME_ENCRYPT_PREPARE’
     ‘GPGME_ENCRYPT_EXPECT_SIGN’
          The ‘GPGME_ENCRYPT_PREPARE’ symbol is used with the UI Server
          protocol to prepare an encryption (i.e.  sending the
          ‘PREP_ENCRYPT’ command).  With the ‘GPGME_ENCRYPT_EXPECT_SIGN’
          symbol the UI Server is advised to also expect a sign command.

     ‘GPGME_ENCRYPT_SYMMETRIC’
          The ‘GPGME_ENCRYPT_SYMMETRIC’ symbol specifies that the output
          should be additionally encrypted symmetically even if
          recipients are provided.  This feature is only supported for
          for the OpenPGP crypto engine.

     If ‘GPG_ERR_UNUSABLE_PUBKEY’ is returned, some recipients in RECP
     are invalid, but not all.  In this case the plaintext might be
     encrypted for all valid recipients and returned in CIPHER (if this
     happens depends on the crypto engine).  More information about the
     invalid recipients is available with ‘gpgme_op_encrypt_result’.

     If RECP is ‘NULL’, symmetric rather than public key encryption is
     performed.  Symmetrically encrypted cipher text can be deciphered
     with ‘gpgme_op_decrypt’.  Note that in this case the crypto backend
     needs to retrieve a passphrase from the user.  Symmetric encryption
     is currently only supported for the OpenPGP crypto backend.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     ciphertext could be created successfully, ‘GPG_ERR_INV_VALUE’ if
     CTX, RECP, PLAIN or CIPHER is not a valid pointer,
     ‘GPG_ERR_UNUSABLE_PUBKEY’ if RECP contains some invalid recipients,
     ‘GPG_ERR_BAD_PASSPHRASE’ if the passphrase for the symmetric key
     could not be retrieved, and passes through any errors that are
     reported by the crypto engine support routines.

 -- Function: gpgme_error_t gpgme_op_encrypt_start (gpgme_ctx_t CTX,
          gpgme_key_t RECP[], gpgme_encrypt_flags_t FLAGS,
          gpgme_data_t PLAIN, gpgme_data_t CIPHER)
     The function ‘gpgme_op_encrypt_start’ initiates a
     ‘gpgme_op_encrypt’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     References to the keys only need to be held for the duration of
     this call.  The user can release its references to the keys after
     this function returns, even if the operation is not yet finished.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, ‘GPG_ERR_INV_VALUE’ if
     CTX, RSET, PLAIN or CIPHER is not a valid pointer, and
     ‘GPG_ERR_UNUSABLE_PUBKEY’ if RSET does not contain any valid
     recipients.

 -- Data type: gpgme_encrypt_result_t
     This is a pointer to a structure used to store the result of a
     ‘gpgme_op_encrypt’ operation.  After successfully encrypting data,
     you can retrieve the pointer to the result with
     ‘gpgme_op_encrypt_result’.  The structure contains the following
     members:

     ‘gpgme_invalid_key_t invalid_recipients’
          A linked list with information about all invalid keys for
          which the data could not be encrypted.

 -- Function: gpgme_encrypt_result_t gpgme_op_encrypt_result
          (gpgme_ctx_t CTX)
     The function ‘gpgme_op_encrypt_result’ returns a
     ‘gpgme_encrypt_result_t’ pointer to a structure holding the result
     of a ‘gpgme_op_encrypt’ operation.  The pointer is only valid if
     the last operation on the context was a ‘gpgme_op_encrypt’,
     ‘gpgme_op_encrypt_start’, ‘gpgme_op_sign’ or ‘gpgme_op_sign_start’
     operation.  If this operation failed, this might be a ‘NULL’
     pointer.  The returned pointer is only valid until the next
     operation is started on the context.

 -- Function: gpgme_error_t gpgme_op_encrypt_sign (gpgme_ctx_t CTX,
          gpgme_key_t RECP[], gpgme_encrypt_flags_t FLAGS,
          gpgme_data_t PLAIN, gpgme_data_t CIPHER)
     The function ‘gpgme_op_encrypt_sign’ does a combined encrypt and
     sign operation.  It is used like ‘gpgme_op_encrypt’, but the
     ciphertext also contains signatures for the signers listed in CTX.

     The combined encrypt and sign operation is currently only available
     for the OpenPGP crypto engine.

 -- Function: gpgme_error_t gpgme_op_encrypt_sign_start
          (gpgme_ctx_t CTX, gpgme_key_t RECP,
          gpgme_encrypt_flags_t FLAGS, gpgme_data_t PLAIN,
          gpgme_data_t CIPHER)
     The function ‘gpgme_op_encrypt_sign_start’ initiates a
     ‘gpgme_op_encrypt_sign’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation could be started successfully, and ‘GPG_ERR_INV_VALUE’ if
     CTX, RSET, PLAIN or CIPHER is not a valid pointer.


File: gpgme.info,  Node: Miscellaneous,  Next: Run Control,  Prev: Crypto Operations,  Up: Contexts

7.8 Miscellaneous operations
============================

Here are some support functions which are sometimes useful.

* Menu:

* Running other Programs::      Running other Programs
* Using the Assuan protocol::   Using the Assuan protocol
* Checking for updates::        How to check for software updates


File: gpgme.info,  Node: Running other Programs,  Next: Using the Assuan protocol,  Up: Miscellaneous

7.8.1 Running other Programs
----------------------------

GPGME features an internal subsystem to run the actual backend engines.
Along with data abstraction object this subsystem can be used to run
arbitrary simple programs which even need not be related to
cryptographic features.  It may for example be used to run tools which
are part of the GnuPG system but are not directly accessible with the
GPGME API.

 -- Function: gpgme_error_t gpgme_op_spawn (gpgme_ctx_t CTX,
          const char *FILE, const char *ARGV[], gpgme_data_t DATAIN,
          gpgme_data_t DATAOUT, gpgme_data_t DATAERR,
          unsigned int FLAGS)

     The function ‘gpgme_op_spawn’ runs the program FILE with the
     arguments taken from the NULL terminated array ARGV.  If no
     arguments are required ARGV may be given as ‘NULL’.  In the latter
     case or if ‘argv[0]’ is the empty string, GPGME uses the basename
     of FILE for ‘argv[0]’.  The file descriptors ‘stdin’, ‘stdout’, and
     ‘stderr’ are connected to the data objects DATAIN, DATAOUT, and
     DATAERR.  If NULL is passed for one of these data objects the
     corresponding file descriptor is connected to ‘/dev/null’.

     The value in FLAGS is a bitwise-or combination of one or multiple
     of the following bit values:

     ‘GPGME_SPAWN_DETACHED’
          Under Windows this flag inhibits the allocation of a new
          console for the program.  This is useful for a GUI application
          which needs to call a command line helper tool.
     ‘GPGME_SPAWN_ALLOW_SET_FG’
          Under Windows this flag allows the called program to put
          itself into the foreground.

 -- Function: gpgme_error_t gpgme_op_spawn_start (gpgme_ctx_t CTX,
          const char *FILE, const char *ARGV[], gpgme_data_t DATAIN,
          gpgme_data_t DATAOUT, gpgme_data_t DATAERR,
          unsigned int FLAGS)

     This is the asynchronous variant of ‘gpgme_op_spawn’.


File: gpgme.info,  Node: Using the Assuan protocol,  Next: Checking for updates,  Prev: Running other Programs,  Up: Miscellaneous

7.8.2 Using the Assuan protocol
-------------------------------

The Assuan protocol can be used to talk to arbitrary Assuan servers.  By
default it is connected to the GnuPG agent, but it may be connected to
arbitrary servers by using ‘gpgme_ctx_set_engine_info’, passing the
location of the servers socket as FILE_NAME argument, and an empty
string as HOME_DIR argument.

   The Assuan protocol functions use three kinds of callbacks to
transfer data:

 -- Data type: gpgme_error_t (*gpgme_assuan_data_cb_t) (void *OPAQUE,
          const void *DATA, size_t DATALEN)

     This callback receives any data sent by the server.  OPAQUE is the
     pointer passed to ‘gpgme_op_assuan_transact_start’, DATA of length
     DATALEN refers to the data sent.

 -- Data type: gpgme_error_t (*gpgme_assuan_inquire_cb_t) (void *OPAQUE,
          const char *NAME, const char *ARGS, gpgme_data_t *R_DATA)

     This callback is used to provide additional data to the Assuan
     server.  OPAQUE is the pointer passed to
     ‘gpgme_op_assuan_transact_start’, NAME and ARGS specify what kind
     of data the server requested, and R_DATA is used to return the
     actual data.

     Note: Returning data is currently not implemented in GPGME.

 -- Data type: gpgme_error_t (*gpgme_assuan_status_cb_t) (void *OPAQUE,
          const char *STATUS, const char *ARGS)

     This callback receives any status lines sent by the server.  OPAQUE
     is the pointer passed to ‘gpgme_op_assuan_transact_start’, STATUS
     and ARGS denote the status update sent.

 -- Function: gpgme_error_t gpgme_op_assuan_transact_start
          (gpgme_ctx_t CTX, const char *COMMAND,
          gpgme_assuan_data_cb_t DATA_CB, void * DATA_CB_VALUE,
          gpgme_assuan_inquire_cb_t INQUIRE_CB, void * INQUIRE_CB_VALUE,
          gpgme_assuan_status_cb_t STATUS_CB, void * STATUS_CB_VALUE)

     Send the Assuan COMMAND and return results via the callbacks.  Any
     callback may be ‘NULL’.  The result of the operation may be
     retrieved using ‘gpgme_wait_ext’.

     Asynchronous variant.

 -- Function: gpgme_error_t gpgme_op_assuan_transact_ext
          (gpgme_ctx_t CTX, const char *COMMAND,
          gpgme_assuan_data_cb_t DATA_CB, void * DATA_CB_VALUE,
          gpgme_assuan_inquire_cb_t INQUIRE_CB, void * INQUIRE_CB_VALUE,
          gpgme_assuan_status_cb_t STATUS_CB, void * STATUS_CB_VALUE,
          gpgme_error_t *OP_ERR)

     Send the Assuan COMMAND and return results via the callbacks.  The
     result of the operation is returned in OP_ERR.

     Synchronous variant.


File: gpgme.info,  Node: Checking for updates,  Prev: Using the Assuan protocol,  Up: Miscellaneous

7.8.3 How to check for software updates
---------------------------------------

The GnuPG Project operates a server to query the current versions of
software packages related to GnuPG. GPGME can be used to access this
online database and check whether a new version of a software package is
available.

 -- Data type: gpgme_query_swdb_result_t
     This is a pointer to a structure used to store the result of a
     ‘gpgme_op_query_swdb’ operation.  After success full call to that
     function, you can retrieve the pointer to the result with
     ‘gpgme_op_query_swdb_result’.  The structure contains the following
     member:

     ‘name’
          This is the name of the package.

     ‘iversion’
          The currently installed version or an empty string.  This
          value is either a copy of the argument given to
          ‘gpgme_op_query_swdb’ or the version of the installed software
          as figured out by GPGME or GnuPG.

     ‘created’
          This gives the date the file with the list of version numbers
          has originally be created by the GnuPG project.

     ‘retrieved’
          This gives the date the file was downloaded.

     ‘warning’
          If this flag is set either an error has occurred or some of
          the information in this structure are not properly set.  For
          example if the version number of the installed software could
          not be figured out, the ‘update’ flag may not reflect a
          required update status.

     ‘update’
          If this flag is set an update of the software is available.

     ‘urgent’
          If this flag is set an available update is important.

     ‘noinfo’
          If this flag is set, no valid information could be retrieved.

     ‘unknown’
          If this flag is set the given ‘name’ is not known.

     ‘tooold’
          If this flag is set the available information is not fresh
          enough.

     ‘error’
          If this flag is set some other error has occured.

     ‘version’
          The version string of the latest released version.

     ‘reldate’
          The release date of the latest released version.

 -- Function: gpgme_error_t gpgme_op_query_swdb (gpgme_ctx_t CTX,
          const char *NAME, const char *IVERSION, gpgme_data_t RESERVED)

     Query the software version database for software package NAME and
     check against the installed version given by IVERSION.  If IVERSION
     is given as ‘NULL’ a check is only done if GPGME can figure out the
     version by itself (for example when using "gpgme" or "gnupg").  If
     ‘NULL’ is used for NAME the current gpgme version is checked.
     RESERVED must be set to 0.

 -- Function: gpgme_query_swdb_result_t gpgme_op_query_swdb_result
          (gpgme_ctx_t CTX)

     The function ‘gpgme_op_query_swdb_result’ returns a
     ‘gpgme_query_swdb_result_t’ pointer to a structure holding the
     result of a ‘gpgme_op_query_swdb’ operation.  The pointer is only
     valid if the last operation on the context was a sucessful call to
     ‘gpgme_op_query_swdb’.  If that call failed, the result might be a
     ‘NULL’ pointer.  The returned pointer is only valid until the next
     operation is started on the context CTX.

Here is an example on how to check whether GnuPG is current:

     #include <gpgme.h>

     int
     main (void)
     {
       gpg_error_t err;
       gpgme_ctx_t ctx;
       gpgme_query_swdb_result_t result;

       gpgme_check_version (NULL);
       err = gpgme_new (&ctx);
       if (err)
         fprintf (stderr, "error creating context: %s\n", gpg_strerror (err));
       else
         {
           gpgme_set_protocol (ctx, GPGME_PROTOCOL_GPGCONF);

           err = gpgme_op_query_swdb (ctx, "gnupg", NULL, 0);
           if (err)
             fprintf (stderr, "error querying swdb: %s\n", gpg_strerror (err));
           else
             {
               result = gpgme_op_query_swdb_result (ctx);
               if (!result)
                 fprintf (stderr, "error querying swdb\n");
               if (!result->warning && !result->update)
                 printf ("GnuPG version %s is current\n",
                         result->iversion);
               else if (!result->warning && result->update)
                 printf ("GnuPG version %s can be updated to %s\n",
                         result->iversion, result->version);
               else
                 fprintf (stderr, "error finding the update status\n");
             }
           gpgme_release (ctx);
         }
       return 0;
     }


File: gpgme.info,  Node: Run Control,  Prev: Miscellaneous,  Up: Contexts

7.9 Run Control
===============

GPGME supports running operations synchronously and asynchronously.  You
can use asynchronous operation to set up a context up to initiating the
desired operation, but delay performing it to a later point.

   Furthermore, you can use an external event loop to control exactly
when GPGME runs.  This ensures that GPGME only runs when necessary and
also prevents it from blocking for a long time.

* Menu:

* Waiting For Completion::        Waiting until an operation is completed.
* Using External Event Loops::    Advanced control over what happens when.
* Cancellation::                  How to end pending operations prematurely.


File: gpgme.info,  Node: Waiting For Completion,  Next: Using External Event Loops,  Up: Run Control

7.9.1 Waiting For Completion
----------------------------

 -- Function: gpgme_ctx_t gpgme_wait (gpgme_ctx_t CTX,
          gpgme_error_t *STATUS, int HANG)
     The function ‘gpgme_wait’ continues the pending operation within
     the context CTX.  In particular, it ensures the data exchange
     between GPGME and the crypto backend and watches over the run time
     status of the backend process.

     If HANG is true, the function does not return until the operation
     is completed or cancelled.  Otherwise the function will not block
     for a long time.

     The error status of the finished operation is returned in STATUS if
     ‘gpgme_wait’ does not return ‘NULL’.

     The CTX argument can be ‘NULL’.  In that case, ‘gpgme_wait’ waits
     for any context to complete its operation.

     ‘gpgme_wait’ can be used only in conjunction with any context that
     has a pending operation initiated with one of the
     ‘gpgme_op_*_start’ functions except ‘gpgme_op_keylist_start’ and
     ‘gpgme_op_trustlist_start’ (for which you should use the
     corresponding ‘gpgme_op_*_next’ functions).  If CTX is ‘NULL’, all
     of such contexts are waited upon and possibly returned.
     Synchronous operations running in parallel, as well as key and
     trust item list operations, do not affect ‘gpgme_wait’.

     In a multi-threaded environment, only one thread should ever call
     ‘gpgme_wait’ at any time, irregardless if CTX is specified or not.
     This means that all calls to this function should be fully
     synchronized by locking primitives.  It is safe to start
     asynchronous operations while a thread is running in ‘gpgme_wait’.

     The function returns the CTX of the context which has finished the
     operation.  If HANG is false, and the timeout expires, ‘NULL’ is
     returned and ‘*status’ will be set to 0.  If an error occurs,
     ‘NULL’ is returned and the error is returned in ‘*status’.


File: gpgme.info,  Node: Using External Event Loops,  Next: Cancellation,  Prev: Waiting For Completion,  Up: Run Control

7.9.2 Using External Event Loops
--------------------------------

GPGME hides the complexity of the communication between the library and
the crypto engine.  The price of this convenience is that the calling
thread can block arbitrary long waiting for the data returned by the
crypto engine.  In single-threaded programs, in particular if they are
interactive, this is an unwanted side-effect.  OTOH, if ‘gpgme_wait’ is
used without the HANG option being enabled, it might be called
unnecessarily often, wasting CPU time that could be used otherwise.

   The I/O callback interface described in this section lets the user
take control over what happens when.  GPGME will provide the user with
the file descriptors that should be monitored, and the callback
functions that should be invoked when a file descriptor is ready for
reading or writing.  It is then the user’s responsibility to decide when
to check the file descriptors and when to invoke the callback functions.
Usually this is done in an event loop, that also checks for events in
other parts of the program.  If the callback functions are only called
when the file descriptors are ready, GPGME will never block.  This gives
the user more control over the program flow, and allows to perform other
tasks when GPGME would block otherwise.

   By using this advanced mechanism, GPGME can be integrated smoothly
into GUI toolkits like GTK+ even for single-threaded programs.

* Menu:

* I/O Callback Interface::        How I/O callbacks are registered.
* Registering I/O Callbacks::     How to use I/O callbacks for a context.
* I/O Callback Example::          An example how to use I/O callbacks.
* I/O Callback Example GTK+::     How to use GPGME with GTK+.
* I/O Callback Example GDK::      How to use GPGME with GDK.
* I/O Callback Example Qt::       How to use GPGME with Qt.


File: gpgme.info,  Node: I/O Callback Interface,  Next: Registering I/O Callbacks,  Up: Using External Event Loops

7.9.2.1 I/O Callback Interface
..............................

 -- Data type: gpgme_error_t (*gpgme_io_cb_t) (void *DATA, int FD)
     The ‘gpgme_io_cb_t’ type is the type of functions which GPGME wants
     to register as I/O callback handlers using the
     ‘gpgme_register_io_cb_t’ functions provided by the user.

     DATA and FD are provided by GPGME when the I/O callback handler is
     registered, and should be passed through to the handler when it is
     invoked by the user because it noticed activity on the file
     descriptor FD.

     The callback handler always returns ‘0’, but you should consider
     the return value to be reserved for later use.

 -- Data type: gpgme_error_t (*gpgme_register_io_cb_t) (void *DATA,
          int FD, int DIR, gpgme_io_cb_t FNC, void *FNC_DATA,
          void **TAG)
     The ‘gpgme_register_io_cb_t’ type is the type of functions which
     can be called by GPGME to register an I/O callback function FNC for
     the file descriptor FD with the user.  FNC_DATA should be passed as
     the first argument to FNC when the handler is invoked (the second
     argument should be FD).  If DIR is 0, FNC should be called by the
     user when FD is ready for writing.  If DIR is 1, FNC should be
     called when FD is ready for reading.

     DATA was provided by the user when registering the
     ‘gpgme_register_io_cb_t’ function with GPGME and will always be
     passed as the first argument when registering a callback function.
     For example, the user can use this to determine the event loop to
     which the file descriptor should be added.

     GPGME will call this function when a crypto operation is initiated
     in a context for which the user has registered I/O callback handler
     functions with ‘gpgme_set_io_cbs’.  It can also call this function
     when it is in an I/O callback handler for a file descriptor
     associated to this context.

     The user should return a unique handle in TAG identifying this I/O
     callback registration, which will be passed to the
     ‘gpgme_register_io_cb_t’ function without interpretation when the
     file descriptor should not be monitored anymore.

 -- Data type: void (*gpgme_remove_io_cb_t) (void *TAG)
     The ‘gpgme_remove_io_cb_t’ type is the type of functions which can
     be called by GPGME to remove an I/O callback handler that was
     registered before.  TAG is the handle that was returned by the
     ‘gpgme_register_io_cb_t’ for this I/O callback.

     GPGME can call this function when a crypto operation is in an I/O
     callback.  It will also call this function when the context is
     destroyed while an operation is pending.

 -- Data type: enum gpgme_event_io_t
     The ‘gpgme_event_io_t’ type specifies the type of an event that is
     reported to the user by GPGME as a consequence of an I/O operation.
     The following events are defined:

     ‘GPGME_EVENT_START’
          The operation is fully initialized now, and you can start to
          run the registered I/O callback handlers now.  Note that
          registered I/O callback handlers must not be run before this
          event is signalled.  TYPE_DATA is ‘NULL’ and reserved for
          later use.

     ‘GPGME_EVENT_DONE’
          The operation is finished, the last I/O callback for this
          operation was removed.  The accompanying TYPE_DATA points to a
          ‘struct gpgme_io_event_done_data’ variable that contains the
          status of the operation that finished.  This event is
          signalled after the last I/O callback has been removed.

     ‘GPGME_EVENT_NEXT_KEY’
          In a ‘gpgme_op_keylist_start’ operation, the next key was
          received from the crypto engine.  The accompanying TYPE_DATA
          is a ‘gpgme_key_t’ variable that contains the key with one
          reference for the user.

     ‘GPGME_EVENT_NEXT_TRUSTITEM’
          In a ‘gpgme_op_trustlist_start’ operation, the next trust item
          was received from the crypto engine.  The accompanying
          TYPE_DATA is a ‘gpgme_trust_item_t’ variable that contains the
          trust item with one reference for the user.

 -- Data type: void (*gpgme_event_io_cb_t) (void *DATA,
          gpgme_event_io_t TYPE, void *TYPE_DATA)
     The ‘gpgme_event_io_cb_t’ type is the type of functions which can
     be called by GPGME to signal an event for an operation running in a
     context which has I/O callback functions registered by the user.

     DATA was provided by the user when registering the
     ‘gpgme_event_io_cb_t’ function with GPGME and will always be passed
     as the first argument when registering a callback function.  For
     example, the user can use this to determine the context in which
     this event has occured.

     TYPE will specify the type of event that has occured.  TYPE_DATA
     specifies the event further, as described in the above list of
     possible ‘gpgme_event_io_t’ types.

     GPGME can call this function in an I/O callback handler.


File: gpgme.info,  Node: Registering I/O Callbacks,  Next: I/O Callback Example,  Prev: I/O Callback Interface,  Up: Using External Event Loops

7.9.2.2 Registering I/O Callbacks
.................................

 -- Data type: struct gpgme_io_cbs
     This structure is used to store the I/O callback interface
     functions described in the previous section.  It has the following
     members:

     ‘gpgme_register_io_cb_t add’
          This is the function called by GPGME to register an I/O
          callback handler.  It must be specified.

     ‘void *add_priv’
          This is passed as the first argument to the ‘add’ function
          when it is called by GPGME.  For example, it can be used to
          determine the event loop to which the file descriptor should
          be added.

     ‘gpgme_remove_io_cb_t remove’
          This is the function called by GPGME to remove an I/O callback
          handler.  It must be specified.

     ‘gpgme_event_io_cb_t event’
          This is the function called by GPGME to signal an event for an
          operation.  It must be specified, because at least the start
          event must be processed.

     ‘void *event_priv’
          This is passed as the first argument to the ‘event’ function
          when it is called by GPGME.  For example, it can be used to
          determine the context in which the event has occured.

 -- Function: void gpgme_set_io_cbs (gpgme_ctx_t CTX,
          struct gpgme_io_cbs *IO_CBS)
     The function ‘gpgme_set_io_cbs’ enables the I/O callback interface
     for the context CTX.  The I/O callback functions are specified by
     IO_CBS.

     If IO_CBS->‘add’ is ‘NULL’, the I/O callback interface is disabled
     for the context, and normal operation is restored.

 -- Function: void gpgme_get_io_cbs (gpgme_ctx_t CTX,
          struct gpgme_io_cbs *IO_CBS)
     The function ‘gpgme_get_io_cbs’ returns the I/O callback functions
     set with ‘gpgme_set_io_cbs’ in IO_CBS.


File: gpgme.info,  Node: I/O Callback Example,  Next: I/O Callback Example GTK+,  Prev: Registering I/O Callbacks,  Up: Using External Event Loops

7.9.2.3 I/O Callback Example
............................

To actually use an external event loop, you have to implement the I/O
callback functions that are used by GPGME to register and unregister
file descriptors.  Furthermore, you have to actually monitor these file
descriptors for activity and call the appropriate I/O callbacks.

   The following example illustrates how to do that.  The example uses
locking to show in which way the callbacks and the event loop can run
concurrently.  For the event loop, we use a fixed array.  For a
real-world implementation, you should use a dynamically sized structure
because the number of file descriptors needed for a crypto operation in
GPGME is not predictable.

     #include <assert.h>
     #include <errno.h>
     #include <stdlib.h>
     #include <pthread.h>
     #include <sys/types.h>
     #include <gpgme.h>

     /* The following structure holds the result of a crypto operation.  */
     struct op_result
     {
       int done;
       gpgme_error_t err;
     };

     /* The following structure holds the data associated with one I/O
     callback.  */
     struct one_fd
     {
       int fd;
       int dir;
       gpgme_io_cb_t fnc;
       void *fnc_data;
       void *loop;
     };

     struct event_loop
     {
       pthread_mutex_t lock;
     #define MAX_FDS 32
       /* Unused slots are marked with FD being -1.  */
       struct one_fd fds[MAX_FDS];
     };

   The following functions implement the I/O callback interface.

     gpgme_error_t
     add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc, void *fnc_data,
     	   void **r_tag)
     {
       struct event_loop *loop = data;
       struct one_fd *fds = loop->fds;
       int i;

       pthread_mutex_lock (&loop->lock);
       for (i = 0; i < MAX_FDS; i++)
         {
           if (fds[i].fd == -1)
	     {
     	  fds[i].fd = fd;
     	  fds[i].dir = dir;
     	  fds[i].fnc = fnc;
     	  fds[i].fnc_data = fnc_data;
     	  fds[i].loop = loop;
     	  break;
	     }
         }
       pthread_mutex_unlock (&loop->lock);
       if (i == MAX_FDS)
         return gpg_error (GPG_ERR_GENERAL);
       *r_tag = &fds[i];
       return 0;
     }

     void
     remove_io_cb (void *tag)
     {
       struct one_fd *fd = tag;
       struct event_loop *loop = fd->loop;

       pthread_mutex_lock (&loop->lock);
       fd->fd = -1;
       pthread_mutex_unlock (&loop->lock);
     }

     void
     event_io_cb (void *data, gpgme_event_io_t type, void *type_data)
     {
       struct op_result *result = data;

       /* We don't support list operations here.  */
       if (type == GPGME_EVENT_DONE)
         {
           result->done = 1;
           result->err = *type_data;
         }
     }

   The final missing piece is the event loop, which will be presented
next.  We only support waiting for the success of a single operation.

     int
     do_select (struct event_loop *loop)
     {
       fd_set rfds;
       fd_set wfds;
       int i, n;
       int any = 0;
       struct timeval tv;
       struct one_fd *fdlist = loop->fds;

       pthread_mutex_lock (&loop->lock);
       FD_ZERO (&rfds);
       FD_ZERO (&wfds);
       for (i = 0; i < MAX_FDS; i++)
         if (fdlist[i].fd != -1)
           FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds);
       pthread_mutex_unlock (&loop->lock);

       tv.tv_sec = 0;
       tv.tv_usec = 1000;

       do
         {
           n = select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
         }
       while (n < 0 && errno == EINTR);

       if (n < 0)
         return n;	/* Error or timeout.  */

       pthread_mutex_lock (&loop->lock);
       for (i = 0; i < MAX_FDS && n; i++)
         {
           if (fdlist[i].fd != -1)
	     {
     	  if (FD_ISSET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds))
	         {
     	      assert (n);
     	      n--;
     	      any = 1;
                   /* The I/O callback handler can register/remove callbacks,
                      so we have to unlock the file descriptor list.  */
                   pthread_mutex_unlock (&loop->lock);
     	      (*fdlist[i].fnc) (fdlist[i].fnc_data, fdlist[i].fd);
                   pthread_mutex_lock (&loop->lock);
	         }
	     }
         }
       pthread_mutex_unlock (&loop->lock);
       return any;
     }

     void
     wait_for_op (struct event_loop *loop, struct op_result *result)
     {
       int ret;

       do
         {
           ret = do_select (loop);
         }
       while (ret >= 0 && !result->done);
     }

   The main function shows how to put it all together.

     int
     main (int argc, char *argv[])
     {
       struct event_loop loop;
       struct op_result result;
       gpgme_ctx_t ctx;
       gpgme_error_t err;
       gpgme_data_t sig, text;
       int i;
       pthread_mutexattr_t attr;
       struct gpgme_io_cbs io_cbs =
       {
         add_io_cb,
         &loop,
         remove_io_cb,
         event_io_cb,
         &result
       };

       init_gpgme ();

       /* Initialize the loop structure.  */

       /* The mutex must be recursive, since remove_io_cb (which acquires a
          lock) can be called while holding a lock acquired in do_select.  */
       pthread_mutexattr_init (&attr);
       pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
       pthread_mutex_init (&loop.lock, &attr);
       pthread_mutexattr_destroy (&attr);

       for (i = 0; i < MAX_FDS; i++)
         loop.fds[i].fd = -1;

       /* Initialize the result structure.  */
       result.done = 0;

       err = gpgme_data_new_from_file (&sig, "signature", 1);
       if (!err)
         err = gpgme_data_new_from_file (&text, "text", 1);
       if (!err)
         err = gpgme_new (&ctx);
       if (!err)
         {
            gpgme_set_io_cbs (ctx, &io_cbs);
            err = gpgme_op_verify_start (ctx, sig, text, NULL);
         }
       if (err)
         {
           fprintf (stderr, "gpgme error: %s: %s\n",
                    gpgme_strsource (err), gpgme_strerror (err));
           exit (1);
         }

       wait_for_op (&loop, &result);
       if (!result.done)
         {
           fprintf (stderr, "select error\n");
           exit (1);
         }
       if (!result.err)
         {
           fprintf (stderr, "verification failed: %s: %s\n",
                    gpgme_strsource (result.err), gpgme_strerror (result.err));
           exit (1);
         }
       /* Evaluate verify result.  */
       …
       return 0;
     }


File: gpgme.info,  Node: I/O Callback Example GTK+,  Next: I/O Callback Example GDK,  Prev: I/O Callback Example,  Up: Using External Event Loops

7.9.2.4 I/O Callback Example GTK+
.................................

The I/O callback interface can be used to integrate GPGME with the GTK+
event loop.  The following code snippets shows how this can be done
using the appropriate register and remove I/O callback functions.  In
this example, the private data of the register I/O callback function is
unused.  The event notifications is missing because it does not require
any GTK+ specific setup.

     #include <gtk/gtk.h>

     struct my_gpgme_io_cb
     {
       gpgme_io_cb_t fnc;
       void *fnc_data;
       guint input_handler_id
     };

     void
     my_gpgme_io_cb (gpointer data, gint source, GdkInputCondition condition)
     {
       struct my_gpgme_io_cb *iocb = data;
       (*(iocb->fnc)) (iocb->data, source);
     }

     void
     my_gpgme_remove_io_cb (void *data)
     {
       struct my_gpgme_io_cb *iocb = data;
       gtk_input_remove (data->input_handler_id);
     }

     void
     my_gpgme_register_io_callback (void *data, int fd, int dir, gpgme_io_cb_t fnc,
                                    void *fnc_data, void **tag)
     {
       struct my_gpgme_io_cb *iocb = g_malloc (sizeof (struct my_gpgme_io_cb));
       iocb->fnc = fnc;
       iocb->data = fnc_data;
       iocb->input_handler_id = gtk_input_add_full (fd, dir
                                                        ? GDK_INPUT_READ
                                                        : GDK_INPUT_WRITE,
                                                    my_gpgme_io_callback,
                                                    0, iocb, NULL);
       *tag = iocb;
       return 0;
     }


File: gpgme.info,  Node: I/O Callback Example GDK,  Next: I/O Callback Example Qt,  Prev: I/O Callback Example GTK+,  Up: Using External Event Loops

7.9.2.5 I/O Callback Example GDK
................................

The I/O callback interface can also be used to integrate GPGME with the
GDK event loop.  The following code snippets shows how this can be done
using the appropriate register and remove I/O callback functions.  In
this example, the private data of the register I/O callback function is
unused.  The event notifications is missing because it does not require
any GDK specific setup.

   It is very similar to the GTK+ example in the previous section.

     #include <gdk/gdk.h>

     struct my_gpgme_io_cb
     {
       gpgme_io_cb_t fnc;
       void *fnc_data;
       gint tag;
     };

     void
     my_gpgme_io_cb (gpointer data, gint source, GdkInputCondition condition)
     {
       struct my_gpgme_io_cb *iocb = data;
       (*(iocb->fnc)) (iocb->data, source);
     }

     void
     my_gpgme_remove_io_cb (void *data)
     {
       struct my_gpgme_io_cb *iocb = data;
       gdk_input_remove (data->tag);
     }

     void
     my_gpgme_register_io_callback (void *data, int fd, int dir, gpgme_io_cb_t fnc,
                                    void *fnc_data, void **tag)
     {
       struct my_gpgme_io_cb *iocb = g_malloc (sizeof (struct my_gpgme_io_cb));
       iocb->fnc = fnc;
       iocb->data = fnc_data;
       iocb->tag = gtk_input_add_full (fd, dir ? GDK_INPUT_READ : GDK_INPUT_WRITE,
                                       my_gpgme_io_callback, iocb, NULL);
       *tag = iocb;
       return 0;
     }


File: gpgme.info,  Node: I/O Callback Example Qt,  Prev: I/O Callback Example GDK,  Up: Using External Event Loops

7.9.2.6 I/O Callback Example Qt
...............................

The I/O callback interface can also be used to integrate GPGME with the
Qt event loop.  The following code snippets show how this can be done
using the appropriate register and remove I/O callback functions.  In
this example, the private data of the register I/O callback function is
unused.  The event notifications is missing because it does not require
any Qt specific setup.

     #include <qsocketnotifier.h>
     #include <qapplication.h>

     struct IOCB {
       IOCB( GpgmeIOCb f, void * d, QSocketNotifier * n )
         : func( f ), data( d ), notifier( n ) {}
       GpgmeIOCb func;
       void * data;
       QSocketNotifier * notifier;
     }

     class MyApp : public QApplication {

       // ...

       static void registerGpgmeIOCallback( void * data, int fd, int dir,
                                            GpgmeIOCb func, void * func_data,
                                            void ** tag ) {
         QSocketNotifier * n =
           new QSocketNotifier( fd, dir ? QSocketNotifier::Read
                                        : QSocketNotifier::Write );
         connect( n, SIGNAL(activated(int)),
                  qApp, SLOT(slotGpgmeIOCallback(int)) );
         qApp->mIOCBs.push_back( IOCB( func, func_data, n ) );
         *tag = (void*)n;
       }

       static void removeGpgmeIOCallback( void * tag ) {
         if ( !tag ) return;
         QSocketNotifier * n = static_cast<QSocketNotifier*>( tag );
         for ( QValueList<IOCB>::iterator it = qApp->mIOCBs.begin() ;
               it != qApp->mIOCBs.end() ; ++it )
           if ( it->notifier == n ) {
             delete it->notifier;
             qApp->mIOCBs.erase( it );
             return;
           }
       }

     public slots:
       void slotGpgmeIOCallback( int fd ) {
         for ( QValueList<IOCB>::const_iterator it = mIOCBs.begin() ;
               it != mIOCBs.end() ; ++it )
           if ( it->notifier && it->notifier->socket() == fd )
             (*(it->func)) ( it->func_data, fd );
       }

       // ...

     private:
       QValueList<IOCB> mIOCBs;
       // ...
     };


File: gpgme.info,  Node: Cancellation,  Prev: Using External Event Loops,  Up: Run Control

7.9.3 Cancellation
------------------

Sometimes you do not want to wait for an operation to finish.  GPGME
provides two different functions to achieve that.  The function
‘gpgme_cancel’ takes effect immediately.  When it returns, the operation
is effectively canceled.  However, it has some limitations and can not
be used with synchronous operations.  In contrast, the function
‘gpgme_cancel_async’ can be used with any context and from any thread,
but it is not guaranteed to take effect immediately.  Instead,
cancellation occurs at the next possible time (typically the next time
I/O occurs in the target context).

 -- Function: gpgme_ctx_t gpgme_cancel (gpgme_ctx_t CTX)
     The function ‘gpgme_cancel’ attempts to cancel a pending operation
     in the context CTX.  This only works if you use the global event
     loop or your own event loop.

     If you use the global event loop, you must not call ‘gpgme_wait’
     during cancellation.  After successful cancellation, you can call
     ‘gpgme_wait’ (optionally waiting on CTX), and the context CTX will
     appear as if it had finished with the error code ‘GPG_ERR_CANCEL’.

     If you use an external event loop, you must ensure that no I/O
     callbacks are invoked for this context (for example by halting the
     event loop).  On successful cancellation, all registered I/O
     callbacks for this context will be unregistered, and a
     ‘GPGME_EVENT_DONE’ event with the error code ‘GPG_ERR_CANCEL’ will
     be signalled.

     The function returns an error code if the cancellation failed (in
     this case the state of CTX is not modified).

 -- Function: gpgme_ctx_t gpgme_cancel_async (gpgme_ctx_t CTX)
     The function ‘gpgme_cancel_async’ attempts to cancel a pending
     operation in the context CTX.  This can be called by any thread at
     any time after starting an operation on the context, but will not
     take effect immediately.  The actual cancellation happens at the
     next time GPGME processes I/O in that context.

     The function returns an error code if the cancellation failed (in
     this case the state of CTX is not modified).


File: gpgme.info,  Node: UI Server Protocol,  Next: Debugging,  Prev: Contexts,  Up: Top

Appendix A The GnuPG UI Server Protocol
***************************************

This section specifies the protocol used between clients and a User
Interface Server (UI server).  This protocol helps to build a system
where all cryptographic operations are done by a server and the server
is responsible for all dialogs.  Although GPGME has no direct support
for this protocol it is believed that servers will utilize the GPGME
library; thus having the specification included in this manual is an
appropriate choice.  This protocol should be referenced as ‘The GnuPG UI
Server Protocol’.

A server needs to implement these commands:(1)

* Menu:

* UI Server Encrypt::                Encrypt a message.
* UI Server Sign::                   Sign a message.
* UI Server Decrypt::                Decrypt a message.
* UI Server Verify::                 Verify a message.
* UI Server Set Input Files::        Specifying the input files to operate on.
* UI Server Sign/Encrypt Files::     Encrypting and signing files.
* UI Server Verify/Decrypt Files::   Decrypting and verifying files.
* UI Server Import/Export Keys::     Managing certificates.
* UI Server Checksum Files::         Create and verify checksums for files.
* Miscellaneous UI Server Commands::   Commands not related to a specific operation.

   ---------- Footnotes ----------

   (1) In all examples we assume that the connection has already been
established; see the Assuan manual for details.


File: gpgme.info,  Node: UI Server Encrypt,  Next: UI Server Sign,  Up: UI Server Protocol

A.1 UI Server: Encrypt a Message
================================

Before encryption can be done the recipients must be set using the
command:

 -- Command: RECIPIENT STRING

     Set the recipient for the encryption.  STRING is an RFC-2822
     recipient name ("mailbox" as per section 3.4).  This command may or
     may not check the recipient for validity right away; if it does not
     all recipients are expected to be checked at the time of the
     ‘ENCRYPT’ command.  All ‘RECIPIENT’ commands are cumulative until a
     successful ‘ENCRYPT’ command or until a ‘RESET’ command.  Linefeeds
     are obviously not allowed in STRING and should be folded into
     spaces (which are equivalent).

To tell the server the source and destination of the data, the next two
commands are to be used:

 -- Command: INPUT FD=N
     Set the file descriptor for the message to be encrypted to N.  The
     message send to the server is binary encoded.

     GpgOL is a Windows only program, thus N is not a libc file
     descriptor but a regular system handle.  Given that the Assuan
     connection works over a socket, it is not possible to use regular
     inheritance to make the file descriptor available to the server.
     Thus ‘DuplicateHandle’ needs to be used to duplicate a handle to
     the server process.  This is the reason that the server needs to
     implement the ‘GETINFO pid’ command.  Sending this command a second
     time replaces the file descriptor set by the last one.

 -- Command: OUTPUT FD=N [--binary]
     Set the file descriptor to be used for the output (i.e.  the
     encrypted message) to N.  If the option ‘--binary’ is given the
     output shall be in binary format; if not given, the output for
     OpenPGP needs to be ASCII armored and for CMS Base-64 encoded.  For
     details on the file descriptor, see the ‘INPUT’ command.

The setting of the recipients, the data source and destination may
happen in any order, even intermixed.  If this has been done the actual
encryption operation is called using:

 -- Command: ENCRYPT --protocol=NAME

     This command reads the plaintext from the file descriptor set by
     the ‘INPUT’ command, encrypts it and writes the ciphertext to the
     file descriptor set by the ‘OUTPUT’ command.  The server may (and
     should) overlap reading and writing.  The recipients used for the
     encryption are all the recipients set so far.  If any recipient is
     not usable the server should take appropriate measures to notify
     the user about the problem and may cancel the operation by
     returning an error code.  The used file descriptors are void after
     this command; the recipient list is only cleared if the server
     returns success.

     Because GpgOL uses a streaming mode of operation the server is not
     allowed to auto select the protocol and must obey to the mandatory
     PROTOCOL parameter:

     ‘OpenPGP’
          Use the OpenPGP protocol (RFC-2440).
     ‘CMS’
          Use the CMS (PKCS#7) protocol (RFC-3852).

   To support automagically selection of the protocol depending on the
selected keys, the server MAY implement the command:

 -- Command: PREP_ENCRYPT [--protocol=NAME] [--expect-sign]

     This commands considers all recipients set so far and decides
     whether it is able to take input and start the actual encryption.
     This is kind of a dry-run ‘ENCRYPT’ without requiring or using the
     input and output file descriptors.  The server shall cache the
     result of any user selection to avoid asking this again when the
     actual ‘ENCRYPT’ command is send.  The ‘--protocol’ option is
     optional; if it is not given, the server should allow the user to
     select the protocol to be used based on the recipients given or by
     any other means.

     If ‘--expect-sign’ is given the server should expect that the
     message will also be signed and use this hint to present a unified
     recipient and signer selection dialog if possible and desired.  A
     selected signer should then be cached for the expected SIGN command
     (which is expected in the same session but possible on another
     connection).

     If this command is given again before a successful ‘ENCRYPT’
     command, the second one takes effect.

     Before sending the OK response the server shall tell the client the
     protocol to be used (either the one given by the argument or the
     one selected by the user) by means of a status line:

 -- Status line: PROTOCOL NAME
     Advise the client to use the protocol NAME for the ‘ENCRYPT’
     command.  The valid protocol names are listed under the description
     of the ‘ENCRYPT’ command.  The server shall emit exactly one
     PROTOCOL status line.

Here is an example of a complete encryption sequence; client lines are
indicated by a C:, server responses by C::

         C: RESET
         S: OK
         C: RECIPIENT foo@example.net
         S: OK
         C: RECIPIENT bar@example.com
         S: OK
         C: PREP_ENCRYPT
         S: S PROTOCOL OpenPGP
         S: OK
         C: INPUT FD=17
         S: OK
         C: OUTPUT FD=18
         S: OK
         C: ENCRYPT
         S: OK


File: gpgme.info,  Node: UI Server Sign,  Next: UI Server Decrypt,  Prev: UI Server Encrypt,  Up: UI Server Protocol

A.2 UI Server: Sign a Message
=============================

The server needs to implement opaque signing as well as detached
signing.  Due to the nature of OpenPGP messages it is always required to
send the entire message to the server; sending just the hash is not
possible.  The following two commands are required to set the input and
output file descriptors:

 -- Command: INPUT FD=N
     Set the file descriptor for the message to be signed to N.  The
     message send to the server is binary encoded.  For details on the
     file descriptor, see the description of ‘INPUT’ in the ‘ENCRYPT’
     section.

 -- Command: OUTPUT FD=N [--binary]
     Set the file descriptor to be used for the output.  The output is
     either the complete signed message or in case of a detached
     signature just that detached signature.  If the option ‘--binary’
     is given the output shall be in binary format; if not given, the
     output for OpenPGP needs to be ASCII armored and for CMS Base-64
     encoded.  For details on the file descriptor, see the ‘INPUT’
     command.

To allow the server the selection of a non-default signing key the
client may optionally use the ‘SENDER’ command, see *note command
SENDER::.

The signing operation is then initiated by:

 -- Command: SIGN --protocol=NAME [--detached]
     Sign the data set with the ‘INPUT’ command and write it to the sink
     set by OUTPUT. NAME is the signing protocol used for the message.
     For a description of the allowed protocols see the ‘ENCRYPT’
     command.  With option ‘--detached’ given, a detached signature is
     created; this is actually the usual way the command is used.

The client expects the server to send at least this status information
before the final OK response:

 -- Status line: MICALG STRING
     The STRING represents the hash algorithm used to create the
     signature.  It is used with RFC-1847 style signature messages and
     defined by PGP/MIME (RFC-3156) and S/MIME (RFC-3851).  The GPGME
     library has a supporting function ‘gpgme_hash_algo_name’ to return
     the algorithm name as a string.  This string needs to be lowercased
     and for OpenPGP prefixed with "‘pgp-’".


File: gpgme.info,  Node: UI Server Decrypt,  Next: UI Server Verify,  Prev: UI Server Sign,  Up: UI Server Protocol

A.3 UI Server: Decrypt a Message
================================

Decryption may include the verification of OpenPGP messages.  This is
due to the often used combined signing/encryption modus of OpenPGP. The
client may pass an option to the server to inhibit the signature
verification.  The following two commands are required to set the input
and output file descriptors:

 -- Command: INPUT FD=N
     Set the file descriptor for the message to be decrypted to N.  The
     message send to the server is either binary encoded or — in the
     case of OpenPGP — ASCII armored.  For details on the file
     descriptor, see the description of ‘INPUT’ in the ‘ENCRYPT’
     section.

 -- Command: OUTPUT FD=N
     Set the file descriptor to be used for the output.  The output is
     binary encoded.  For details on the file descriptor, see the
     description of ‘INPUT’ in the ‘ENCRYPT’ section.

The decryption is started with the command:

 -- Command: DECRYPT --protocol=NAME [--no-verify]
          [--export-session-key]
     NAME is the encryption protocol used for the message.  For a
     description of the allowed protocols see the ‘ENCRYPT’ command.
     This argument is mandatory.  If the option ‘--no-verify’ is given,
     the server should not try to verify a signature, in case the input
     data is an OpenPGP combined message.  If the option
     ‘--export-session-key’ is given and the underlying engine knows how
     to export the session key, it will appear on a status line


File: gpgme.info,  Node: UI Server Verify,  Next: UI Server Set Input Files,  Prev: UI Server Decrypt,  Up: UI Server Protocol

A.4 UI Server: Verify a Message
===============================

The server needs to support the verification of opaque signatures as
well as detached signatures.  The kind of input sources controls what
kind message is to be verified.

 -- Command: MESSAGE FD=N
     This command is used with detached signatures to set the file
     descriptor for the signed data to N.  The data is binary encoded
     (used verbatim).  For details on the file descriptor, see the
     description of ‘INPUT’ in the ‘ENCRYPT’ section.

 -- Command: INPUT FD=N
     Set the file descriptor for the opaque message or the signature
     part of a detached signature to N.  The message send to the server
     is either binary encoded or – in the case of OpenPGP – ASCII
     armored.  For details on the file descriptor, see the description
     of ‘INPUT’ in the ‘ENCRYPT’ section.

 -- Command: OUTPUT FD=N
     Set the file descriptor to be used for the output.  The output is
     binary encoded and only used for opaque signatures.  For details on
     the file descriptor, see the description of ‘INPUT’ in the
     ‘ENCRYPT’ section.

The verification is then started using:

 -- Command: VERIFY --protocol=NAME [--silent]
     NAME is the signing protocol used for the message.  For a
     description of the allowed protocols see the ‘ENCRYPT’ command.
     This argument is mandatory.  Depending on the combination of
     ‘MESSAGE’ ‘INPUT’ and ‘OUTPUT’ commands, the server needs to select
     the appropriate verification mode:

     MESSAGE and INPUT
          This indicates a detached signature.  Output data is not
          applicable.
     INPUT
          This indicates an opaque signature.  As no output command has
          been given, the server is only required to check the
          signature.
     INPUT and OUTPUT
          This indicates an opaque signature.  The server shall write
          the signed data to the file descriptor set by the output
          command.  This data shall even be written if the signatures
          can’t be verified.

   With ‘--silent’ the server shall not display any dialog; this is for
example used by the client to get the content of opaque signed messages.
The client expects the server to send at least this status information
before the final OK response:

 -- Status line: SIGSTATUS FLAG DISPLAYSTRING
     Returns the status for the signature and a short string explaining
     the status.  Valid values for FLAG are:

     ‘none’
          The message has a signature but it could not not be verified
          due to a missing key.
     ‘green’
          The signature is fully valid.
     ‘yellow’
          The signature is valid but additional information was shown
          regarding the validity of the key.
     ‘red’
          The signature is not valid.

     DISPLAYSTRING is a percent-and-plus-encoded string with a short
     human readable description of the status.  For example

          S SIGSTATUS green Good+signature+from+Keith+Moon+<keith@example.net>

     Note that this string needs to fit into an Assuan line and should
     be short enough to be displayed as short one-liner on the clients
     window.  As usual the encoding of this string is UTF-8 and it
     should be send in its translated form.

     The server shall send one status line for every signature found on
     the message.


File: gpgme.info,  Node: UI Server Set Input Files,  Next: UI Server Sign/Encrypt Files,  Prev: UI Server Verify,  Up: UI Server Protocol

A.5 UI Server: Specifying the input files to operate on.
========================================================

All file related UI server commands operate on a number of input files
or directories, specified by one or more ‘FILE’ commands:

 -- Command: FILE [--clear] NAME
     Add the file or directory NAME to the list of pathnames to be
     processed by the server.  The parameter NAME must be an absolute
     path name (including the drive letter) and is percent espaced (in
     particular, the characters %, = and white space characters are
     always escaped).  If the option ‘--clear’ is given, the list of
     files is cleared before adding NAME.

     Historical note: The original spec did not define ‘--clear’ but the
     keyword ‘--continued’ after the file name to indicate that more
     files are to be expected.  However, this has never been used and
     thus removed from the specs.


File: gpgme.info,  Node: UI Server Sign/Encrypt Files,  Next: UI Server Verify/Decrypt Files,  Prev: UI Server Set Input Files,  Up: UI Server Protocol

A.6 UI Server: Encrypting and signing files.
============================================

First, the input files need to be specified by one or more ‘FILE’
commands.  Afterwards, the actual operation is requested:

 -- Command: ENCRYPT_FILES --nohup
 -- Command: SIGN_FILES --nohup
 -- Command: ENCRYPT_SIGN_FILES --nohup
     Request that the files specified by ‘FILE’ are encrypted and/or
     signed.  The command selects the default action.  The UI server may
     allow the user to change this default afterwards interactively, and
     even abort the operation or complete it only on some of the
     selected files and directories.

     What it means to encrypt or sign a file or directory is specific to
     the preferences of the user, the functionality the UI server
     provides, and the selected protocol.  Typically, for each input
     file a new file is created under the original filename plus a
     protocol specific extension (like ‘.gpg’ or ‘.sig’), which contain
     the encrypted/signed file or a detached signature.  For
     directories, the server may offer multiple options to the user (for
     example ignore or process recursively).

     The ‘ENCRYPT_SIGN_FILES’ command requests a combined sign and
     encrypt operation.  It may not be available for all protocols (for
     example, it is available for OpenPGP but not for CMS).

     The option ‘--nohup’ is mandatory.  It is currently unspecified
     what should happen if ‘--nohup’ is not present.  Because ‘--nohup’
     is present, the server always returns ‘OK’ promptly, and completes
     the operation asynchronously.


File: gpgme.info,  Node: UI Server Verify/Decrypt Files,  Next: UI Server Import/Export Keys,  Prev: UI Server Sign/Encrypt Files,  Up: UI Server Protocol

A.7 UI Server: Decrypting and verifying files.
==============================================

First, the input files need to be specified by one or more ‘FILE’
commands.  Afterwards, the actual operation is requested:

 -- Command: DECRYPT_FILES --nohup
 -- Command: VERIFY_FILES --nohup
 -- Command: DECRYPT_VERIFY_FILES --nohup
     Request that the files specified by ‘FILE’ are decrypted and/or
     verified.  The command selects the default action.  The UI server
     may allow the user to change this default afterwards interactively,
     and even abort the operation or complete it only on some of the
     selected files and directories.

     What it means to decrypt or verify a file or directory is specific
     to the preferences of the user, the functionality the UI server
     provides, and the selected protocol.  Typically, for decryption, a
     new file is created for each input file under the original filename
     minus a protocol specific extension (like ‘.gpg’) which contains
     the original plaintext.  For verification a status is displayed for
     each signed input file, indicating if it is signed, and if yes, if
     the signature is valid.  For files that are signed and encrypted,
     the ‘VERIFY’ command transiently decrypts the file to verify the
     enclosed signature.  For directories, the server may offer multiple
     options to the user (for example ignore or process recursively).

     The option ‘--nohup’ is mandatory.  It is currently unspecified
     what should happen if ‘--nohup’ is not present.  Because ‘--nohup’
     is present, the server always returns ‘OK’ promptly, and completes
     the operation asynchronously.


File: gpgme.info,  Node: UI Server Import/Export Keys,  Next: UI Server Checksum Files,  Prev: UI Server Verify/Decrypt Files,  Up: UI Server Protocol

A.8 UI Server: Managing certificates.
=====================================

First, the input files need to be specified by one or more ‘FILE’
commands.  Afterwards, the actual operation is requested:

 -- Command: IMPORT_FILES --nohup
     Request that the certificates contained in the files specified by
     ‘FILE’ are imported into the local certificate databases.

     For directories, the server may offer multiple options to the user
     (for example ignore or process recursively).

     The option ‘--nohup’ is mandatory.  It is currently unspecified
     what should happen if ‘--nohup’ is not present.  Because ‘--nohup’
     is present, the server always returns ‘OK’ promptly, and completes
     the operation asynchronously.

   FIXME: It may be nice to support an ‘EXPORT’ command as well, which
is enabled by the context menu of the background of a directory.


File: gpgme.info,  Node: UI Server Checksum Files,  Next: Miscellaneous UI Server Commands,  Prev: UI Server Import/Export Keys,  Up: UI Server Protocol

A.9 UI Server: Create and verify checksums for files.
=====================================================

First, the input files need to be specified by one or more ‘FILE’
commands.  Afterwards, the actual operation is requested:

 -- Command: CHECKSUM_CREATE_FILES --nohup
     Request that checksums are created for the files specifed by
     ‘FILE’.  The choice of checksum algorithm and the destination
     storage and format for the created checksums depend on the
     preferences of the user and the functionality provided by the UI
     server.  For directories, the server may offer multiple options to
     the user (for example ignore or process recursively).

     The option ‘--nohup’ is mandatory.  It is currently unspecified
     what should happen if ‘--nohup’ is not present.  Because ‘--nohup’
     is present, the server always returns ‘OK’ promptly, and completes
     the operation asynchronously.

 -- Command: CHECKSUM_VERIFY_FILES --nohup
     Request that checksums are created for the files specifed by ‘FILE’
     and verified against previously created and stored checksums.  The
     choice of checksum algorithm and the source storage and format for
     previously created checksums depend on the preferences of the user
     and the functionality provided by the UI server.  For directories,
     the server may offer multiple options to the user (for example
     ignore or process recursively).

     If the source storage of previously created checksums is available
     to the user through the Windows shell, this command may also accept
     such checksum files as ‘FILE’ arguments.  In this case, the UI
     server should instead verify the checksum of the referenced files
     as if they were given as INPUT files.

     The option ‘--nohup’ is mandatory.  It is currently unspecified
     what should happen if ‘--nohup’ is not present.  Because ‘--nohup’
     is present, the server always returns ‘OK’ promptly, and completes
     the operation asynchronously.


File: gpgme.info,  Node: Miscellaneous UI Server Commands,  Prev: UI Server Checksum Files,  Up: UI Server Protocol

A.10 Miscellaneous UI Server Commands
=====================================

The server needs to implement the following commands which are not
related to a specific command:

 -- Command: GETINFO WHAT
     This is a multi purpose command, commonly used to return a variety
     of information.  The required subcommands as described by the WHAT
     parameter are:

     ‘pid’
          Return the process id of the server in decimal notation using
          an Assuan data line.

To allow the server to pop up the windows in the correct relation to the
client, the client is advised to tell the server by sending the option:

 -- Command option: window-id NUMBER
     The NUMBER represents the native window ID of the clients current
     window.  On Windows systems this is a windows handle (‘HWND’) and
     on X11 systems it is the ‘X Window ID’.  The number needs to be
     given as a hexadecimal value so that it is easier to convey pointer
     values (e.g.  ‘HWND’).

A client may want to fire up the certificate manager of the server.  To
do this it uses the Assuan command:

 -- Command: START_KEYMANAGER
     The server shall pop up the main window of the key manager (aka
     certificate manager).  The client expects that the key manager is
     brought into the foregound and that this command immediatley
     returns (does not wait until the key manager has been fully brought
     up).

A client may want to fire up the configuration dialog of the server.  To
do this it uses the Assuan command:

 -- Command: START_CONFDIALOG
     The server shall pop up its configuration dialog.  The client
     expects that this dialog is brought into the foregound and that
     this command immediatley returns (i.e.  it does not wait until the
     dialog has been fully brought up).

When doing an operation on a mail, it is useful to let the server know
the address of the sender:

 -- Command: SENDER [--info] [--protocol=NAME] EMAIL
     EMAIL is the plain ASCII encoded address ("addr-spec" as per
     RFC-2822) enclosed in angle brackets.  The address set with this
     command is valid until a successful completion of the operation or
     until a ‘RESET’ command.  A second command overrides the effect of
     the first one; if EMAIL is not given and ‘--info’ is not used, the
     server shall use the default signing key.

     If option ‘--info’ is not given, the server shall also suggest a
     protocol to use for signing.  The client may use this suggested
     protocol on its own discretion.  The same status line as with
     PREP_ENCRYPT is used for this.

     The option ‘--protocol’ may be used to give the server a hint on
     which signing protocol should be preferred.

To allow the UI-server to visually identify a running operation or to
associate operations the server MAY support the command:

 -- Command: SESSION NUMBER [STRING]
     The NUMBER is an arbitrary value, a server may use to associate
     simultaneous running sessions.  It is a 32 bit unsigned integer
     with ‘0’ as a special value indicating that no session association
     shall be done.

     If STRING is given, the server may use this as the title of a
     window or, in the case of an email operation, to extract the
     sender’s address.  The string may contain spaces; thus no
     plus-escaping is used.

     This command may be used at any time and overrides the effect of
     the last command.  A ‘RESET’ undoes the effect of this command.


File: gpgme.info,  Node: Debugging,  Next: Deprecated Functions,  Prev: UI Server Protocol,  Up: Top

Appendix B How to solve problems
********************************

Everyone knows that software often does not do what it should do and
thus there is a need to track down problems.  This is in particular true
for applications using a complex library like GPGME and of course also
for the library itself.  Here we give a few hints on how to solve such
problems.

   First of all you should make sure that the keys you want to use are
installed in the GnuPG engine and are usable.  Thus the first test is to
run the desired operation using ‘gpg’ or ‘gpgsm’ on the command line.
If you can’t figure out why things don’t work, you may use GPGME’s built
in trace feature.  This feature is either enabled using the environment
variable ‘GPGME_DEBUG’ or, if this is not possible, by calling the
function ‘gpgme_set_global_flag’.  The value is the trace level and an
optional file name.  If no file name is given the trace output is
printed to ‘stderr’.

For example
     GPGME_DEBUG=9:/home/user/mygpgme.log
(Note that under Windows you use a semicolon in place of the colon to
separate the fields.)

   A trace level of 9 is pretty verbose and thus you may want to start
off with a lower level.  The exact definition of the trace levels and
the output format may change with any release; you need to check the
source code for details.  In any case the trace log should be helpful to
understand what is going going on.  Warning: The trace log may reveal
sensitive details like passphrases or other data you use in your
application.  If you are asked to send a log file, make sure that you
run your tests only with play data.


File: gpgme.info,  Node: Deprecated Functions,  Next: Library Copying,  Prev: Debugging,  Up: Top

Appendix C Deprecated Functions
*******************************

For backward compatibility GPGME has a number of functions, data types
and constants which are deprecated and should not be used anymore.  We
document here those which are really old to help understanding old code
and to allow migration to their modern counterparts.

   *Warning:* These interfaces will be removed in a future version of
GPGME.

 -- Function: void gpgme_key_release (gpgme_key_t KEY)
     The function ‘gpgme_key_release’ is equivalent to
     ‘gpgme_key_unref’.

 -- Function: void gpgme_trust_item_release (gpgme_trust_item_t ITEM)
     The function ‘gpgme_trust_item_release’ is an alias for
     ‘gpgme_trust_item_unref’.

 -- Function: gpgme_error_t gpgme_op_import_ext (gpgme_ctx_t CTX,
          gpgme_data_t KEYDATA, int *NR)
     The function ‘gpgme_op_import_ext’ is equivalent to:

            gpgme_error_t err = gpgme_op_import (ctx, keydata);
            if (!err)
              {
                gpgme_import_result_t result = gpgme_op_import_result (ctx);
                *nr = result->considered;
              }

 -- Data type: gpgme_error_t (*gpgme_edit_cb_t) (void *HANDLE,
          gpgme_status_code_t STATUS, const char *ARGS, int FD)
     The ‘gpgme_edit_cb_t’ type is the type of functions which GPGME
     calls if it a key edit operation is on-going.  The status code
     STATUS and the argument line ARGS are passed through by GPGME from
     the crypto engine.  The file descriptor FD is -1 for normal status
     messages.  If STATUS indicates a command rather than a status
     message, the response to the command should be written to FD.  The
     HANDLE is provided by the user at start of operation.

     The function should return ‘GPG_ERR_FALSE’ if it did not handle the
     status code, ‘0’ for success, or any other error value.

 -- Function: gpgme_error_t gpgme_op_edit (gpgme_ctx_t CTX,
          gpgme_key_t KEY, gpgme_edit_cb_t FNC, void *HANDLE,
          gpgme_data_t OUT)
     Note: This function is deprecated, please use ‘gpgme_op_interact’
     instead.

     The function ‘gpgme_op_edit’ processes the key KEY interactively,
     using the edit callback function FNC with the handle HANDLE.  The
     callback is invoked for every status and command request from the
     crypto engine.  The output of the crypto engine is written to the
     data object OUT.

     Note that the protocol between the callback function and the crypto
     engine is specific to the crypto engine and no further support in
     implementing this protocol correctly is provided by GPGME.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the edit
     operation completes successfully, ‘GPG_ERR_INV_VALUE’ if CTX or KEY
     is not a valid pointer, and any error returned by the crypto engine
     or the edit callback handler.

 -- Function: gpgme_error_t gpgme_op_edit_start (gpgme_ctx_t CTX,
          gpgme_key_t KEY, gpgme_edit_cb_t FNC, void *HANDLE,
          gpgme_data_t OUT)
     Note: This function is deprecated, please use
     ‘gpgme_op_interact_start’ instead.

     The function ‘gpgme_op_edit_start’ initiates a ‘gpgme_op_edit’
     operation.  It can be completed by calling ‘gpgme_wait’ on the
     context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation was started successfully, and ‘GPG_ERR_INV_VALUE’ if CTX
     or KEY is not a valid pointer.

 -- Function: gpgme_error_t gpgme_op_card_edit (gpgme_ctx_t CTX,
          gpgme_key_t KEY, gpgme_edit_cb_t FNC, void *HANDLE,
          gpgme_data_t OUT)
     Note: This function is deprecated, please use ‘gpgme_op_interact’
     with the flag ‘GPGME_INTERACT_CARD’ instead.

     The function ‘gpgme_op_card_edit’ is analogous to ‘gpgme_op_edit’,
     but should be used to process the smart card corresponding to the
     key KEY.

 -- Function: gpgme_error_t gpgme_op_card_edit_start (gpgme_ctx_t CTX,
          gpgme_key_t KEY, gpgme_edit_cb_t FNC, void *HANDLE,
          gpgme_data_t OUT)
     Note: This function is deprecated, please use
     ‘gpgme_op_interact_start’ with the flag ‘GPGME_INTERACT_CARD’
     instead.

     The function ‘gpgme_op_card_edit_start’ initiates a
     ‘gpgme_op_card_edit’ operation.  It can be completed by calling
     ‘gpgme_wait’ on the context.  *Note Waiting For Completion::.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the
     operation was started successfully, and ‘GPG_ERR_INV_VALUE’ if CTX
     or KEY is not a valid pointer.

 -- Function: gpgme_error_t gpgme_data_new_with_read_cb
          (gpgme_data_t *DH, int (*READFUNC) (void *HOOK, char *BUFFER,
          size_t COUNT, size_t *NREAD), void *HOOK_VALUE)
     The function ‘gpgme_data_new_with_read_cb’ creates a new
     ‘gpgme_data_t’ object and uses the callback function READFUNC to
     retrieve the data on demand.  As the callback function can supply
     the data in any way it wants, this is the most flexible data type
     GPGME provides.  However, it can not be used to write data.

     The callback function receives HOOK_VALUE as its first argument
     whenever it is invoked.  It should return up to COUNT bytes in
     BUFFER, and return the number of bytes actually read in NREAD.  It
     may return ‘0’ in NREAD if no data is currently available.  To
     indicate ‘EOF’ the function should return with an error code of
     ‘-1’ and set NREAD to ‘0’.  The callback function may support to
     reset its internal read pointer if it is invoked with BUFFER and
     NREAD being ‘NULL’ and COUNT being ‘0’.

     The function returns the error code ‘GPG_ERR_NO_ERROR’ if the data
     object was successfully created, ‘GPG_ERR_INV_VALUE’ if DH or
     READFUNC is not a valid pointer, and ‘GPG_ERR_ENOMEM’ if not enough
     memory is available.

 -- Function: gpgme_error_t gpgme_data_rewind (gpgme_data_t DH)
     The function ‘gpgme_data_rewind’ is equivalent to:

            return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
              ? gpgme_error_from_errno (errno) : 0;

 -- Data type: gpgme_attr_t
     The ‘gpgme_attr_t’ type is used to specify a key or trust item
     attribute.  The following attributes are defined:

     ‘GPGME_ATTR_KEYID’
          This is the key ID of a sub key.  It is representable as a
          string.

          For trust items, the trust item refers to the key with this
          ID.

     ‘GPGME_ATTR_FPR’
          This is the fingerprint of a sub key.  It is representable as
          a string.

     ‘GPGME_ATTR_ALGO’
          This is the crypto algorithm for which the sub key can be
          used.  It is representable as a string and as a number.  The
          numbers correspond to the ‘enum gcry_pk_algos’ values in the
          gcrypt library.

     ‘GPGME_ATTR_LEN’
          This is the key length of a sub key.  It is representable as a
          number.

     ‘GPGME_ATTR_CREATED’
          This is the timestamp at creation time of a sub key.  It is
          representable as a number.

     ‘GPGME_ATTR_EXPIRE’
          This is the expiration time of a sub key.  It is representable
          as a number.

     ‘GPGME_ATTR_OTRUST’
          XXX FIXME (also for trust items)

     ‘GPGME_ATTR_USERID’
          This is a user ID. There can be more than one user IDs in a
          GPGME_KEY_T object.  The first one (with index 0) is the
          primary user ID. The user ID is representable as a number.

          For trust items, this is the user ID associated with this
          trust item.

     ‘GPGME_ATTR_NAME’
          This is the name belonging to a user ID. It is representable
          as a string.

     ‘GPGME_ATTR_EMAIL’
          This is the email address belonging to a user ID. It is
          representable as a string.

     ‘GPGME_ATTR_COMMENT’
          This is the comment belonging to a user ID. It is
          representable as a string.

     ‘GPGME_ATTR_VALIDITY’
          This is the validity belonging to a user ID. It is
          representable as a string and as a number.  See below for a
          list of available validities.

          For trust items, this is the validity that is associated with
          this trust item.

     ‘GPGME_ATTR_UID_REVOKED’
          This specifies if a user ID is revoked.  It is representable
          as a number, and is ‘1’ if the user ID is revoked, and ‘0’
          otherwise.

     ‘GPGME_ATTR_UID_INVALID’
          This specifies if a user ID is invalid.  It is representable
          as a number, and is ‘1’ if the user ID is invalid, and ‘0’
          otherwise.

     ‘GPGME_ATTR_LEVEL’
          This is the trust level of a trust item.

     ‘GPGME_ATTR_TYPE’
          This returns information about the type of key.  For the
          string function this will eother be "PGP" or "X.509".  The
          integer function returns 0 for PGP and 1 for X.509.  It is
          also used for the type of a trust item.

     ‘GPGME_ATTR_IS_SECRET’
          This specifies if the key is a secret key.  It is
          representable as a number, and is ‘1’ if the key is revoked,
          and ‘0’ otherwise.

     ‘GPGME_ATTR_KEY_REVOKED’
          This specifies if a sub key is revoked.  It is representable
          as a number, and is ‘1’ if the key is revoked, and ‘0’
          otherwise.

     ‘GPGME_ATTR_KEY_INVALID’
          This specifies if a sub key is invalid.  It is representable
          as a number, and is ‘1’ if the key is invalid, and ‘0’
          otherwise.

     ‘GPGME_ATTR_KEY_EXPIRED’
          This specifies if a sub key is expired.  It is representable
          as a number, and is ‘1’ if the key is expired, and ‘0’
          otherwise.

     ‘GPGME_ATTR_KEY_DISABLED’
          This specifies if a sub key is disabled.  It is representable
          as a number, and is ‘1’ if the key is disabled, and ‘0’
          otherwise.

     ‘GPGME_ATTR_KEY_CAPS’
          This is a description of the capabilities of a sub key.  It is
          representable as a string.  The string contains the letter “e”
          if the key can be used for encryption, “s” if the key can be
          used for signatures, and “c” if the key can be used for
          certifications.

     ‘GPGME_ATTR_CAN_ENCRYPT’
          This specifies if a sub key can be used for encryption.  It is
          representable as a number, and is ‘1’ if the sub key can be
          used for encryption, and ‘0’ otherwise.

     ‘GPGME_ATTR_CAN_SIGN’
          This specifies if a sub key can be used to create data
          signatures.  It is representable as a number, and is ‘1’ if
          the sub key can be used for signatures, and ‘0’ otherwise.

     ‘GPGME_ATTR_CAN_CERTIFY’
          This specifies if a sub key can be used to create key
          certificates.  It is representable as a number, and is ‘1’ if
          the sub key can be used for certifications, and ‘0’ otherwise.

     ‘GPGME_ATTR_SERIAL’
          The X.509 issuer serial attribute of the key.  It is
          representable as a string.

     ‘GPGME_ATTR_ISSUE’
          The X.509 issuer name attribute of the key.  It is
          representable as a string.

     ‘GPGME_ATTR_CHAINID’
          The X.509 chain ID can be used to build the certification
          chain.  It is representable as a string.

 -- Function: const char * gpgme_key_get_string_attr (gpgme_key_t KEY,
          gpgme_attr_t WHAT, const void *RESERVED, int IDX)
     The function ‘gpgme_key_get_string_attr’ returns the value of the
     string-representable attribute WHAT of key KEY.  If the attribute
     is an attribute of a sub key or an user ID, IDX specifies the sub
     key or user ID of which the attribute value is returned.  The
     argument RESERVED is reserved for later use and should be ‘NULL’.

     The string returned is only valid as long as the key is valid.

     The function returns ‘0’ if an attribute can’t be returned as a
     string, KEY is not a valid pointer, IDX out of range, or RESERVED
     not ‘NULL’.

 -- Function: unsigned long gpgme_key_get_ulong_attr (gpgme_key_t KEY,
          gpgme_attr_t WHAT, const void *RESERVED, int IDX)
     The function ‘gpgme_key_get_ulong_attr’ returns the value of the
     number-representable attribute WHAT of key KEY.  If the attribute
     is an attribute of a sub key or an user ID, IDX specifies the sub
     key or user ID of which the attribute value is returned.  The
     argument RESERVED is reserved for later use and should be ‘NULL’.

     The function returns ‘0’ if the attribute can’t be returned as a
     number, KEY is not a valid pointer, IDX out of range, or RESERVED
     not ‘NULL’.

   The signatures on a key are only available if the key was retrieved
via a listing operation with the ‘GPGME_KEYLIST_MODE_SIGS’ mode enabled,
because it is expensive to retrieve all signatures of a key.

   So, before using the below interfaces to retrieve the signatures on a
key, you have to make sure that the key was listed with signatures
enabled.  One convenient, but blocking, way to do this is to use the
function ‘gpgme_get_key’.

 -- Data type: gpgme_attr_t
     The ‘gpgme_attr_t’ type is used to specify a key signature
     attribute.  The following attributes are defined:

     ‘GPGME_ATTR_KEYID’
          This is the key ID of the key which was used for the
          signature.  It is representable as a string.

     ‘GPGME_ATTR_ALGO’
          This is the crypto algorithm used to create the signature.  It
          is representable as a string and as a number.  The numbers
          correspond to the ‘enum gcry_pk_algos’ values in the gcrypt
          library.

     ‘GPGME_ATTR_CREATED’
          This is the timestamp at creation time of the signature.  It
          is representable as a number.

     ‘GPGME_ATTR_EXPIRE’
          This is the expiration time of the signature.  It is
          representable as a number.

     ‘GPGME_ATTR_USERID’
          This is the user ID associated with the signing key.  The user
          ID is representable as a number.

     ‘GPGME_ATTR_NAME’
          This is the name belonging to a user ID. It is representable
          as a string.

     ‘GPGME_ATTR_EMAIL’
          This is the email address belonging to a user ID. It is
          representable as a string.

     ‘GPGME_ATTR_COMMENT’
          This is the comment belonging to a user ID. It is
          representable as a string.

     ‘GPGME_ATTR_KEY_REVOKED’
          This specifies if a key signature is a revocation signature.
          It is representable as a number, and is ‘1’ if the key is
          revoked, and ‘0’ otherwise.

     ‘GPGME_ATTR_SIG_CLASS’
          This specifies the signature class of a key signature.  It is
          representable as a number.  The meaning is specific to the
          crypto engine.

     ‘GPGME_ATTR_SIG_CLASS’
          This specifies the signature class of a key signature.  It is
          representable as a number.  The meaning is specific to the
          crypto engine.

     ‘GPGME_ATTR_SIG_STATUS’
          This is the same value as returned by ‘gpgme_get_sig_status’.

 -- Function: const char * gpgme_key_sig_get_string_attr
          (gpgme_key_t KEY, int UID_IDX, gpgme_attr_t WHAT,
          const void *RESERVED, int IDX)
     The function ‘gpgme_key_sig_get_string_attr’ returns the value of
     the string-representable attribute WHAT of the signature IDX on the
     user ID UID_IDX in the key KEY.  The argument RESERVED is reserved
     for later use and should be ‘NULL’.

     The string returned is only valid as long as the key is valid.

     The function returns ‘0’ if an attribute can’t be returned as a
     string, KEY is not a valid pointer, UID_IDX or IDX out of range, or
     RESERVED not ‘NULL’.

 -- Function: unsigned long gpgme_key_sig_get_ulong_attr
          (gpgme_key_t KEY, int UID_IDX, gpgme_attr_t WHAT,
          const void *RESERVED, int IDX)
     The function ‘gpgme_key_sig_get_ulong_attr’ returns the value of
     the number-representable attribute WHAT of the signature IDX on the
     user ID UID_IDX in the key KEY.  The argument RESERVED is reserved
     for later use and should be ‘NULL’.

     The function returns ‘0’ if an attribute can’t be returned as a
     string, KEY is not a valid pointer, UID_IDX or IDX out of range, or
     RESERVED not ‘NULL’.

   Trust items have attributes which can be queried using the interfaces
below.  The attribute identifiers are shared with those for key
attributes.  *Note Information About Keys::.

 -- Function: const char * gpgme_trust_item_get_string_attr
          (gpgme_trust_item_t ITEM, gpgme_attr_t WHAT,
          const void *RESERVED, int IDX)
     The function ‘gpgme_trust_item_get_string_attr’ returns the value
     of the string-representable attribute WHAT of trust item ITEM.  The
     arguments IDX and RESERVED are reserved for later use and should be
     ‘0’ and ‘NULL’ respectively.

     The string returned is only valid as long as the key is valid.

     The function returns ‘0’ if an attribute can’t be returned as a
     string, KEY is not a valid pointer, IDX out of range, or RESERVED
     not ‘NULL’.

 -- Function: int gpgme_trust_item_get_int_attr
          (gpgme_trust_item_t ITEM, gpgme_attr_t WHAT,
          const void *RESERVED, int IDX)
     The function ‘gpgme_trust_item_get_int_attr’ returns the value of
     the number-representable attribute WHAT of trust item ITEM.  If the
     attribute occurs more than once in the trust item, the index is
     specified by IDX.  However, currently no such attribute exists, so
     IDX should be ‘0’.  The argument RESERVED is reserved for later use
     and should be ‘NULL’.

     The function returns ‘0’ if the attribute can’t be returned as a
     number, KEY is not a valid pointer, IDX out of range, or RESERVED
     not ‘NULL’.

 -- Data type: enum gpgme_sig_stat_t
     The ‘gpgme_sig_stat_t’ type holds the result of a signature check,
     or the combined result of all signatures.  The following results
     are possible:

     ‘GPGME_SIG_STAT_NONE’
          This status should not occur in normal operation.

     ‘GPGME_SIG_STAT_GOOD’
          This status indicates that the signature is valid.  For the
          combined result this status means that all signatures are
          valid.

     ‘GPGME_SIG_STAT_GOOD_EXP’
          This status indicates that the signature is valid but expired.
          For the combined result this status means that all signatures
          are valid and expired.

     ‘GPGME_SIG_STAT_GOOD_EXPKEY’
          This status indicates that the signature is valid but the key
          used to verify the signature has expired.  For the combined
          result this status means that all signatures are valid and all
          keys are expired.

     ‘GPGME_SIG_STAT_BAD’
          This status indicates that the signature is invalid.  For the
          combined result this status means that all signatures are
          invalid.

     ‘GPGME_SIG_STAT_NOKEY’
          This status indicates that the signature could not be verified
          due to a missing key.  For the combined result this status
          means that all signatures could not be checked due to missing
          keys.

     ‘GPGME_SIG_STAT_NOSIG’
          This status indicates that the signature data provided was not
          a real signature.

     ‘GPGME_SIG_STAT_ERROR’
          This status indicates that there was some other error which
          prevented the signature verification.

     ‘GPGME_SIG_STAT_DIFF’
          For the combined result this status means that at least two
          signatures have a different status.  You can get each key’s
          status with ‘gpgme_get_sig_status’.

 -- Function: const char * gpgme_get_sig_status (gpgme_ctx_t CTX,
          int IDX, gpgme_sig_stat_t *R_STAT, time_t *R_CREATED)
     The function ‘gpgme_get_sig_status’ is equivalent to:

            gpgme_verify_result_t result;
            gpgme_signature_t sig;

            result = gpgme_op_verify_result (ctx);
            sig = result->signatures;

            while (sig && idx)
              {
                sig = sig->next;
                idx--;
              }
            if (!sig || idx)
              return NULL;

            if (r_stat)
              {
                switch (gpg_err_code (sig->status))
	          {
          	case GPG_ERR_NO_ERROR:
          	  *r_stat = GPGME_SIG_STAT_GOOD;
          	  break;

          	case GPG_ERR_BAD_SIGNATURE:
          	  *r_stat = GPGME_SIG_STAT_BAD;
          	  break;

          	case GPG_ERR_NO_PUBKEY:
          	  *r_stat = GPGME_SIG_STAT_NOKEY;
          	  break;

          	case GPG_ERR_NO_DATA:
          	  *r_stat = GPGME_SIG_STAT_NOSIG;
          	  break;

          	case GPG_ERR_SIG_EXPIRED:
          	  *r_stat = GPGME_SIG_STAT_GOOD_EXP;
          	  break;

          	case GPG_ERR_KEY_EXPIRED:
          	  *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
          	  break;

          	default:
          	  *r_stat = GPGME_SIG_STAT_ERROR;
          	  break;
	          }
              }
            if (r_created)
              *r_created = sig->timestamp;
            return sig->fpr;

 -- Function: const char * gpgme_get_sig_string_attr (gpgme_ctx_t CTX,
          int IDX, gpgme_attr_t WHAT, int WHATIDX)
     The function ‘gpgme_get_sig_string_attr’ is equivalent to:

            gpgme_verify_result_t result;
            gpgme_signature_t sig;

            result = gpgme_op_verify_result (ctx);
            sig = result->signatures;

            while (sig && idx)
              {
                sig = sig->next;
                idx--;
              }
            if (!sig || idx)
              return NULL;

            switch (what)
              {
              case GPGME_ATTR_FPR:
                return sig->fpr;

              case GPGME_ATTR_ERRTOK:
                if (whatidx == 1)
                  return sig->wrong_key_usage ? "Wrong_Key_Usage" : "";
                else
          	return "";
              default:
                break;
              }

            return NULL;

 -- Function: const char * gpgme_get_sig_ulong_attr (gpgme_ctx_t CTX,
          int IDX, gpgme_attr_t WAHT, int WHATIDX)
     The function ‘gpgme_get_sig_ulong_attr’ is equivalent to:

            gpgme_verify_result_t result;
            gpgme_signature_t sig;

            result = gpgme_op_verify_result (ctx);
            sig = result->signatures;

            while (sig && idx)
              {
                sig = sig->next;
                idx--;
              }
            if (!sig || idx)
              return 0;

            switch (what)
              {
              case GPGME_ATTR_CREATED:
                return sig->timestamp;

              case GPGME_ATTR_EXPIRE:
                return sig->exp_timestamp;

              case GPGME_ATTR_VALIDITY:
                return (unsigned long) sig->validity;

              case GPGME_ATTR_SIG_STATUS:
                switch (sig->status)
	          {
          	case GPG_ERR_NO_ERROR:
          	  return GPGME_SIG_STAT_GOOD;

          	case GPG_ERR_BAD_SIGNATURE:
          	  return GPGME_SIG_STAT_BAD;

          	case GPG_ERR_NO_PUBKEY:
          	  return GPGME_SIG_STAT_NOKEY;

          	case GPG_ERR_NO_DATA:
          	  return GPGME_SIG_STAT_NOSIG;

          	case GPG_ERR_SIG_EXPIRED:
          	  return GPGME_SIG_STAT_GOOD_EXP;

          	case GPG_ERR_KEY_EXPIRED:
          	  return GPGME_SIG_STAT_GOOD_EXPKEY;

          	default:
          	  return GPGME_SIG_STAT_ERROR;
	          }

              case GPGME_ATTR_SIG_SUMMARY:
                return sig->summary;

              default:
                break;
              }
            return 0;

 -- Function: const char * gpgme_get_sig_key (gpgme_ctx_t CTX, int IDX,
          gpgme_key_t *R_KEY)
     The function ‘gpgme_get_sig_key’ is equivalent to:

            gpgme_verify_result_t result;
            gpgme_signature_t sig;

            result = gpgme_op_verify_result (ctx);
            sig = result->signatures;

            while (sig && idx)
              {
                sig = sig->next;
                idx--;
              }
            if (!sig || idx)
              return gpg_error (GPG_ERR_EOF);

            return gpgme_get_key (ctx, sig->fpr, r_key, 0);