1 module bindbc.gnutls;
2 
3 public import bindbc.gnutls.abstract_;
4 public import bindbc.gnutls.config;
5 public import bindbc.gnutls.crypto;
6 public import bindbc.gnutls.dane;
7 public import bindbc.gnutls.dtls;
8 public import bindbc.gnutls.gnutls;
9 public import bindbc.gnutls.ocsp;
10 public import bindbc.gnutls.openpgp;
11 public import bindbc.gnutls.pkcs7;
12 public import bindbc.gnutls.pkcs11;
13 public import bindbc.gnutls.pkcs12;
14 public import bindbc.gnutls.self_test;
15 public import bindbc.gnutls.socket;
16 public import bindbc.gnutls.system_keys;
17 public import bindbc.gnutls.tpm;
18 public import bindbc.gnutls.urls;
19 public import bindbc.gnutls.x509_ext;
20 public import bindbc.gnutls.x509;
21 
22 version (BindGnuTLS_Static) {}
23 else {
24     import bindbc.loader;
25 
26     private SharedLib lib, libDane;
27 
28     GnuTLSSupport loadGnuTLS()
29     {
30         version(Windows) {
31             const(char)[][2] libNames = [
32                 "libgnutls.dll",
33                 "libgnutls-30.dll"
34             ];
35         }
36         else version(Posix) {
37             const(char)[][2] libNames = [
38                 "libgnutls.so",
39                 "libgnutls.so.30"
40             ];
41         }
42         else static assert(0, "bindbc-gnutls is not yet supported on this platform.");
43 
44         GnuTLSSupport ret;
45         foreach (name; libNames) {
46             ret = loadGnuTLS(name.ptr);
47             if (ret != GnuTLSSupport.noLibrary) break;
48         }
49         return ret;
50     }
51 
52     GnuTLSSupport loadGnuTLS_Dane()
53     {
54         version(Posix) {
55             const(char)[][2] libNames = [
56                 "libgnutls-dane.so",
57                 "libgnutls-dane.so.0"
58             ];
59         }
60         else static assert(0, "bindbc-gnutls-dane is not yet supported on this platform.");
61 
62         GnuTLSSupport ret;
63         foreach (name; libNames) {
64             ret = loadGnuTLS_Dane(name.ptr);
65             if (ret != GnuTLSSupport.noLibrary) break;
66         }
67         return ret;
68     }
69 
70     GnuTLSSupport loadGnuTLS(const(char)* libName)
71     {
72         // If the library isn't yet loaded, load it now.
73         if (lib == invalidHandle)
74         {
75             lib = load(libName);
76             if (lib == invalidHandle) return GnuTLSSupport.noLibrary;
77         }
78 
79         immutable errCount = errorCount();
80 
81         // Bind functions from individual modules
82         lib.bindAbstract();
83         lib.bindCrypto();
84         lib.bindDtls();
85         lib.bindGnutls();
86         lib.bindOcsp();
87         lib.bindOpenPGP();
88         lib.bindPkcs7();
89         lib.bindPkcs11();
90         lib.bindPkcs12();
91         lib.bindSelfTest();
92 
93         static if (gnuTLSSupport >= GnuTLSSupport.gnutls_3_5_3)
94             lib.bindSocket();
95 
96         lib.bindSystemKeys();
97         lib.bindTpm();
98         lib.bindUrls();
99         lib.bindX509Ext();
100         lib.bindX509();
101 
102         if (errorCount() != errCount) return GnuTLSSupport.badLibrary;
103         return gnuTLSSupport;
104     }
105 
106     GnuTLSSupport loadGnuTLS_Dane(const(char)* libName)
107     {
108         // If the library isn't yet loaded, load it now.
109         if (libDane == invalidHandle)
110         {
111             libDane = load(libName);
112             if (libDane == invalidHandle) return GnuTLSSupport.noLibrary;
113         }
114 
115         immutable errCount = errorCount();
116 
117         libDane.bindDane();
118 
119         if (errorCount() != errCount) return GnuTLSSupport.badLibrary;
120         return gnuTLSSupport;
121     }
122 }