1 module bindbc.gnutls.pkcs7;
2 
3 import bindbc.gnutls.config;
4 import bindbc.gnutls.gnutls;
5 import bindbc.gnutls.x509;
6 import core.sys.posix.sys.select;
7 
8 struct gnutls_pkcs7_int;
9 alias gnutls_pkcs7_t = gnutls_pkcs7_int*;
10 
11 enum GNUTLS_PKCS7_EDATA_GET_RAW = 1 << 24;
12 
13 struct gnutls_pkcs7_attrs_st;
14 alias gnutls_pkcs7_attrs_t = gnutls_pkcs7_attrs_st*;
15 
16 struct gnutls_pkcs7_signature_info_st
17 {
18     gnutls_sign_algorithm_t algo;
19     gnutls_datum_t sig;
20     gnutls_datum_t issuer_dn;
21     gnutls_datum_t signer_serial;
22     gnutls_datum_t issuer_keyid;
23     time_t signing_time;
24     gnutls_pkcs7_attrs_t signed_attrs;
25     gnutls_pkcs7_attrs_t unsigned_attrs;
26     char[64] pad;
27 }
28 
29 enum GNUTLS_PKCS7_ATTR_ENCODE_OCTET_STRING = 1;
30 
31 enum gnutls_pkcs7_sign_flags
32 {
33     GNUTLS_PKCS7_EMBED_DATA = 1,
34     GNUTLS_PKCS7_INCLUDE_TIME = 1 << 1,
35     GNUTLS_PKCS7_INCLUDE_CERT = 1 << 2,
36     GNUTLS_PKCS7_WRITE_SPKI = 1 << 3
37 }
38 
39 version (BindGnuTLS_Static)
40 {
41     extern (System) @nogc nothrow @system:
42 
43     int gnutls_pkcs7_init (gnutls_pkcs7_t* pkcs7);
44     void gnutls_pkcs7_deinit (gnutls_pkcs7_t pkcs7);
45     int gnutls_pkcs7_import (gnutls_pkcs7_t pkcs7, const(gnutls_datum_t)* data, gnutls_x509_crt_fmt_t format);
46     int gnutls_pkcs7_export (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_fmt_t format, void* output_data, size_t* output_data_size);
47     int gnutls_pkcs7_export2 (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_fmt_t format, gnutls_datum_t* out_);
48     int gnutls_pkcs7_get_signature_count (gnutls_pkcs7_t pkcs7);
49     int gnutls_pkcs7_get_embedded_data (gnutls_pkcs7_t pkcs7, uint flags, gnutls_datum_t* data);
50 
51     static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_5_6)
52         const(char)* gnutls_pkcs7_get_embedded_data_oid (gnutls_pkcs7_t pkcs7);
53 
54     int gnutls_pkcs7_get_crt_count (gnutls_pkcs7_t pkcs7);
55     int gnutls_pkcs7_get_crt_raw (gnutls_pkcs7_t pkcs7, uint indx, void* certificate, size_t* certificate_size);
56     int gnutls_pkcs7_set_crt_raw (gnutls_pkcs7_t pkcs7, const(gnutls_datum_t)* crt);
57     int gnutls_pkcs7_set_crt (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t crt);
58     int gnutls_pkcs7_delete_crt (gnutls_pkcs7_t pkcs7, int indx);
59     int gnutls_pkcs7_get_crl_raw (gnutls_pkcs7_t pkcs7, uint indx, void* crl, size_t* crl_size);
60     int gnutls_pkcs7_get_crl_count (gnutls_pkcs7_t pkcs7);
61     int gnutls_pkcs7_set_crl_raw (gnutls_pkcs7_t pkcs7, const(gnutls_datum_t)* crl);
62     int gnutls_pkcs7_set_crl (gnutls_pkcs7_t pkcs7, gnutls_x509_crl_t crl);
63     int gnutls_pkcs7_delete_crl (gnutls_pkcs7_t pkcs7, int indx);
64     void gnutls_pkcs7_signature_info_deinit (gnutls_pkcs7_signature_info_st* info);
65     int gnutls_pkcs7_get_signature_info (gnutls_pkcs7_t pkcs7, uint idx, gnutls_pkcs7_signature_info_st* info);
66     int gnutls_pkcs7_verify_direct (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t signer, uint idx, const(gnutls_datum_t)* data, uint flags);
67     int gnutls_pkcs7_verify (gnutls_pkcs7_t pkcs7, gnutls_x509_trust_list_t tl, gnutls_typed_vdata_st* vdata, uint vdata_size, uint idx, const(gnutls_datum_t)* data, uint flags);
68     int gnutls_pkcs7_add_attr (gnutls_pkcs7_attrs_t* list, const(char)* oid, gnutls_datum_t* data, uint flags);
69     void gnutls_pkcs7_attrs_deinit (gnutls_pkcs7_attrs_t list);
70     int gnutls_pkcs7_get_attr (gnutls_pkcs7_attrs_t list, uint idx, char** oid, gnutls_datum_t* data, uint flags);
71     int gnutls_pkcs7_sign (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t signer, gnutls_privkey_t signer_key, const(gnutls_datum_t)* data, gnutls_pkcs7_attrs_t signed_attrs, gnutls_pkcs7_attrs_t unsigned_attrs, gnutls_digest_algorithm_t dig, uint flags);
72     int gnutls_pkcs7_get_crt_raw2 (gnutls_pkcs7_t pkcs7, uint indx, gnutls_datum_t* cert);
73     int gnutls_pkcs7_get_crl_raw2 (gnutls_pkcs7_t pkcs7, uint indx, gnutls_datum_t* crl);
74     int gnutls_pkcs7_print (gnutls_pkcs7_t pkcs7, gnutls_certificate_print_formats_t format, gnutls_datum_t* out_);
75 
76     static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_6_14)
77         int gnutls_pkcs7_print_signature_info (gnutls_pkcs7_signature_info_st* info, gnutls_certificate_print_formats_t format, gnutls_datum_t* out_);
78 }
79 else
80 {
81     extern (System) @nogc nothrow @system
82     {
83         alias pgnutls_pkcs7_init = int function (gnutls_pkcs7_t* pkcs7);
84         alias pgnutls_pkcs7_deinit = void function (gnutls_pkcs7_t pkcs7);
85         alias pgnutls_pkcs7_import = int function (gnutls_pkcs7_t pkcs7, const(gnutls_datum_t)* data, gnutls_x509_crt_fmt_t format);
86         alias pgnutls_pkcs7_export = int function (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_fmt_t format, void* output_data, size_t* output_data_size);
87         alias pgnutls_pkcs7_export2 = int function (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_fmt_t format, gnutls_datum_t* out_);
88         alias pgnutls_pkcs7_get_signature_count = int function (gnutls_pkcs7_t pkcs7);
89         alias pgnutls_pkcs7_get_embedded_data = int function (gnutls_pkcs7_t pkcs7, uint flags, gnutls_datum_t* data);
90 
91         static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_5_6)
92             alias pgnutls_pkcs7_get_embedded_data_oid = const(char)* function (gnutls_pkcs7_t pkcs7);
93 
94         alias pgnutls_pkcs7_get_crt_count = int function (gnutls_pkcs7_t pkcs7);
95         alias pgnutls_pkcs7_get_crt_raw = int function (gnutls_pkcs7_t pkcs7, uint indx, void* certificate, size_t* certificate_size);
96         alias pgnutls_pkcs7_set_crt_raw = int function (gnutls_pkcs7_t pkcs7, const(gnutls_datum_t)* crt);
97         alias pgnutls_pkcs7_set_crt = int function (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t crt);
98         alias pgnutls_pkcs7_delete_crt = int function (gnutls_pkcs7_t pkcs7, int indx);
99         alias pgnutls_pkcs7_get_crl_raw = int function (gnutls_pkcs7_t pkcs7, uint indx, void* crl, size_t* crl_size);
100         alias pgnutls_pkcs7_get_crl_count = int function (gnutls_pkcs7_t pkcs7);
101         alias pgnutls_pkcs7_set_crl_raw = int function (gnutls_pkcs7_t pkcs7, const(gnutls_datum_t)* crl);
102         alias pgnutls_pkcs7_set_crl = int function (gnutls_pkcs7_t pkcs7, gnutls_x509_crl_t crl);
103         alias pgnutls_pkcs7_delete_crl = int function (gnutls_pkcs7_t pkcs7, int indx);
104         alias pgnutls_pkcs7_signature_info_deinit = void function (gnutls_pkcs7_signature_info_st* info);
105         alias pgnutls_pkcs7_get_signature_info = int function (gnutls_pkcs7_t pkcs7, uint idx, gnutls_pkcs7_signature_info_st* info);
106         alias pgnutls_pkcs7_verify_direct = int function (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t signer, uint idx, const(gnutls_datum_t)* data, uint flags);
107         alias pgnutls_pkcs7_verify = int function (gnutls_pkcs7_t pkcs7, gnutls_x509_trust_list_t tl, gnutls_typed_vdata_st* vdata, uint vdata_size, uint idx, const(gnutls_datum_t)* data, uint flags);
108         alias pgnutls_pkcs7_add_attr = int function (gnutls_pkcs7_attrs_t* list, const(char)* oid, gnutls_datum_t* data, uint flags);
109         alias pgnutls_pkcs7_attrs_deinit = void function (gnutls_pkcs7_attrs_t list);
110         alias pgnutls_pkcs7_get_attr = int function (gnutls_pkcs7_attrs_t list, uint idx, char** oid, gnutls_datum_t* data, uint flags);
111         alias pgnutls_pkcs7_sign = int function (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t signer, gnutls_privkey_t signer_key, const(gnutls_datum_t)* data, gnutls_pkcs7_attrs_t signed_attrs, gnutls_pkcs7_attrs_t unsigned_attrs, gnutls_digest_algorithm_t dig, uint flags);
112         alias pgnutls_pkcs7_get_crt_raw2 = int function (gnutls_pkcs7_t pkcs7, uint indx, gnutls_datum_t* cert);
113         alias pgnutls_pkcs7_get_crl_raw2 = int function (gnutls_pkcs7_t pkcs7, uint indx, gnutls_datum_t* crl);
114         alias pgnutls_pkcs7_print = int function (gnutls_pkcs7_t pkcs7, gnutls_certificate_print_formats_t format, gnutls_datum_t* out_);
115 
116         static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_6_14)
117             alias pgnutls_pkcs7_print_signature_info = int function (gnutls_pkcs7_signature_info_st* info, gnutls_certificate_print_formats_t format, gnutls_datum_t* out_);
118     }
119 
120     __gshared
121     {
122         pgnutls_pkcs7_init gnutls_pkcs7_init;
123         pgnutls_pkcs7_deinit gnutls_pkcs7_deinit;
124         pgnutls_pkcs7_import gnutls_pkcs7_import;
125         pgnutls_pkcs7_export gnutls_pkcs7_export;
126         pgnutls_pkcs7_export2 gnutls_pkcs7_export2;
127         pgnutls_pkcs7_get_signature_count gnutls_pkcs7_get_signature_count;
128         pgnutls_pkcs7_get_embedded_data gnutls_pkcs7_get_embedded_data;
129 
130         static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_5_6)
131             pgnutls_pkcs7_get_embedded_data_oid gnutls_pkcs7_get_embedded_data_oid;
132 
133         pgnutls_pkcs7_get_crt_count gnutls_pkcs7_get_crt_count;
134         pgnutls_pkcs7_get_crt_raw gnutls_pkcs7_get_crt_raw;
135         pgnutls_pkcs7_set_crt_raw gnutls_pkcs7_set_crt_raw;
136         pgnutls_pkcs7_set_crt gnutls_pkcs7_set_crt;
137         pgnutls_pkcs7_delete_crt gnutls_pkcs7_delete_crt;
138         pgnutls_pkcs7_get_crl_raw gnutls_pkcs7_get_crl_raw;
139         pgnutls_pkcs7_get_crl_count gnutls_pkcs7_get_crl_count;
140         pgnutls_pkcs7_set_crl_raw gnutls_pkcs7_set_crl_raw;
141         pgnutls_pkcs7_set_crl gnutls_pkcs7_set_crl;
142         pgnutls_pkcs7_delete_crl gnutls_pkcs7_delete_crl;
143         pgnutls_pkcs7_signature_info_deinit gnutls_pkcs7_signature_info_deinit;
144         pgnutls_pkcs7_get_signature_info gnutls_pkcs7_get_signature_info;
145         pgnutls_pkcs7_verify_direct gnutls_pkcs7_verify_direct;
146         pgnutls_pkcs7_verify gnutls_pkcs7_verify;
147         pgnutls_pkcs7_add_attr gnutls_pkcs7_add_attr;
148         pgnutls_pkcs7_attrs_deinit gnutls_pkcs7_attrs_deinit;
149         pgnutls_pkcs7_get_attr gnutls_pkcs7_get_attr;
150         pgnutls_pkcs7_sign gnutls_pkcs7_sign;
151         pgnutls_pkcs7_get_crt_raw2 gnutls_pkcs7_get_crt_raw2;
152         pgnutls_pkcs7_get_crl_raw2 gnutls_pkcs7_get_crl_raw2;
153         pgnutls_pkcs7_print gnutls_pkcs7_print;
154 
155         static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_6_14)
156             pgnutls_pkcs7_print_signature_info gnutls_pkcs7_print_signature_info;
157     }
158 
159     import bindbc.loader : SharedLib, bindSymbol_stdcall;
160     void bindPkcs7(SharedLib lib)
161     {
162         lib.bindSymbol_stdcall(gnutls_pkcs7_init, "gnutls_pkcs7_init");
163         lib.bindSymbol_stdcall(gnutls_pkcs7_deinit, "gnutls_pkcs7_deinit");
164         lib.bindSymbol_stdcall(gnutls_pkcs7_import, "gnutls_pkcs7_import");
165         lib.bindSymbol_stdcall(gnutls_pkcs7_export, "gnutls_pkcs7_export");
166         lib.bindSymbol_stdcall(gnutls_pkcs7_export2, "gnutls_pkcs7_export2");
167         lib.bindSymbol_stdcall(gnutls_pkcs7_get_signature_count, "gnutls_pkcs7_get_signature_count");
168         lib.bindSymbol_stdcall(gnutls_pkcs7_get_embedded_data, "gnutls_pkcs7_get_embedded_data");
169 
170         static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_5_6)
171             lib.bindSymbol_stdcall(gnutls_pkcs7_get_embedded_data_oid, "gnutls_pkcs7_get_embedded_data_oid");
172 
173         lib.bindSymbol_stdcall(gnutls_pkcs7_get_crt_count, "gnutls_pkcs7_get_crt_count");
174         lib.bindSymbol_stdcall(gnutls_pkcs7_get_crt_raw, "gnutls_pkcs7_get_crt_raw");
175         lib.bindSymbol_stdcall(gnutls_pkcs7_set_crt_raw, "gnutls_pkcs7_set_crt_raw");
176         lib.bindSymbol_stdcall(gnutls_pkcs7_set_crt, "gnutls_pkcs7_set_crt");
177         lib.bindSymbol_stdcall(gnutls_pkcs7_delete_crt, "gnutls_pkcs7_delete_crt");
178         lib.bindSymbol_stdcall(gnutls_pkcs7_get_crl_raw, "gnutls_pkcs7_get_crl_raw");
179         lib.bindSymbol_stdcall(gnutls_pkcs7_get_crl_count, "gnutls_pkcs7_get_crl_count");
180         lib.bindSymbol_stdcall(gnutls_pkcs7_set_crl_raw, "gnutls_pkcs7_set_crl_raw");
181         lib.bindSymbol_stdcall(gnutls_pkcs7_set_crl, "gnutls_pkcs7_set_crl");
182         lib.bindSymbol_stdcall(gnutls_pkcs7_delete_crl, "gnutls_pkcs7_delete_crl");
183         lib.bindSymbol_stdcall(gnutls_pkcs7_signature_info_deinit, "gnutls_pkcs7_signature_info_deinit");
184         lib.bindSymbol_stdcall(gnutls_pkcs7_get_signature_info, "gnutls_pkcs7_get_signature_info");
185         lib.bindSymbol_stdcall(gnutls_pkcs7_verify_direct, "gnutls_pkcs7_verify_direct");
186         lib.bindSymbol_stdcall(gnutls_pkcs7_verify, "gnutls_pkcs7_verify");
187         lib.bindSymbol_stdcall(gnutls_pkcs7_add_attr, "gnutls_pkcs7_add_attr");
188         lib.bindSymbol_stdcall(gnutls_pkcs7_attrs_deinit, "gnutls_pkcs7_attrs_deinit");
189         lib.bindSymbol_stdcall(gnutls_pkcs7_get_attr, "gnutls_pkcs7_get_attr");
190         lib.bindSymbol_stdcall(gnutls_pkcs7_sign, "gnutls_pkcs7_sign");
191         lib.bindSymbol_stdcall(gnutls_pkcs7_get_crt_raw2, "gnutls_pkcs7_get_crt_raw2");
192         lib.bindSymbol_stdcall(gnutls_pkcs7_get_crl_raw2, "gnutls_pkcs7_get_crl_raw2");
193         lib.bindSymbol_stdcall(gnutls_pkcs7_print, "gnutls_pkcs7_print");
194 
195         static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_6_14)
196             lib.bindSymbol_stdcall(gnutls_pkcs7_print_signature_info, "gnutls_pkcs7_print_signature_info");
197     }
198 }