1 module bindbc.gnutls.tpm;
2 
3 import bindbc.gnutls.gnutls;
4 
5 struct tpm_key_list_st;
6 alias gnutls_tpm_key_list_t = tpm_key_list_st*;
7 
8 enum GNUTLS_TPM_KEY_SIGNING = 1 << 1;
9 enum GNUTLS_TPM_REGISTER_KEY = 1 << 2;
10 enum GNUTLS_TPM_KEY_USER = 1 << 3;
11 
12 enum gnutls_tpmkey_fmt_t
13 {
14     GNUTLS_TPMKEY_FMT_RAW = 0,
15     GNUTLS_TPMKEY_FMT_DER = GNUTLS_TPMKEY_FMT_RAW,
16     GNUTLS_TPMKEY_FMT_CTK_PEM = 1
17 }
18 
19 version (BindGnuTLS_Static)
20 {
21     extern (System) @nogc nothrow @system:
22 
23     int gnutls_tpm_privkey_generate (gnutls_pk_algorithm_t pk, uint bits, const(char)* srk_password, const(char)* key_password, gnutls_tpmkey_fmt_t format, gnutls_x509_crt_fmt_t pub_format, gnutls_datum_t* privkey, gnutls_datum_t* pubkey, uint flags);
24     void gnutls_tpm_key_list_deinit (gnutls_tpm_key_list_t list);
25     int gnutls_tpm_key_list_get_url (gnutls_tpm_key_list_t list, uint idx, char** url, uint flags);
26     int gnutls_tpm_get_registered (gnutls_tpm_key_list_t* list);
27     int gnutls_tpm_privkey_delete (const(char)* url, const(char)* srk_password);
28 }
29 else
30 {
31     extern (System) @nogc nothrow @system
32     {
33         alias pgnutls_tpm_privkey_generate = int function (gnutls_pk_algorithm_t pk, uint bits, const(char)* srk_password, const(char)* key_password, gnutls_tpmkey_fmt_t format, gnutls_x509_crt_fmt_t pub_format, gnutls_datum_t* privkey, gnutls_datum_t* pubkey, uint flags);
34         alias pgnutls_tpm_key_list_deinit = void function (gnutls_tpm_key_list_t list);
35         alias pgnutls_tpm_key_list_get_url = int function (gnutls_tpm_key_list_t list, uint idx, char** url, uint flags);
36         alias pgnutls_tpm_get_registered = int function (gnutls_tpm_key_list_t* list);
37         alias pgnutls_tpm_privkey_delete = int function (const(char)* url, const(char)* srk_password);
38     }
39 
40     __gshared
41     {
42         pgnutls_tpm_privkey_generate gnutls_tpm_privkey_generate;
43         pgnutls_tpm_key_list_deinit gnutls_tpm_key_list_deinit;
44         pgnutls_tpm_key_list_get_url gnutls_tpm_key_list_get_url;
45         pgnutls_tpm_get_registered gnutls_tpm_get_registered;
46         pgnutls_tpm_privkey_delete gnutls_tpm_privkey_delete;
47     }
48 
49     import bindbc.loader : SharedLib, bindSymbol_stdcall;
50     void bindTpm(SharedLib lib)
51     {
52         lib.bindSymbol_stdcall(gnutls_tpm_privkey_generate, "gnutls_tpm_privkey_generate");
53         lib.bindSymbol_stdcall(gnutls_tpm_key_list_deinit, "gnutls_tpm_key_list_deinit");
54         lib.bindSymbol_stdcall(gnutls_tpm_key_list_get_url, "gnutls_tpm_key_list_get_url");
55         lib.bindSymbol_stdcall(gnutls_tpm_get_registered, "gnutls_tpm_get_registered");
56         lib.bindSymbol_stdcall(gnutls_tpm_privkey_delete, "gnutls_tpm_privkey_delete");
57     }
58 }