Fix `this' access in default signal handlers
[vala-lang.git] / vapi / gnutls.vapi
blobfae83b3828ead1f81f44f2d208ea0c05794febcc
1 /* gnutls.vapi
2  *
3  * Copyright (C) 2009  Jiří Zárevúcky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *
19  * As a special exception, if you use inline functions from this file, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU Lesser General Public License.
22  *
23  * Author:
24  *      Jiří Zárevúcky <zarevucky.jiri@gmail.com>
25  *
26  */
28 [CCode (cprefix = "gnutls_", lower_case_cprefix = "gnutls_", cheader_filename = "gnutls/gnutls.h")]
29 namespace GnuTLS
31         [CCode (cname = "LIBGNUTLS_VERSION")]
32         public const string VERSION;
33         [CCode (cname = "LIBGNUTLS_VERSION_MAJOR")]
34         public const int VERSION_MAJOR;
35         [CCode (cname = "LIBGNUTLS_VERSION_MINOR")]
36         public const int VERSION_MINOR;
37         [CCode (cname = "LIBGNUTLS_VERSION_PATCH")]
38         public const int VERSION_PATCH;
39         [CCode (cname = "LIBGNUTLS_VERSION_NUMBER")]
40         public const int VERSION_NUMBER;
42         public unowned string? check_version (string? req_version);
44         [CCode (cname = "gnutls_cipher_algorithm_t", cprefix = "GNUTLS_CIPHER_")]
45         public enum CipherAlgorithm {
46                 UNKNOWN,
47                 NULL,
48                 ARCFOUR_128,
49                 3DES_CBC,
50                 AES_128_CBC,
51                 AES_256_CBC,
52                 ARCFOUR_40,
53                 CAMELLIA_128_CBC,
54                 CAMELLIA_256_CBC,
55                 RC2_40_CBC,
56                 DES_CBC,
58                 RIJNDAEL_128_CBC,    // == AES_128_CBC
59                 RIJNDAEL_256_CBC,    // == AES_256_CBC
60                 RIJNDAEL_CBC,        // == AES_128_CBC
61                 ARCFOUR;             // == ARCFOUR_128
63                 [CCode (cname = "gnutls_cipher_get_key_size")]
64                 public size_t get_key_size ();
65                 [CCode (cname = "gnutls_cipher_get_name")]
66                 public unowned string? get_name ();
67                 [CCode (cname = "gnutls_mac_get_id")]
68                 public static CipherAlgorithm from_name (string name);
69                 [CCode (cname = "gnutls_cipher_list", array_length = "false", array_null_terminated = "true")]
70                 public static unowned CipherAlgorithm[] list ();
71         }
73         [CCode (cname = "gnutls_kx_algorithm_t", cprefix = "GNUTLS_KX_")]
74         public enum KXAlgorithm {
75                 UNKNOWN,
76                 RSA,
77                 DHE_DSS,
78                 DHE_RSA,
79                 ANON_DH,
80                 SRP,
81                 RSA_EXPORT,
82                 SRP_RSA,
83                 SRP_DSS,
84                 PSK,
85                 DHE_PSK;
87                 [CCode (cname = "gnutls_kx_get_name")]
88                 public unowned string? get_name ();
89                 [CCode (cname = "gnutls_kx_get_id")]
90                 public static KXAlgorithm from_name (string name);
91                 [CCode (cname = "gnutls_kx_list", array_length = "false", array_null_terminated = "true")]
92                 public static unowned KXAlgorithm[] list ();
93         }
95         [CCode (cname = "gnutls_mac_algorithm_t", cprefix = "GNUTLS_MAC_")]
96         public enum MacAlgorithm {
97                 UNKNOWN,
98                 NULL,
99                 MD5,
100                 SHA1,
101                 RMD160,
102                 MD2,
103                 SHA256,
104                 SHA384,
105                 SHA512;
107                 [CCode (cname = "gnutls_mac_get_key_size")]
108                 public size_t get_key_size ();
109                 [CCode (cname = "gnutls_mac_get_name")]
110                 public unowned string? get_name ();
111                 [CCode (cname = "gnutls_mac_get_id")]
112                 public static MacAlgorithm from_name (string name);
113                 [CCode (cname = "gnutls_mac_list", array_length = "false", array_null_terminated = "true")]
114                 public static unowned MacAlgorithm[] list ();
115         }
117         [CCode (cname = "gnutls_digest_algorithm_t", cprefix = "GNUTLS_DIG_")]
118         public enum DigestAlgorithm {
119                 NULL,
120                 MD5,
121                 SHA1,
122                 RMD160,
123                 MD2,
124                 SHA224,
125                 SHA256,
126                 SHA384,
127                 SHA512;
129                 [CCode (cname = "gnutls_fingerprint")]
130                 public int fingerprint (/* const */ ref Datum data, void* result, ref size_t result_size);
131         }
133         [CCode (cname = "GNUTLS_MAX_ALGORITHM_NUM")]
134         public const int MAX_ALGORITHM_NUM;
136         [CCode (cname = "gnutls_pk_algorithm_t", cprefix = "GNUTLS_PK_")]
137         public enum PKAlgorithm {
138                 UNKNOWN,
139                 RSA,
140                 DSA;
142                 [CCode (cname = "gnutls_pk_algorithm_get_name")]
143                 public unowned string? get_name ();
144         }
146         [CCode (cname = "gnutls_sign_algorithm_t", cprefix = "GNUTLS_SIGN_")]
147         public enum SignAlgorithm {
148                 UNKNOWN,
149                 RSA_SHA1,
150                 DSA_SHA1,
151                 RSA_MD5,
152                 RSA_MD2,
153                 RSA_RMD160,
154                 RSA_SHA224,
155                 RSA_SHA256,
156                 RSA_SHA384,
157                 RSA_SHA512;
159                 [CCode (cname = "gnutls_sign_algorithm_get_name")]
160                 public unowned string? get_name ();
161         }
163         [CCode (cname = "gnutls_compression_method_t", cprefix = "GNUTLS_COMP_")]
164         public enum CompressionMethod {
165                 UNKNOWN,
166                 NULL,
167                 DEFLATE,
168                 ZLIB,     // == DEFLATE
169                 LZO;      // only available if gnutls-extra has been initialized
171                 [CCode (cname = "gnutls_compression_get_name")]
172                 public unowned string? get_name ();
173                 [CCode (cname = "gnutls_compression_get_id")]
174                 public static CompressionMethod from_name (string name);
175                 [CCode (cname = "gnutls_compression_list", array_length = "false", array_null_terminated = "true")]
176                 public static unowned CompressionMethod[] list ();
177         }
179         [CCode (cname = "gnutls_params_type_t", cprefix = "GNUTLS_PARAMS_")]
180         public enum ParamsType {
181                 RSA_EXPORT,
182                 DH
183         }
185         [CCode (cname = "gnutls_credentials_type_t", cprefix = "GNUTLS_CRD_")]
186         public enum CredentialsType {
187                 CERTIFICATE,
188                 ANON,
189                 SRP,
190                 PSK,
191                 IA
192         }
194         [CCode (cname = "gnutls_alert_level_t", cprefix = "GNUTLS_AL_")]
195         public enum AlertLevel {
196                 WARNING,
197                 FATAL
198         }
200         [CCode (cname = "gnutls_alert_description_t", cprefix = "GNUTLS_A_")]
201         public enum AlertDescription {
202                 CLOSE_NOTIFY,
203                 UNEXPECTED_MESSAGE,
204                 BAD_RECORD_MAC,
205                 DECRYPTION_FAILED,
206                 RECORD_OVERFLOW,
207                 DECOMPRESSION_FAILURE,
208                 HANDSHAKE_FAILURE,
209                 SSL3_NO_CERTIFICATE,
210                 BAD_CERTIFICATE,
211                 UNSUPPORTED_CERTIFICATE,
212                 CERTIFICATE_REVOKED,
213                 CERTIFICATE_EXPIRED,
214                 CERTIFICATE_UNKNOWN,
215                 ILLEGAL_PARAMETER,
216                 UNKNOWN_CA,
217                 ACCESS_DENIED,
218                 DECODE_ERROR,
219                 DECRYPT_ERROR,
220                 EXPORT_RESTRICTION,
221                 PROTOCOL_VERSION,
222                 INSUFFICIENT_SECURITY,
223                 INTERNAL_ERROR,
224                 USER_CANCELED,
225                 NO_RENEGOTIATION,
226                 UNSUPPORTED_EXTENSION,
227                 CERTIFICATE_UNOBTAINABLE,
228                 UNRECOGNIZED_NAME,
229                 UNKNOWN_PSK_IDENTITY,
230                 INNER_APPLICATION_FAILURE,
231                 INNER_APPLICATION_VERIFICATION;
233                 [CCode (cname = "gnutls_alert_get_name")]
234                 public unowned string? get_name ();
235         }
237         [CCode (cname = "gnutls_handshake_description_t", cprefix = "GNUTLS_HANDSHAKE_")]
238         public enum HandshakeDescription {
239                 HELLO_REQUEST,
240                 CLIENT_HELLO,
241                 SERVER_HELLO,
242                 CERTIFICATE_PKT,
243                 SERVER_KEY_EXCHANGE,
244                 CERTIFICATE_REQUEST,
245                 SERVER_HELLO_DONE,
246                 CERTIFICATE_VERIFY,
247                 CLIENT_KEY_EXCHANGE,
248                 FINISHED,
249                 SUPPLEMENTAL
250         }
252         /* Note that the status bits have different meanings
253          * in openpgp keys and x.509 certificate verification.
254          */
255         [Flags]
256         [CCode (cname = "gnutls_certificate_status_t", cprefix = "GNUTLS_CERT_")]
257         public enum CertificateStatus {
258                 INVALID,             // will be set if the certificate was not verified.
259                 REVOKED,             // in X.509 this will be set only if CRLs are checked
260                 SIGNER_NOT_FOUND,
261                 SIGNER_NOT_CA,
262                 INSECURE_ALGORITHM
263         }
265         [CCode (cname = "gnutls_certificate_request_t", cprefix = "GNUTLS_CERT_")]
266         public enum CertificateRequest {
267                 IGNORE,
268                 REQUEST,
269                 REQUIRE
270         }
272 //      [CCode (cname = "gnutls_openpgp_crt_status_t", cprefix = "GNUTLS_OPENPGP_")]
273 //      public enum OpenPGP.CertificateStatus {
274 //              CERT,
275 //              CERT_FINGERPRINT
276 //      }
278 //      [CCode (cname = "gnutls_connection_end_t", cprefix = "GNUTLS_")]
279 //      public enum ConnectionEnd {
280 //              SERVER,
281 //              CLIENT
282 //      }
284         [CCode (cname = "gnutls_close_request_t", cprefix = "GNUTLS_SHUT_")]
285         public enum CloseRequest {
286                 RDWR,
287                 WR
288         }
290         [CCode (cname = "gnutls_protocol_t", cprefix = "GNUTLS_")]
291         public enum Protocol {
292                 SSL3,
293                 TLS1,    // == TLS1_0
294                 TLS1_0,
295                 TLS1_1,
296                 TLS1_2,
297                 [CCode (cname = "GNUTLS_VERSION_UNKNOWN")]
298                 UNKNOWN;
300                 [CCode (cname = "gnutls_protocol_get_name")]
301                 public unowned string? get_name ();
302                 [CCode (cname = "gnutls_protocol_get_id")]
303                 public static Protocol from_name (string name);
304                 [CCode (cname = "gnutls_protocol_list", array_length = "false", array_null_terminated = "true")]
305                 public static unowned Protocol[] list ();
306         }
308         [CCode (cname = "gnutls_certificate_type_t", cprefix = "GNUTLS_CRT_")]
309         public enum CertificateType {
310                 UNKNOWN,
311                 X509,
312                 OPENPGP;
314                 [CCode (cname = "gnutls_certificate_type_get_name")]
315                 public unowned string? get_name ();
316                 [CCode (cname = "gnutls_certificate_type_get_id")]
317                 public static CertificateType from_name (string name);
318                 [CCode (cname = "gnutls_certificate_type_list", array_length = "false", array_null_terminated = "true")]
319                 public static unowned CertificateType[] list ();
320         }
322         [CCode (cname = "gnutls_certificate_print_formats_t", cprefix = "GNUTLS_CRT_PRINT_")]
323         public enum CertificatePrintFormats {
324                 FULL,
325                 ONELINE,
326                 UNSIGNED_FULL
327         }
329         [Flags]
330         [CCode (cname = "unsigned int", cprefix = "GNUTLS_KEY_")]
331         public enum KeyUsage
332         {
333                 DIGITAL_SIGNATURE,
334                 NON_REPUDIATION,
335                 KEY_ENCIPHERMENT,
336                 DATA_ENCIPHERMENT,
337                 KEY_AGREEMENT,
338                 KEY_CERT_SIGN,
339                 CRL_SIGN,
340                 ENCIPHER_ONLY,
341                 DECIPHER_ONLY
342         }
344         [CCode (cname = "gnutls_server_name_type_t", cprefix = "GNUTLS_NAME_")]
345         public enum ServerNameType {
346                 DNS;
347         }
349         // Diffie Hellman parameter handling.
350         [Compact]
351         [CCode (cname = "struct gnutls_dh_params_int", free_function = "gnutls_dh_params_deinit", lower_case_cprefix = "gnutls_dh_params_")]
352         public class DHParams {
353                 private static int init (DHParams* dh_params);
354                 public static DHParams create ()
355                 {
356                         DHParams result = null;
357                         var ret = init (&result);
358                         if (ret != 0)
359                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
360                         return result;
361                 }
363                 private int cpy (DHParams source);
365                 public int import_raw (/* const */ ref Datum prime, /* const */ ref Datum generator);
366                 public int export_raw (/* const */ ref Datum prime, /* const */ ref Datum generator, out uint bits);
367                 public int import_pkcs3 (/* const */ ref Datum pkcs3_params, X509.CertificateFormat format);
368                 public int export_pkcs3 (X509.CertificateFormat format, void* params_data, ref size_t params_data_size);
370                 [CCode (cname = "gnutls_dh_params_generate2")]
371                 public int generate (uint bits);
372         }
374         [Compact]
375         [CCode (cname = "struct gnutls_x509_privkey_int", free_function = "gnutls_rsa_params_deinit", lower_case_cprefix = "gnutls_rsa_params_")]
376         public class RSAParams {
377                 private static int init (RSAParams* dh_params);
378                 public static RSAParams create ()
379                 {
380                         RSAParams result = null;
381                         var ret = init (&result);
382                         if (ret != 0)
383                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
384                         return result;
385                 }
387                 private int cpy (RSAParams source);
389                 public int import_raw (/* const */ ref Datum m, /* const */ ref Datum e, /* const */ ref Datum d, /* const */ ref Datum p, /* const */ ref Datum q, /* const */ ref Datum u);
390                 public int export_raw (/* const */ ref Datum m, /* const */ ref Datum e, /* const */ ref Datum d, /* const */ ref Datum p, /* const */ ref Datum q, /* const */ ref Datum u, out uint bits);
391                 public int import_pkcs1 (/* const */ ref Datum pkcs1_params, X509.CertificateFormat format);
392                 public int export_pkcs1 (X509.CertificateFormat format, void* params_data, ref size_t params_data_size);
394                 public int generate2 (uint bits);
395         }
397         [Compact]
398         [CCode (cname = "struct gnutls_priority_st", free_function = "gnutls_priority_deinit")]
399         public class Priority {
400                 private static int init (Priority* self, string priority, out char* err_pos);
401                 public static Priority create (string priority, out ErrorCode err = null, out char* err_pos = null)
402                 {
403                         Priority result = null;
404                         var ret = init (&result, priority, out err_pos);
405                         if (&err != null)
406                                 err = (ErrorCode) ret;
407                         return result;
408                 }
409         }
411         [SimpleType]
412         [CCode (cname = "gnutls_datum_t")]
413         public struct Datum {
414                 public void* data;
415                 public uint size;
416         }
418         [CCode (cname = "gnutls_params_st")]
419         public struct Params {
420                 public ParamsType type;
421                 [CCode (cname = "params.dh")]
422                 public DHParams dh_params;
423                 [CCode (cname = "params.rsa_export")]
424                 public RSAParams rsa_params;
425                 public bool deinit;
426         }
428         [CCode (cname = "gnutls_params_function *")]
429         public static delegate int ParamsFunction (Session session, ParamsType type, Params params);
431         [CCode (cname = "gnutls_oprfi_callback_func", instance_pos = "1.2")]
432         public delegate int OprfiCallbackFunc (Session session,
433                                                [CCode (array_length_pos = "1.8", array_length_type = "size_t")] /* const */ uint8[] in_oprfi,
434                                                [CCode (array_length_pos = "1.8", array_length_type = "size_t")] uint8[] out_oprfi);
436         /* Supplemental data, RFC 4680. */
437         [CCode (cname = "gnutls_supplemental_data_format_type_t")]
438         public enum SupplementalDataFormatType {
439                 USER_MAPPING_DATA;
441                 [CCode (cname = "gnutls_supplemental_get_name")]
442                 public unowned string? get_name ();
443         }
445         [CCode (cname = "TLS_MASTER_SIZE")]
446         public const int TLS_MASTER_SIZE;
447         [CCode (cname = "TLS_RANDOM_SIZE")]
448         public const int TLS_RANDOM_SIZE;
450         [CCode (cname = "gnutls_db_store_func")]
451         public static delegate int DBStoreFunc (void* ptr, Datum key, Datum data);
452         [CCode (cname = "gnutls_db_remove_func")]
453         public static delegate int DBRemoveFunc (void* ptr, Datum key);
454         [CCode (cname = "gnutls_db_retr_func")]
455         public static delegate Datum DBRetrieveFunc (void* ptr, Datum key);
457         [CCode (cname = "gnutls_handshake_post_client_hello_func")]
458         public static delegate int HandshakePostClientHelloFunc (Session session);
460         // External signing callback.  Experimental.
461         [CCode (cname = "gnutls_sign_func", instance_pos = "1.9")]
462         public delegate int SignFunc (Session session, CertificateType cert_type, /* const */ ref Datum cert, /* const */ ref Datum hash, out Datum signature);
464         [CCode (cname = "gnutls_pull_func")]
465         public static delegate ssize_t PullFunc (void* transport_ptr, void* buffer, size_t count);
466         [CCode (cname = "gnutls_push_func")]
467         public static delegate ssize_t PushFunc (void* transport_ptr, void* buffer, size_t count);
469         [Compact]
470         [CCode (cname = "struct gnutls_session_int", free_function = "gnutls_deinit")]
471         public class Session {
472                 [CCode (cname = "gnutls_init")]
473                 private static int init (Session* session, int con_end);
475                 protected static Session create (int con_end)
476                 {
477                         Session result = null;
478                         var ret = init (&result, con_end);
479                         if (ret != 0)
480                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
481                         return result;
482                 }
484                 [CCode (cname = "gnutls_credentials_set")]
485                 public int set_credentials (CredentialsType type, void* cred);
486                 [CCode (cname = "gnutls_credentials_clear")]
487                 public void clear_credentials ();
489                 [CCode (cname = "gnutls_handshake")]
490                 public int handshake ();
491                 [CCode (cname = "gnutls_bye")]
492                 public int bye (CloseRequest how);
494                 [CCode (cname = "gnutls_session_is_resumed")]
495                 public bool is_resumed ();
497                 [CCode (cname = "gnutls_alert_get")]
498                 public AlertDescription get_last_alert ();
499                 [CCode (cname = "gnutls_alert_send")]
500                 public int send_alert (AlertLevel level, AlertDescription desc);
501                 [CCode (cname = "gnutls_alert_send_appropriate")]
502                 public int send_appropriate_alert (ErrorCode err);
504                 [CCode (cname = "gnutls_cipher_get")]
505                 public CipherAlgorithm get_cipher ();
506                 [CCode (cname = "gnutls_kx_get")]
507                 public KXAlgorithm get_kx ();
508                 [CCode (cname = "gnutls_mac_get")]
509                 public MacAlgorithm get_mac ();
510                 [CCode (cname = "gnutls_compression_get")]
511                 public CompressionMethod get_compression ();
512                 [CCode (cname = "gnutls_certificate_type_get")]
513                 public CertificateType get_certificate_type ();
514                 [CCode (cname = "gnutls_protocol_get_version")]
515                 public Protocol get_protocol_version ();
516                 [CCode (cname = "gnutls_record_get_max_size")]
517                 public size_t get_max_record_size ();
518                 [CCode (cname = "gnutls_dh_get_prime_bits")]
519                 public int get_dh_prime_bits ();
520                 [CCode (cname = "gnutls_dh_get_secret_bits")]
521                 public int get_dh_secret_bits ();
522                 [CCode (cname = "gnutls_dh_get_peers_public_bits")]
523                 public int get_peers_dh_public_bits ();
524                 [CCode (cname = "gnutls_dh_get_group")]
525                 public int get_dh_group (out Datum raw_gen, out Datum raw_prime);
526                 [CCode (cname = "gnutls_dh_get_pubkey")]
527                 public int get_dh_pubkey (out Datum raw_key);
528                 [CCode (cname = "gnutls_rsa_export_get_pubkey")]
529                 public int get_rsa_export_pubkey (out Datum exponent, out Datum modulus);
530                 [CCode (cname = "gnutls_rsa_export_get_modulus_bits")]
531                 public int get_rsa_export_modulus_bits ();
533                 [CCode (cname = "gnutls_handshake_set_private_extensions")]
534                 public void allow_private_extensions (bool allow);
535                 [CCode (cname = "gnutls_handshake_get_last_out")]
536                 public HandshakeDescription get_last_out_handshake ();
537                 [CCode (cname = "gnutls_handshake_get_last_in")]
538                 public HandshakeDescription get_last_in_handshake ();
540                 [CCode (cname = "gnutls_record_send")]
541                 public ssize_t send (void* buffer, size_t count);
542                 [CCode (cname = "gnutls_record_recv")]
543                 public ssize_t receive (void* buffer, size_t count);
545                 [CCode (cname = "gnutls_record_get_direction")]
546                 public int get_last_direction ();
548                 [CCode (cname = "gnutls_record_check_pending")]
549                 public size_t check_pending ();
551                 [CCode (cname = "gnutls_cipher_set_priority")]
552                 public int set_cipher_priority ([CCode (array_length = "false", array_null_terminated = "true")] CipherAlgorithm[] list);
553                 [CCode (cname = "gnutls_mac_set_priority")]
554                 public int set_mac_priority ([CCode (array_length = "false", array_null_terminated = "true")] MacAlgorithm[] list);
555                 [CCode (cname = "gnutls_compression_set_priority")]
556                 public int set_compression_priority ([CCode (array_length = "false", array_null_terminated = "true")] CompressionMethod[] list);
557                 [CCode (cname = "gnutls_kx_set_priority")]
558                 public int set_kx_priority ([CCode (array_length = "false", array_null_terminated = "true")] KXAlgorithm[] list);
559                 [CCode (cname = "gnutls_protocol_set_priority")]
560                 public int set_protocol_priority ([CCode (array_length = "false", array_null_terminated = "true")] Protocol[] list);
561                 [CCode (cname = "gnutls_certificate_type_set_priority")]
562                 public int set_certificate_type_priority ([CCode (array_length = "false", array_null_terminated = "true")] CertificateType[] list);
564                 [CCode (cname = "gnutls_priority_set")]
565                 public int set_priority (Priority priority);
566                 [CCode (cname = "gnutls_priority_set_direct")]
567                 public int set_priority_from_string (string priority, out char* err_pos = null);
568                 [CCode (cname = "gnutls_set_default_priority")]
569                 public int set_default_priority ();
570                 [CCode (cname = "gnutls_set_default_export_priority")]
571                 public int set_default_export_priority ();
573                 [CCode (cname = "GNUTLS_MAX_SESSION_ID")]
574                 public const int MAX_SESSION_ID;
576                 [CCode (cname = "gnutls_session_get_id")]
577                 public int get_id (void* session_id, ref size_t session_id_size);
579                 [CCode (cname = "gnutls_session_get_server_random")]
580                 public void* get_server_random ();
581                 [CCode (cname = "gnutls_session_get_client_random")]
582                 public void* get_client_random ();
583                 [CCode (cname = "gnutls_session_get_master_secret")]
584                 public void* get_master_secret ();
586                 [CCode (cname = "gnutls_transport_set_ptr")]
587                 public void set_transport_ptr (void* ptr);
588                 [CCode (cname = "gnutls_transport_set_ptr2")]
589                 public void set_transport_ptr2 (void* recv_ptr, void* send_ptr);
590                 [CCode (cname = "gnutls_transport_set_lowat")]
591                 public void set_lowat (int num);
592                 [CCode (cname = "gnutls_transport_set_push_function")]
593                 public void set_push_function (PushFunc func);
594                 [CCode (cname = "gnutls_transport_set_pull_function")]
595                 public void set_pull_function (PullFunc func);
597                 [CCode (cname = "gnutls_transport_set_errno")]
598                 public void set_errno (int err);
600                 [CCode (cname = "gnutls_session_set_ptr")]
601                 public void set_ptr (void* ptr);
602                 [CCode (cname = "gnutls_session_get_ptr")]
603                 public void* get_ptr ();
605                 [CCode (cname = "gnutls_auth_get_type")]
606                 public CredentialsType get_auth_type ();
607         //      [CCode (cname = "gnutls_auth_server_get_type")]
608         //      public CredentialsType get_server_auth_type ();
609         //      [CCode (cname = "gnutls_auth_client_get_type")]
610         //      public CredentialsType get_client_auth_type ();
612                 [CCode (cname = "gnutls_sign_callback_set")]
613                 public void set_sign_callback (SignFunc func);
614                 [CCode (cname = "gnutls_sign_callback_get")]
615                 public SignFunc get_sign_callback ();
617                 [CCode (cname = "gnutls_certificate_get_peers", array_length_type = "unsigned int")]
618                 public unowned Datum[]? get_peer_certificates ();
619                 [CCode (cname = "gnutls_certificate_get_ours")]
620                 public unowned Datum? get_our_certificate ();
622                 [CCode (cname = "gnutls_certificate_verify_peers2")]
623                 public int verify_peer_certificate (out CertificateStatus status);
624         }
626         [CCode (cname = "struct gnutls_session_int", lower_case_cprefix = "gnutls_", free_function = "gnutls_deinit")]
627         public class ClientSession: Session {
629                 public static ClientSession create ()
630                 {
631                         return (ClientSession) Session.create (2);
632                 }
634                 [CCode (cname = "gnutls_record_set_max_size")]
635                 public ssize_t set_max_record_size (size_t size);
637                 [CCode (cname = "gnutls_dh_set_prime_bits")]
638                 public void set_dh_prime_bits (uint bits);
640                 [CCode (cname = "gnutls_server_name_get")]
641                 public int get_server_name (void* data, out size_t data_length, out ServerNameType type, uint index);
643                 [CCode (cname = "gnutls_oprfi_enable_client")]
644                 public void enable_oprfi ([CCode (array_length_pos = "0.9", array_length_type = "size_t")] uint8[] data);
646                 [CCode (cname = "gnutls_session_set_data")]
647                 public int set_session_data (void* session_data, size_t session_data_size);
648                 [CCode (cname = "gnutls_session_get_data")]
649                 public int get_session_data (void* session_data, out size_t session_data_size);
650                 [CCode (cname = "gnutls_session_get_data2")]
651                 public int get_session_data2 (out Datum data);
653                 [CCode (cname = "gnutls_openpgp_send_cert")]
654                 public void set_openpgp_send_cert (bool fingerprint_only);
656                 [CCode (cname = "gnutls_psk_client_get_hint")]
657                 public unowned string get_psk_hint ();
659                 [CCode (cname = "gnutls_certificate_client_get_request_status")]
660                 public int get_certificate_request_status ();
661         }
663         [CCode (cname = "struct gnutls_session_int", lower_case_cprefix = "gnutls_", free_function = "gnutls_deinit")]
664         public class ServerSession: Session {
666                 public static ServerSession create ()
667                 {
668                         return (ServerSession) Session.create (1);
669                 }
671                 public int rehandshake ();
673                 [CCode (cname = "gnutls_session_enable_compatibility_mode")]
674                 public void enable_compatibility_mode ();
676                 [CCode (cname = "gnutls_record_disable_padding")]
677                 public void disable_record_padding ();
679                 [CCode (cname = "gnutls_server_name_set")]
680                 public int set_server_name (ServerNameType type, void* data, size_t data_length);
682                 [CCode (cname = "gnutls_oprfi_enable_server")]
683                 public void enable_oprfi (OprfiCallbackFunc cb);
685                 public void db_set_cache_expiration (int seconds);
686                 public void db_remove_session ();
687                 public void db_set_retrieve_function (DBRetrieveFunc func);
688                 public void db_set_remove_function (DBRemoveFunc func);
689                 public void db_set_store_function (DBStoreFunc func);
690                 public void db_set_ptr (void* ptr);
691                 public void* db_get_ptr ();
692                 public int db_check_entry (Datum session_entry);
694                 [CCode (cname = "gnutls_handshake_set_post_client_hello_function")]
695                 public void set_post_client_hello_function (HandshakePostClientHelloFunc func);
697                 [CCode (cname = "gnutls_handshake_set_max_packet_length")]
698                 public void set_max_handshake_packet_length (size_t max);
700                 [CCode (cname = "gnutls_certificate_server_set_request")]
701                 public void set_certificate_request (CertificateRequest req);
703                 [CCode (cname = "gnutls_certificate_send_x509_rdn_sequence")]
704                 public void disable_sending_x509_rdn_sequence (bool disable);
706                 [CCode (cname = "gnutls_psk_server_get_username")]
707                 public unowned string get_psk_username ();
709                 [CCode (cheader_filename = "gnutls/openpgp.h", cname = "gnutls_openpgp_set_recv_key_function")]
710                 public void set_openpgp_recv_key_function (OpenPGP.RecvKeyFunc func);
711         }
714         [Compact]
715         [CCode (cname = "struct gnutls_anon_server_credentials_st", free_function = "gnutls_anon_free_server_credentials")]
716         public class AnonServerCredentials
717         {
718                 [CCode (cname = "gnutls_anon_allocate_server_credentials")]
719                 private static int allocate (AnonServerCredentials* credentials);
720                 public static AnonServerCredentials create ()
721                 {
722                         AnonServerCredentials result = null;
723                         var ret = allocate (&result);
724                         if (ret != 0)
725                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
726                         return result;
727                 }
730                 [CCode (cname = "gnutls_anon_set_server_dh_params")]
731                 public void set_dh_params (DHParams dh_params);
733         //      [CCode (cname = "gnutls_anon_set_server_params_function")]
734         //      public void set_server_params_function (ParamsFunction func);
736                 [CCode (cname = "gnutls_anon_set_params_function")]
737                 public void set_params_function (ParamsFunction func);
738         }
740         [Compact]
741         [CCode (cname = "struct gnutls_anon_client_credentials_st", free_function = "gnutls_anon_free_client_credentials")]
742         public class AnonClientCredentials
743         {
744                 [CCode (cname = "gnutls_anon_allocate_client_credentials")]
745                 private static int allocate (AnonClientCredentials* credentials);
746                 public static AnonClientCredentials create ()
747                 {
748                         AnonClientCredentials result = null;
749                         var ret = allocate (&result);
750                         if (ret != 0)
751                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
752                         return result;
753                 }
754         }
756         [CCode (cheader_filename = "gnutls/x509.h", cprefix = "GNUTLS_")]
757         namespace X509
758         {
759                 // Some OIDs usually found in Distinguished names, or
760                 // in Subject Directory Attribute extensions.
762                 public const string OID_X520_COUNTRY_NAME;
763                 public const string OID_X520_ORGANIZATION_NAME;
764                 public const string OID_X520_ORGANIZATIONAL_UNIT_NAME;
765                 public const string OID_X520_COMMON_NAME;
766                 public const string OID_X520_LOCALITY_NAME;
767                 public const string OID_X520_STATE_OR_PROVINCE_NAME;
769                 public const string OID_X520_INITIALS;
770                 public const string OID_X520_GENERATION_QUALIFIER;
771                 public const string OID_X520_SURNAME;
772                 public const string OID_X520_GIVEN_NAME;
773                 public const string OID_X520_TITLE;
774                 public const string OID_X520_DN_QUALIFIER;
775                 public const string OID_X520_PSEUDONYM;
777                 public const string OID_LDAP_DC;
778                 public const string OID_LDAP_UID;
780                 // The following should not be included in DN.
782                 public const string OID_PKCS9_EMAIL;
784                 public const string OID_PKIX_DATE_OF_BIRTH;
785                 public const string OID_PKIX_PLACE_OF_BIRTH;
786                 public const string OID_PKIX_GENDER;
787                 public const string OID_PKIX_COUNTRY_OF_CITIZENSHIP;
788                 public const string OID_PKIX_COUNTRY_OF_RESIDENCE;
790                 // Key purpose Object Identifiers.
792                 public const string KP_TLS_WWW_SERVER;
793                 public const string KP_TLS_WWW_CLIENT;
794                 public const string KP_CODE_SIGNING;
795                 public const string KP_EMAIL_PROTECTION;
796                 public const string KP_TIME_STAMPING;
797                 public const string KP_OCSP_SIGNING;
798                 public const string KP_ANY;
801                 [CCode (cname = "gnutls_x509_crt_fmt_t", cprefix = "GNUTLS_X509_FMT_")]
802                 public enum CertificateFormat {
803                         DER,
804                         PEM
805                 }
807                 [Flags]
808                 [CCode (cname = "gnutls_certificate_import_flags", cprefix = "GNUTLS_X509_CRT_")]
809                 public enum CertificateImportFlags {
810                         /* Fail if the certificates in the buffer are more than the space
811                         * allocated for certificates. The error code will be
812                         * GNUTLS_E_SHORT_MEMORY_BUFFER.
813                         */
814                         LIST_IMPORT_FAIL_IF_EXCEED    // == 1
815                 }
817                 [Flags]
818                 [CCode (cname = "unsigned int", cprefix = "GNUTLS_CRL_REASON_")]
819                 public enum RevocationReasons {
820                         UNUSED,
821                         KEY_COMPROMISE,
822                         CA_COMPROMISE,
823                         AFFILIATION_CHANGED,
824                         SUPERSEEDED,
825                         CESSATION_OF_OPERATION,
826                         CERTIFICATE_HOLD,
827                         PRIVILEGE_WITHDRAWN,
828                         AA_COMPROMISE
829                 }
831                 [Flags]
832                 [CCode (cname = "gnutls_certificate_verify_flags", cprefix = "GNUTLS_VERIFY_")]
833                 public enum CertificateVerifyFlags
834                 {
835                         // If set a signer does not have to be a certificate authority. This
836                         // flag should normaly be disabled, unless you know what this means.
837                         DISABLE_CA_SIGN,
839                         // Allow only trusted CA certificates that have version 1.  This is
840                         // safer than GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT, and should be
841                         // used instead. That way only signers in your trusted list will be
842                         // allowed to have certificates of version 1.
843                         ALLOW_X509_V1_CA_CRT,
845                         // If a certificate is not signed by anyone trusted but exists in
846                         // the trusted CA list do not treat it as trusted.
847                         DO_NOT_ALLOW_SAME,
849                         // Allow CA certificates that have version 1 (both root and
850                         // intermediate). This might be dangerous since those haven't the
851                         // basicConstraints extension. Must be used in combination with
852                         // GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT.
853                         ALLOW_ANY_X509_V1_CA_CRT,
855                         // Allow certificates to be signed using the broken MD2 algorithm.
856                         ALLOW_SIGN_RSA_MD2,
858                         // Allow certificates to be signed using the broken MD5 algorithm.
859                         ALLOW_SIGN_RSA_MD5
860                 }
862                 [CCode (cname = "gnutls_x509_subject_alt_name_t")]
863                 public enum SubjectAltName {
864                         DNSNAME,
865                         RFC822NAME,
866                         URI,
867                         IPADDRESS,
868                         OTHERNAME,
869                         DN,
871                         OTHERNAME_XMPP
872                 }
874                 [Compact]
875                 [CCode (cname = "void", cprefix = "gnutls_x509_dn_", free_function = "gnutls_x509_dn_deinit")]
876                 public class DN
877                 {
878                         private static int init (DN* dn);
879                         public static DN create ()
880                         {
881                                 DN result = null;
882                                 var ret = init (&result);
883                                 if (ret != 0)
884                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
885                                 return result;
886                         }
888                         public int get_rdn_ava (int irdn, int iava, out unowned Ava ava);
890                         public int import (ref Datum data);
891                         public int export (CertificateFormat format, void* output, ref size_t output_size);
893                 }
895                 // RDN handling.
896                 public int rdn_get (ref Datum idn, char* buf, ref size_t buf_size);
897                 public int rdn_get_oid (ref Datum idn, int index, void* buf, ref size_t buf_size);
898                 public int rdn_get_by_oid (ref Datum idn, string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
900                 [SimpleType]
901                 [CCode (cname = "gnutls_x509_ava_st")]
902                 public struct Ava
903                 {
904                         [CCode (cname = "oid.data", array_length_name = "oid.size")]
905                         uint8[] oid;
906                         [CCode (cname = "value.data", array_length_name = "value.size")]
907                         uint8[] value;
908                         ulong value_tag;
909                 }
911                 [Compact]
912                 [CCode (cname = "struct gnutls_x509_crt_int", cprefix = "gnutls_x509_crt_", free_function = "gnutls_x509_crt_deinit ")]
913                 public class Certificate
914                 {
915                         private static int init (Certificate* cert);
917                         public static Certificate create ()
918                         {
919                                 Certificate result = null;
920                                 var ret = init (&result);
921                                 if (ret != 0)
922                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
923                                 return result;
924                         }
926                         public int import (ref Datum data, CertificateFormat format);
927                         public int export (CertificateFormat format, void* output, ref size_t output_size);
929                         public static int list_import ([CCode (array_length = "false")] Certificate[]? certs,
930                                                        ref uint cert_max, ref Datum data,
931                                                        CertificateFormat format, bool fail_if_exceed);
935                         public int get_issuer_dn (char* buf, ref size_t buf_size);
936                         public int get_issuer_dn_oid (int index, void* oid, ref size_t oid_size);
937                         public int get_issuer_dn_by_oid (string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
939                         public int get_dn (char* buf, ref size_t buf_size);
940                         public int get_dn_oid (int index, void* oid, ref size_t oid_size);
941                         public int get_dn_by_oid (string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
944                         public int get_subject (out DN dn);
945                         public int get_issuer (out DN dn);
947                         public bool check_hostname (string hostname);
949                         public SignAlgorithm get_signature_algorithm ();
951                         public int get_signature (char* sig, ref size_t sig_size);
953                         public int get_version ();
955                         public int get_key_id (uint flags, uchar* output, ref size_t output_size);
957                         public int set_authority_key_id (void* id, size_t id_size);
958                         public int get_authority_key_id (void* ret, ref size_t ret_size, out bool critical);
960                         public int get_subject_key_id (void* ret, ref size_t ret_size, out bool critical);
962                         public int get_crl_dist_points (uint seq, void* ret, ref size_t ret_size, out RevocationReasons reason_flags, out bool critical);
963                         public int set_crl_dist_points (SubjectAltName type, void* data_string, RevocationReasons reason_flags);
964                         public int cpy_crl_dist_points (Certificate source);
966                         public time_t get_activation_time ();
967                         public time_t get_expiration_time ();
969                         public int get_serial (void* result, ref size_t result_size);
971                         public PKAlgorithm get_pk_algorithm (out uint bits);
972                         public int get_pk_rsa_raw (out Datum modulus, out Datum exponent);
973                         public int get_pk_dsa_raw (out Datum p, out Datum q, out Datum g, out Datum y);
975                         public int get_subject_alt_name (uint seq, void* ret, ref size_t ret_size, out bool critical);
976                         public int get_subject_alt_name2 (uint seq, void* ret, ref size_t ret_size, out SubjectAltName ret_type, out bool critical);
978                         public int get_subject_alt_othername_oid (uint seq, void* ret, ref size_t ret_size);
980                         public int get_ca_status (out bool critical);
982                         public int get_basic_constraints (out bool critical, out int ca, out int pathlen);
984                         public int get_key_usage (out KeyUsage key_usage, out bool critical);
985                         public int set_key_usage (KeyUsage usage);
987                         public int get_proxy (out bool critical, out int pathlen, [CCode (array_length = "false")] out char[] policyLanguage, out char[] policy);
989                         public bool dn_oid_known (string oid);
991                         public int get_extension_oid (int index, void* oid, ref size_t oid_size);
992                         public int get_extension_by_oid (string oid, int index, void* buf, ref size_t buf_size, out bool critical);
994                         public int get_extension_info (int index, void* oid, ref size_t oid_size, out bool critical);
995                         public int get_extension_data (int index, void* data, ref size_t data_size);
997                         public int set_extension_by_oid (string oid, void* buf, size_t buf_size, bool critical);
998                         public int set_dn_by_oid (string oid, uint raw_flag, void* name, uint name_size);
999                         public int set_issuer_dn_by_oid (string oid, uint raw_flag, void* name, uint name_size);
1000                         public int set_version (uint version);
1001                         public int set_key (PrivateKey key);
1002                         public int set_ca_status (uint ca);
1003                         public int set_basic_constraints (uint ca, int pathLenConstraint);
1004                         public int set_subject_alternative_name (SubjectAltName type, string data_string);
1006                         public int sign (Certificate issuer, PrivateKey issuer_key);
1007                         public int sign2 (Certificate issuer, PrivateKey issuer_key, DigestAlgorithm alg, uint flags);
1009                         public int set_activation_time (time_t act_time);
1010                         public int set_expiration_time (time_t exp_time);
1011                         public int set_serial (void* serial, size_t serial_size);
1013                         public int set_subject_key_id (void* id, size_t id_size);
1014                         public int set_proxy_dn (Certificate eecrt, uint raw_flag, void* name, uint name_size);
1015                         public int set_proxy (int pathLenConstraint, string policyLanguage, [CCode (array_length_type = "size_t")] uint8[] policy);
1017                         public int print (CertificatePrintFormats format, out Datum output);
1019                         public int get_raw_issuer_dn (out unowned Datum start);
1020                         public int get_raw_dn (out unowned Datum start);
1022                         public int verify_data (uint flags, ref Datum data, ref Datum signature);
1024                         private int set_crq (CertificateRequest crq);
1026                         // verification
1028                         public int check_issuer (Certificate issuer);
1029                         public static int list_verify (Certificate[] cert_list, Certificate[] CA_list, Certificate[] CLR_list, CertificateVerifyFlags flags, out CertificateStatus verify);
1030                         public int verify (Certificate[] CA_list, CertificateVerifyFlags flags, out CertificateStatus verify);
1031                         public int check_revocation (CRL[] crl_list);
1032                         public int get_fingerprint (DigestAlgorithm algo, void* buf, ref size_t buf_size);
1033                         public int get_key_purpose_oid (int index, void* oid, ref size_t oid_size, out bool critical);
1034                         public int set_key_purpose_oid (string oid, bool critical);
1035                 }
1037                 [Compact]
1038                 [CCode (cname = "struct gnutls_x509_crl_int", free_function = "gnutls_x509_crl_deinit", cprefix = "gnutls_x509_crl_")]
1039                 public class CRL
1040                 {
1041                         private static int init (CRL* crl);
1043                         public static CRL create ()
1044                         {
1045                                 CRL result = null;
1046                                 var ret = init (&result);
1047                                 if (ret != 0)
1048                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1049                                 return result;
1050                         }
1052                         public int import (ref Datum data, CertificateFormat format);
1053                         public int export (CertificateFormat format, void* output, ref size_t output_size);
1055                         public int get_issuer_dn (char* buf, ref size_t buf_size);
1056                         public int get_issuer_dn_by_oid (string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
1058                         public int get_dn_oid (int index, void* oid, ref size_t oid_size);
1060                         public int get_signature_algorithm ();
1061                         public int get_signature (char* sig, ref size_t sig_size);
1062                         public int get_version ();
1064                         public time_t get_this_update ();
1065                         public time_t get_next_update ();
1067                         public int get_crt_count ();
1068                         public int get_crt_serial (int index, uchar* serial, ref size_t serial_size, out time_t t);
1070                         // aliases for previous two
1071                         public int get_certificate_count ();
1072                         public int get_certificate (int index, uchar* serial, ref size_t serial_size, out time_t t);
1074                         public int check_issuer (Certificate issuer);
1076                         public int verify (Certificate[] ca_list, CertificateVerifyFlags flags, out CertificateStatus verify);
1078                         // CRL writing
1080                         public int set_version (uint version);
1081                         public int sign (Certificate issuer, PrivateKey issuer_key);
1082                         public int sign2 (Certificate issuer, PrivateKey issuer_key, DigestAlgorithm algo, uint flags);
1084                         public int set_this_update (time_t act_time);
1085                         public int set_next_update (time_t exp_time);
1087                         public int set_crt_serial (void* serial, size_t serial_size, time_t revocation_time);
1088                         public int set_crt (Certificate crt, time_t revocation_time);
1090                         public int print (CertificatePrintFormats format, out Datum output);
1091                 }
1093                 [Compact]
1094                 [CCode (cname = "struct gnutls_pkcs7_int", cprefix = "gnutls_pkcs7_", free_function = "gnutls_pkcs7_deinit")]
1095                 public class PKCS7
1096                 {
1097                         private static int init (PKCS7* pkcs7);
1098                         public static PKCS7 create ()
1099                         {
1100                                 PKCS7 result = null;
1101                                 var ret = init (&result);
1102                                 if (ret != 0)
1103                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1104                                 return result;
1105                         }
1107                         public int import (ref Datum data, CertificateFormat format);
1108                         public int export (CertificateFormat format, void* output, ref size_t output_size);
1110                         public int get_crt_count ();
1111                         public int get_crt_raw (int index, void* certificate, ref size_t certificate_size);
1112                         public int set_crt_raw (ref Datum crt);
1113                         public int set_crt (Certificate crt);
1114                         public int delete_crt (int index);
1116                         public int get_crl_count ();
1117                         public int get_crl_raw (int index, void* crl, ref size_t crl_size);
1118                         public int set_crl_raw (ref Datum crt);
1119                         public int set_crl (CRL crl);
1120                         public int delete_crl (int index);
1121                 }
1123                 // Flags for the gnutls_x509_privkey_export_pkcs8() function.
1124                 [Flags]
1125                 [CCode (cname = "gnutls_pkcs_encrypt_flags_t", cprefix = "GNUTLS_PKCS_")]
1126                 public enum PKCSEncryptFlags {
1127                         PLAIN,
1128                         USE_PKCS12_3DES,
1129                         USE_PKCS12_ARCFOUR,
1130                         USE_PKCS12_RC2_40,
1131                         USE_PBES2_3DES
1132                 }
1134                 [Compact]
1135                 [CCode (cname = "struct gnutls_x509_privkey_int", cprefix = "gnutls_x509_privkey_", free_function = "gnutls_x509_privkey_deinit")]
1136                 public class PrivateKey
1137                 {
1138                         private static int init (PrivateKey* key);
1139                         public static PrivateKey create ()
1140                         {
1141                                 PrivateKey result = null;
1142                                 var ret = init (&result);
1143                                 if (ret != 0)
1144                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1145                                 return result;
1146                         }
1148                         public int cpy (PrivateKey source);
1150                         public int import (ref Datum data, CertificateFormat format);
1151                         public int import_pkcs8 (ref Datum data, CertificateFormat format, string? password, PKCSEncryptFlags flags);
1152                         public int import_rsa_raw (ref Datum m, ref Datum e, ref Datum d, ref Datum p, ref Datum q, ref Datum u);
1153                         public int import_dsa_raw (ref Datum p, ref Datum q, ref Datum g, ref Datum y, ref Datum x);
1155                         public int export (CertificateFormat format, void* output, ref size_t output_size);
1156                         public int export_pkcs8 (CertificateFormat format, string password, PKCSEncryptFlags flags, void* output, ref size_t output_size);
1157                         public int export_rsa_raw (out Datum m, out Datum e, out Datum d, out Datum p, out Datum q, out Datum u);
1158                         public int export_dsa_raw (out Datum p, out Datum q, out Datum g, out Datum y, out Datum x);
1160                         public int fix ();
1161                         public int generate (PKAlgorithm algo, uint bits, uint flags = 0);
1163                         public int get_pk_algorithm ();
1164                         public int get_key_id (uint flags, uchar* output, ref size_t output_size);
1166                         // Signing stuff
1168                         public int sign_data (DigestAlgorithm digest, uint flags, ref Datum data, void* signature, ref size_t signature_size);
1169                         public int verify_data (uint flags, ref Datum data, ref Datum signature);
1170                         public int sign_hash (ref Datum hash, out Datum signature);
1171                 }
1173                 [Compact]
1174                 [CCode (cname = "struct gnutls_x509_crq_int", cprefix = "gnutls_x509_crq_", free_function = "gnutls_x509_crq_deinit")]
1175                 public class CertificateRequest
1176                 {
1177                         private static int init (CertificateRequest* request);
1178                         public static CertificateRequest create ()
1179                         {
1180                                 CertificateRequest result = null;
1181                                 var ret = init (&result);
1182                                 if (ret != 0)
1183                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1184                                 return result;
1185                         }
1187                         public int import (ref Datum data, CertificateFormat format);
1188                         public int export (CertificateFormat format, void* output, ref size_t output_size);
1190                         public int get_pk_algorithm (out uint bits);
1191                         public int get_dn (char* buf, ref size_t buf_size);
1192                         public int get_dn_oid (int index, void* oid, ref size_t oid_size);
1193                         public int get_dn_by_oid (string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
1194                         public int set_dn_by_oid (string oid, uint raw_flag, void* name, uint name_size);
1196                         public int set_version (uint version);
1198                         public int set_key (PrivateKey key);
1200                         public int sign (PrivateKey key);
1201                         public int sign2 (PrivateKey key, DigestAlgorithm algo, uint flags);
1203                         public int set_challenge_password (string pass);
1204                         public int get_challenge_password (char* pass, ref size_t pass_size);
1206                         public int set_attribute_by_oid (string oid, void* buf, size_t buf_size);
1207                         public int get_attribute_by_oid (string oid, int index, void* buf, ref size_t buf_size);
1208                 }
1210                 [Compact]
1211                 [CCode (cheader_filename = "gnutls/pkcs12.h", cname = "struct gnutls_pkcs12_int", cprefix = "gnutls_pkcs12_", free_function = "gnutls_pkcs12_deinit")]
1212                 public class PKCS12
1213                 {
1214                         private static int init (PKCS12* request);
1215                         public static PKCS12 create ()
1216                         {
1217                                 PKCS12 result = null;
1218                                 var ret = init (&result);
1219                                 if (ret != 0)
1220                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1221                                 return result;
1222                         }
1224                         public int import (ref Datum data, CertificateFormat format, uint flags);
1225                         public int export (CertificateFormat format, void* output, ref size_t output_size);
1227                         public int get_bag (int index, PKCS12Bag bag);
1228                         public int set_bag (PKCS12Bag bag);
1230                         public int generate_mac (string pass);
1231                         public int verify_mac (string pass);
1232                 }
1234                 [CCode (cheader_filename = "gnutls/pkcs12.h", cname = "gnutls_pkcs12_bag_type_t", cprefix = "GNUTLS_BAG_")]
1235                 public enum PKCS12BagType {
1236                         EMPTY,
1237                         PKCS8_ENCRYPTED_KEY,
1238                         PKCS8_KEY,
1239                         CERTIFICATE,
1240                         CRL,
1241                         ENCRYPTED,
1242                         UNKNOWN
1243                 }
1245                 [Compact]
1246                 [CCode (cheader_filename = "gnutls/pkcs12.h", cname = "struct gnutls_pkcs12_bag_int", cprefix = "gnutls_pkcs12_bag_", free_function = "gnutls_pkcs12_bag_deinit")]
1247                 public class PKCS12Bag {
1248                         private static int init (PKCS12Bag* request);
1249                         public static PKCS12Bag create ()
1250                         {
1251                                 PKCS12Bag result = null;
1252                                 var ret = init (&result);
1253                                 if (ret != 0)
1254                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1255                                 return result;
1256                         }
1258                         public int decrypt (string pass);
1259                         public int encrypt (string pass, PKCSEncryptFlags flags);
1261                         public PKCS12BagType get_type (int index);
1262                         public int get_data (int index, out Datum data);
1263                         public int set_data (PKCS12BagType type, ref Datum data);
1264                         public int set_crl (CRL crl);
1265                         public int set_crt (Certificate crt);
1267                         public int get_count ();
1269                         public int get_key_id (int index, out Datum id);
1270                         public int set_key_id (int index, ref Datum id);
1272                         public int get_friendly_name (int index, out unowned string name);
1273                         public int set_friendly_name (int index, string name);
1274                 }
1275         }
1277         [CCode (cheader_filename = "gnutls/openpgp.h")]
1278         namespace OpenPGP
1279         {
1280                 /**
1281                 * gnutls_openpgp_recv_key_func - Callback prototype to get OpenPGP keys
1282                 * @session: a TLS session
1283                 * @keyfpr: key fingerprint
1284                 * @keyfpr_length: length of key fingerprint
1285                 * @key: output key.
1286                 *
1287                 * A callback of this type is used to retrieve OpenPGP keys.  Only
1288                 * useful on the server, and will only be used if the peer send a key
1289                 * fingerprint instead of a full key.  See also
1290                 * gnutls_openpgp_set_recv_key_function().
1291                 *
1292                 */
1293                 public static delegate int RecvKeyFunc (Session session, uint8[] keyfpr, out Datum key);
1295                 [CCode (cname = "gnutls_openpgp_crt_fmt_t", cprefix = "GNUTLS_OPENPGP_FMT_")]
1296                 public enum CertificateFormat {
1297                         RAW,
1298                         BASE64
1299                 }
1301                 [Compact]
1302                 [CCode (cname = "struct gnutls_openpgp_crt_int", cprefix = "gnutls_openpgp_crt_", free_function = "gnutls_openpgp_crt_deinit")]
1303                 public class Certificate
1304                 {
1305                         private static int init (Certificate* crt);
1306                         public static Certificate create ()
1307                         {
1308                                 Certificate result = null;
1309                                 var ret = init (&result);
1310                                 if (ret != 0)
1311                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1312                                 return result;
1313                         }
1315                         public int import (ref Datum data, CertificateFormat format);
1316                         public int export (CertificateFormat format, void* output, ref size_t output_size);
1318                         public int print (CertificatePrintFormats format, out Datum output);
1320                         public int get_key_usage (out KeyUsage key_usage);
1321                         public int get_fingerprint (void* fpr, ref size_t fpr_size);
1322                         public int get_subkey_fingerprint (uint index, void* fpr, ref size_t fpr_size);
1324                         public int get_name (int index, char* buf, ref size_t buf_size);
1326                         public PKAlgorithm get_pk_algorithm (out uint bits);
1328                         public int get_version ();
1330                         public time_t get_creation_time ();
1331                         public time_t get_expiration_time ();
1333                         // keyid is 8 bytes
1334                         public int get_key_id (uchar* keyid);
1336                         public int check_hostname (string hostname);
1338                         public int get_revoked_status ();
1340                         public int get_subkey_count ();
1341                         public int get_subkey_idx (/*const*/ uchar* keyid);
1342                         public int get_subkey_revoked_status (uint idx);
1344                         public PKAlgorithm get_subkey_pk_algorithm (uint idx, out uint bits);
1346                         public time_t get_subkey_creation_time (uint idx);
1347                         public time_t get_subkey_expiration_time (uint idx);
1349                         public int get_subkey_id (uint idx, uchar* keyid);
1350                         public int get_subkey_usage (uint idx, out KeyUsage key_usage);
1352                         public int get_pk_dsa_raw (out Datum p, out Datum q, out Datum g, out Datum y);
1353                         public int get_pk_rsa_raw (out Datum m, out Datum e);
1355                         public int get_subkey_pk_dsa_raw (uint index, out Datum p, out Datum q, out Datum g, out Datum y);
1356                         public int get_subkey_pk_rsa_raw (uint index, out Datum m, out Datum e);
1358                         public int get_preferred_key_id (uchar* keyid);
1359                         public int set_preferred_key_id (/* const */ uchar* keyid);
1361                         public int verify_ring (Keyring keyring, uint flags, out CertificateStatus verify);
1362                         public int verify_self (uint flags, out CertificateStatus verify);
1363                 }
1365                 [Compact]
1366                 [CCode (cname = "struct gnutls_openpgp_privkey_int", cprefix = "gnutls_openpgp_privkey_", free_function = "gnutls_openpgp_privkey_deinit")]
1367                 public class PrivateKey
1368                 {
1369                         private static int init (PrivateKey* key);
1370                         public static PrivateKey create ()
1371                         {
1372                                 PrivateKey result = null;
1373                                 var ret = init (&result);
1374                                 if (ret != 0)
1375                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1376                                 return result;
1377                         }
1379                         public PKAlgorithm get_pk_algorithm (out uint bits);
1381                         public int import (ref Datum data, CertificateFormat format, string pass, uint flags);
1382                         public int export (CertificateFormat format, string password, uint flags, void* output, ref size_t output_size);
1384                         public int sign_hash (ref Datum hash, out Datum signature);
1385                         public int get_fingerprint (void* fpr, ref size_t fpr_size);
1386                         public int get_subkey_fingerprint (uint idx, void* fpr, ref size_t fpr_size);
1388                         public int get_key_id (uchar* keyid);
1389                         public int get_subkey_count ();
1390                         public int get_subkey_idx (/*const*/ uchar* keyid);
1392                         public int get_subkey_revoked_status (uint index);
1393                         public int get_revoked_status ();
1395                         public PKAlgorithm get_subkey_pk_algorithm (uint idx, out uint bits);
1397                         public time_t get_subkey_expiration_time (uint idx);
1398                         public time_t get_subkey_creation_time (uint idx);
1400                         public int get_subkey_id (uint idx, uchar* keyid);
1402                         public int export_subkey_dsa_raw (uint idx, out Datum p, out Datum q, out Datum g, out Datum y, out Datum x);
1403                         public int export_subkey_rsa_raw (uint idx, out Datum m, out Datum e, out Datum d, out Datum p, out Datum q, out Datum u);
1405                         public int export_dsa_raw (out Datum p, out Datum q, out Datum g, out Datum y, out Datum x);
1406                         public int export_rsa_raw (out Datum m, out Datum e, out Datum d, out Datum p, out Datum q, out Datum u);
1408                         public int set_preferred_key_id (/*const*/ uchar* keyid);
1409                         public int get_preferred_key_id (uchar* keyid);
1411                         public int get_auth_subkey (uchar* keyid, uint flag);
1412                 }
1414                 [Compact]
1415                 [CCode (cname = "struct gnutls_openpgp_keyring_int", cprefix = "gnutls_openpgp_keyring_", free_function = "gnutls_openpgp_keyring_deinit")]
1416                 public class Keyring
1417                 {
1418                         private static int init (Keyring* keyring);
1419                         public static Keyring create ()
1420                         {
1421                                 Keyring result = null;
1422                                 var ret = init (&result);
1423                                 if (ret != 0)
1424                                         GLib.error ("%s", ((ErrorCode)ret).to_string ());
1425                                 return result;
1426                         }
1428                         public int import (ref Datum data, CertificateFormat format);
1429                         public int check_id (/*const*/ uchar* keyid, uint flags);
1431                         public int get_crt_count ();
1432                         public int get_crt (uint index, out Certificate cert);
1433                 }
1434         }
1438         [CCode (cname = "gnutls_certificate_client_retrieve_function *")]
1439         public static delegate int ClientCertificateRetrieveFunction (Session session, Datum[] req_ca_rdn, PKAlgorithm[] pk_algos, out RetrStruct st);
1440         [CCode (cname = "gnutls_certificate_server_retrieve_function *")]
1441         public static delegate int ServerCertificateRetrieveFunction (Session session, out RetrStruct st);
1443         [Compact]
1444         [CCode (cname = "struct gnutls_certificate_credentials_st",
1445                 free_function = "gnutls_certificate_free_credentials",
1446                 cprefix = "gnutls_certificate_")]
1447         public class CertificateCredentials
1448         {
1449                 [CCode (cname = "gnutls_certificate_allocate_credentials")]
1450                 private static int allocate (CertificateCredentials* credentials);
1451                 public static CertificateCredentials create ()
1452                 {
1453                         CertificateCredentials result = null;
1454                         var ret = allocate (&result);
1455                         if (ret != 0)
1456                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
1457                         return result;
1458                 }
1460                 public void free_keys ();
1461                 public void free_cas  ();
1462                 public void free_ca_names ();
1463                 public void free_crls ();
1465                 public void set_dh_params (DHParams dh_params);
1466                 public void set_rsa_export_params (RSAParams rsa_params);
1467                 public void set_verify_flags (X509.CertificateVerifyFlags flags);
1468                 public void set_verify_limits (uint max_bits, uint max_depth);
1470                 public int set_x509_trust (X509.Certificate[] ca_list);
1471                 public int set_x509_trust_file (string cafile, X509.CertificateFormat type);
1472                 public int set_x509_trust_mem (/* const */ ref Datum cadata, X509.CertificateFormat type);
1474                 public int set_x509_crl (X509.CRL[] crl_list);
1475                 public int set_x509_crl_file (string crlfile, X509.CertificateFormat type);
1476                 public int set_x509_crl_mem (/* const */ ref Datum crldata, X509.CertificateFormat type);
1478                 public int set_x509_key (X509.Certificate[] cert_list, X509.PrivateKey key);
1479                 public int set_x509_key_file (string certfile, string keyfile, X509.CertificateFormat type);
1480                 public int set_x509_key_mem (/* const */ ref Datum certdata, /* const */ ref Datum keydata, X509.CertificateFormat type);
1482                 public int set_x509_simple_pkcs12_file (string pkcs12file, X509.CertificateFormat type, string? password = null);
1484                 public void get_x509_cas ([CCode (array_length_type = "unsigned int")] out unowned X509.Certificate[] x509_ca_list);
1485                 public void get_x509_crls ([CCode (array_length_type = "unsigned int")] out unowned X509.CRL[] x509_crl_list);
1488                 [CCode (cname = "gnutls_certificate_client_set_retrieve_function")]
1489                 public void set_client_certificate_retrieve_function (ClientCertificateRetrieveFunction func);
1490                 [CCode (cname = "gnutls_certificate_server_set_retrieve_function")]
1491                 public void set_server_certificate_retrieve_function (ServerCertificateRetrieveFunction func);
1493                 [CCode (cname = "gnutls_certificate_set_params_function")]
1494                 public void set_params_function (ParamsFunction func);
1496                 // OpenPGP stuff
1498                 public int set_openpgp_key (OpenPGP.Certificate key, OpenPGP.PrivateKey pkey);
1500                 public int set_openpgp_key_file (string certfile, string keyfile, OpenPGP.CertificateFormat format);
1501                 public int set_openpgp_key_mem (ref Datum cert, ref Datum key, OpenPGP.CertificateFormat format);
1502                 public int set_openpgp_key_file2 (string certfile, string keyfile, string keyid, OpenPGP.CertificateFormat format);
1503                 public int set_openpgp_key_mem2 (ref Datum cert, ref Datum key, string keyid, OpenPGP.CertificateFormat format);
1505                 public int set_openpgp_keyring_mem (uchar* data, size_t data_size, OpenPGP.CertificateFormat format);
1506                 public int set_openpgp_keyring_file (string file, OpenPGP.CertificateFormat format);
1508                 public void get_openpgp_keyring (out unowned OpenPGP.Keyring keyring);
1509         }
1511         [CCode (cname = "gnutls_malloc")]
1512         public void* malloc (size_t size);
1513         [CCode (cname = "gnutls_secure_malloc")]
1514         public void* secure_malloc (size_t size);
1515         [CCode (cname = "gnutls_realloc")]
1516         public void* realloc (void* ptr, size_t new_size);
1517         [CCode (cname = "gnutls_calloc")]
1518         public void* calloc (size_t count, size_t block_size);
1519         [CCode (cname = "gnutls_free")]
1520         public void free (void* ptr);
1522         [CCode (cname = "gnutls_free")]
1523         public void free_data ([CCode (array_length = false)] owned uint[] data);
1525         [CCode (cname = "gnutls_strdup")]
1526         public string strdup (string str);
1528         [CCode (cname = "gnutls_alloc_function")]
1529         public static delegate void* AllocFunction (size_t size);
1530         [CCode (cname = "gnutls_calloc_function")]
1531         public static delegate void* CallocFunction (size_t count, size_t block_size);
1532         [CCode (cname = "gnutls_is_secure_function")]
1533         public static delegate int IsSecureFunction (void* ptr);
1534         [CCode (cname = "gnutls_free_function")]
1535         public static delegate void FreeFunction (void* ptr);
1536         [CCode (cname = "gnutls_realloc_function")]
1537         public static delegate void* ReallocFunction (void* ptr, size_t new_size);
1539         public int global_init ();
1540         public void global_deinit ();
1542         [CCode (cname = "gnutls_global_set_mem_functions")]
1543         public void set_mem_functions (AllocFunction alloc_func, AllocFunction secure_alloc_func,
1544                                        IsSecureFunction is_secure_func, ReallocFunction realloc_func,
1545                                        FreeFunction free_func);
1547         [CCode (cname = "gnutls_log_func")]
1548         public static delegate void LogFunc (int level, string msg);
1549         [CCode (cname = "gnutls_global_set_log_function")]
1550         public void set_log_function (LogFunc func);
1551         [CCode (cname = "gnutls_global_set_log_level")]
1552         public void set_log_level (int level);
1554         [CCode (cname = "gnutls_transport_set_global_errno")]
1555         public void set_global_errno (int err);
1557 // SRP stuff
1559         [CCode (cname = "gnutls_srp_server_credentials_function *")]
1560         public static delegate int SRPServerCredentialsFunction (Session session, string username,
1561                                                                  out Datum salt, out Datum verifier,
1562                                                                  out Datum generator, out Datum prime);
1564         [Compact]
1565         [CCode (cname = "struct gnutls_srp_server_credentials_st", free_function = "gnutls_srp_free_server_credentials")]
1566         public class SRPServerCredentials
1567         {
1568                 [CCode (cname = "gnutls_srp_allocate_server_credentials")]
1569                 private static int allocate (SRPServerCredentials* sc);
1570                 public static SRPServerCredentials create ()
1571                 {
1572                         SRPServerCredentials result = null;
1573                         var ret = allocate (&result);
1574                         if (ret != 0)
1575                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
1576                         return result;
1577                 }
1579                 [CCode (cname = "gnutls_srp_set_server_credentials_file")]
1580                 public int set_credentials_file (string password_file, string password_conf_file);
1582                 [CCode (cname = "gnutls_srp_server_get_username")]
1583                 public string get_username ();
1585                 [CCode (cname = "gnutls_srp_set_server_credentials_function")]
1586                 public void set_credentials_function (SRPServerCredentialsFunction func);
1587         }
1589         [CCode (cname = "gnutls_srp_client_credentials_function *")]
1590         public static delegate int SRPClientCredentialsFunction (Session session, out string username, out string password);
1592         [Compact]
1593         [CCode (cname = "struct gnutls_srp_client_credentials_st", free_function = "gnutls_srp_free_client_credentials")]
1594         public class SRPClientCredentials
1595         {
1596                 [CCode (cname = "gnutls_srp_allocate_client_credentials")]
1597                 private static int allocate (SRPClientCredentials* sc);
1598                 public static SRPClientCredentials create ()
1599                 {
1600                         SRPClientCredentials result = null;
1601                         var ret = allocate (&result);
1602                         if (ret != 0)
1603                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
1604                         return result;
1605                 }
1607                 [CCode (cname = "gnutls_srp_set_client_credentials")]
1608                 public int set_credentials (string username, string password);
1610                 [CCode (cname = "gnutls_srp_set_client_credentials_function")]
1611                 public void set_credentials_function (SRPClientCredentialsFunction func);
1612         }
1614         //  extern int gnutls_srp_verifier (const char *username,
1615         //                        const char *password,
1616         //                        const gnutls_datum_t * salt,
1617         //                        const gnutls_datum_t * generator,
1618         //                        const gnutls_datum_t * prime,
1619         //                        gnutls_datum_t * res);
1621         public int srp_verifier (string username, string password, /* const */ ref Datum salt, /* const */ ref Datum generator, /* const */ ref Datum prime, out Datum result);
1623         // The static parameters defined in draft-ietf-tls-srp-05
1624         // Those should be used as input to gnutls_srp_verifier().
1626         public const Datum srp_2048_group_prime;
1627         public const Datum srp_2048_group_generator;
1629         public const Datum srp_1536_group_prime;
1630         public const Datum srp_1536_group_generator;
1632         public const Datum srp_1024_group_prime;
1633         public const Datum srp_1024_group_generator;
1635         public int srp_base64_encode (/* const */ ref Datum data, [CCode (array_length = "false")] char[] result, ref size_t result_size);
1636         public int srp_base64_encode_alloc (/* const */ ref Datum data, out Datum result);
1638         public int srp_base64_decode (/* const */ ref Datum b64_data, [CCode (array_length = false)] uint8[] result, ref size_t result_size);
1639         public int srp_base64_decode_alloc (/* const */ ref Datum b64_data, out Datum result);
1646 // PSK stuff
1648         [CCode (cname = "gnutls_psk_key_flags", cprefix = "GNUTLS_PSK_KEY_")]
1649         public enum PSKKeyFlags
1650         {
1651                 RAW,
1652                 HEX
1653         }
1655         [CCode (cname = "gnutls_psk_server_credentials_function *")]
1656         public static delegate int PSKServerCredentialsFunction (Session session, string username, /* const */ ref Datum key);
1658         [Compact]
1659         [CCode (cname = "struct gnutls_psk_server_credentials_st", free_function = "gnutls_psk_free_server_credentials")]
1660         public class PSKServerCredentials
1661         {
1662                 [CCode (cname = "gnutls_psk_allocate_server_credentials")]
1663                 private static int allocate (PSKServerCredentials* sc);
1664                 public static PSKServerCredentials create ()
1665                 {
1666                         PSKServerCredentials result = null;
1667                         var ret = allocate (&result);
1668                         if (ret != 0)
1669                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
1670                         return result;
1671                 }
1673                 [CCode (cname = "gnutls_psk_set_server_credentials_file")]
1674                 public int set_credentials_file (string password_file);
1676                 [CCode (cname = "gnutls_psk_set_server_credentials_hint")]
1677                 public int set_credentials_hint (string hint);
1679                 [CCode (cname = "gnutls_psk_set_server_credentials_function")]
1680                 public void set_credentials_function (PSKServerCredentialsFunction func);
1682                 [CCode (cname = "gnutls_psk_set_server_dh_params")]
1683                 public void set_dh_params (DHParams dh_params);
1685                 [CCode (cname = "gnutls_psk_set_server_params_function")] // also gnutls_psk_set_params_function
1686                 public void set_params_function (ParamsFunction func);
1687         }
1689         [CCode (cname = "gnutls_psk_client_credentials_function *")]
1690         public static delegate int PSKClientCredentialsFunction (Session session, out string username, out Datum key);
1692         [Compact]
1693         [CCode (cname = "struct gnutls_psk_client_credentials_st", free_function = "gnutls_psk_free_client_credentials")]
1694         public class PSKClientCredentials
1695         {
1696                 [CCode (cname = "gnutls_psk_allocate_client_credentials")]
1697                 private static int allocate (PSKClientCredentials* sc);
1698                 public static PSKClientCredentials create ()
1699                 {
1700                         PSKClientCredentials result = null;
1701                         var ret = allocate (&result);
1702                         if (ret != 0)
1703                                 GLib.error ("%s", ((ErrorCode)ret).to_string ());
1704                         return result;
1705                 }
1707                 [CCode (cname = "gnutls_psk_set_client_credentials")]
1708                 public int set_credentials (string username, /* const */ ref Datum key, PSKKeyFlags format);
1710                 [CCode (cname = "gnutls_psk_set_client_credentials_function")]
1711                 public void set_credentials_function (PSKClientCredentialsFunction func);
1712         }
1714         public int hex_encode (/* const */ ref Datum data, [CCode (array_length = "false")] char[] result, ref size_t result_size);
1715         public int hex_decode (/* const */ ref Datum hex_data, [CCode (array_length = "false")] char[] result, ref size_t result_size);
1717         public int psk_netconf_derive_key (string password, string psk_identity, string psk_identity_hint, out Datum output_key);
1719 ////
1721         [SimpleType]
1722         [CCode (cname = "gnutls_retr_st")]
1723         public struct RetrStruct
1724         {
1725                 public CertificateType type;
1726                 [CCode (cname = "cert.x509", array_length_name = "ncerts", array_length_type = "unsigned int")]
1727                 public X509.Certificate[] cert_x509;
1728                 [CCode (cname = "cert.pgp")]
1729                 public OpenPGP.Certificate cert_pgp;
1730                 [CCode (cname = "key.x509")]
1731                 public X509.PrivateKey key_x509;
1732                 [CCode (cname = "key.pgp")]
1733                 public OpenPGP.PrivateKey key_pgp;
1734                 public uint deinit_all;
1735         }
1737         public int pem_base64_encode (string msg, /* const */ ref Datum data, void* result, ref size_t result_size);
1738         public int pem_base64_decode (string header, /* const */ ref Datum b64_data, void* result, ref size_t result_size);
1740         public int pem_base64_encode_alloc (string msg, /* const */ ref Datum data, out Datum result);
1741         public int pem_base64_decode_alloc (string header, /* const */ ref Datum b64_data, out Datum result);
1743         public int hex2bin (string hex_data, size_t hex_size, void* bin_data, ref size_t bin_size);
1745         // returns cipher suite name or null if index is out of bounds
1746         public unowned string? cipher_suite_info (size_t index, [CCode (array_length = "false")] char[] cs_id, out KXAlgorithm kx,
1747                                                  out CipherAlgorithm cipher, out MacAlgorithm mac,
1748                                                  out Protocol version);
1750         public unowned string? cipher_suite_get_name (KXAlgorithm kx, CipherAlgorithm cipher, MacAlgorithm mac);
1752         public int prf (Session session, size_t label_size, string label, bool server_random_first,
1753                         size_t extra_size, void* extra, size_t output_size, void* output);
1755         public int prf_raw (Session session, size_t label_size, string label,
1756                             size_t seed_size, void* seed, size_t output_size, void* output);
1758         // Gnutls error codes. The mapping to a TLS alert is also shown in comments.
1759         [CCode (cname = "int", cprefix = "GNUTLS_E_", lower_case_cprefix = "gnutls_error_")]
1760         public enum ErrorCode {
1762                 SUCCESS,
1763                 UNKNOWN_COMPRESSION_ALGORITHM,
1764                 UNKNOWN_CIPHER_TYPE,
1765                 LARGE_PACKET,
1766                 UNSUPPORTED_VERSION_PACKET,     // GNUTLS_A_PROTOCOL_VERSION
1767                 UNEXPECTED_PACKET_LENGTH,       // GNUTLS_A_RECORD_OVERFLOW
1768                 INVALID_SESSION,
1769                 FATAL_ALERT_RECEIVED,
1770                 UNEXPECTED_PACKET,      // GNUTLS_A_UNEXPECTED_MESSAGE
1771                 WARNING_ALERT_RECEIVED,
1772                 ERROR_IN_FINISHED_PACKET,
1773                 UNEXPECTED_HANDSHAKE_PACKET,
1774                 UNKNOWN_CIPHER_SUITE,   // GNUTLS_A_HANDSHAKE_FAILURE
1775                 UNWANTED_ALGORITHM,
1776                 MPI_SCAN_FAILED,
1777                 DECRYPTION_FAILED,      // GNUTLS_A_DECRYPTION_FAILED, GNUTLS_A_BAD_RECORD_MAC
1778                 MEMORY_ERROR,
1779                 DECOMPRESSION_FAILED,  // GNUTLS_A_DECOMPRESSION_FAILURE
1780                 COMPRESSION_FAILED,
1781                 AGAIN,
1782                 EXPIRED,
1783                 DB_ERROR,
1784                 SRP_PWD_ERROR,
1785                 INSUFFICIENT_CREDENTIALS,
1787                 HASH_FAILED,
1788                 BASE64_DECODING_ERROR,
1790                 MPI_PRINT_FAILED,
1791                 REHANDSHAKE,     // GNUTLS_A_NO_RENEGOTIATION
1792                 GOT_APPLICATION_DATA,
1793                 RECORD_LIMIT_REACHED,
1794                 ENCRYPTION_FAILED,
1796                 PK_ENCRYPTION_FAILED,
1797                 PK_DECRYPTION_FAILED,
1798                 PK_SIGN_FAILED,
1799                 X509_UNSUPPORTED_CRITICAL_EXTENSION,
1800                 KEY_USAGE_VIOLATION,
1801                 NO_CERTIFICATE_FOUND,   // GNUTLS_A_BAD_CERTIFICATE
1802                 INVALID_REQUEST,
1803                 SHORT_MEMORY_BUFFER,
1804                 INTERRUPTED,
1805                 PUSH_ERROR,
1806                 PULL_ERROR,
1807                 RECEIVED_ILLEGAL_PARAMETER,    // GNUTLS_A_ILLEGAL_PARAMETER
1808                 REQUESTED_DATA_NOT_AVAILABLE,
1809                 PKCS1_WRONG_PAD,
1810                 RECEIVED_ILLEGAL_EXTENSION,
1811                 INTERNAL_ERROR,
1812                 DH_PRIME_UNACCEPTABLE,
1813                 FILE_ERROR,
1814                 TOO_MANY_EMPTY_PACKETS,
1815                 UNKNOWN_PK_ALGORITHM,
1817                 // returned if libextra functionality was requested but
1818                 // gnutls_global_init_extra() was not called.
1820                 INIT_LIBEXTRA,
1821                 LIBRARY_VERSION_MISMATCH,
1823                 // returned if you need to generate temporary RSA
1824                 // parameters. These are needed for export cipher suites.
1826                 NO_TEMPORARY_RSA_PARAMS,
1828                 LZO_INIT_FAILED,
1829                 NO_COMPRESSION_ALGORITHMS,
1830                 NO_CIPHER_SUITES,
1832                 OPENPGP_GETKEY_FAILED,
1833                 PK_SIG_VERIFY_FAILED,
1835                 ILLEGAL_SRP_USERNAME,
1836                 SRP_PWD_PARSING_ERROR,
1837                 NO_TEMPORARY_DH_PARAMS,
1839                 // For certificate and key stuff
1841                 ASN1_ELEMENT_NOT_FOUND,
1842                 ASN1_IDENTIFIER_NOT_FOUND,
1843                 ASN1_DER_ERROR,
1844                 ASN1_VALUE_NOT_FOUND,
1845                 ASN1_GENERIC_ERROR,
1846                 ASN1_VALUE_NOT_VALID,
1847                 ASN1_TAG_ERROR,
1848                 ASN1_TAG_IMPLICIT,
1849                 ASN1_TYPE_ANY_ERROR,
1850                 ASN1_SYNTAX_ERROR,
1851                 ASN1_DER_OVERFLOW,
1852                 OPENPGP_UID_REVOKED,
1853                 CERTIFICATE_ERROR,
1854                 CERTIFICATE_KEY_MISMATCH,
1855                 UNSUPPORTED_CERTIFICATE_TYPE,   // GNUTLS_A_UNSUPPORTED_CERTIFICATE
1856                 X509_UNKNOWN_SAN,
1857                 OPENPGP_FINGERPRINT_UNSUPPORTED,
1858                 X509_UNSUPPORTED_ATTRIBUTE,
1859                 UNKNOWN_HASH_ALGORITHM,
1860                 UNKNOWN_PKCS_CONTENT_TYPE,
1861                 UNKNOWN_PKCS_BAG_TYPE,
1862                 INVALID_PASSWORD,
1863                 MAC_VERIFY_FAILED,      // for PKCS #12 MAC
1864                 CONSTRAINT_ERROR,
1866                 WARNING_IA_IPHF_RECEIVED,
1867                 WARNING_IA_FPHF_RECEIVED,
1869                 IA_VERIFY_FAILED,
1871                 UNKNOWN_ALGORITHM,
1873                 BASE64_ENCODING_ERROR,
1874                 INCOMPATIBLE_CRYPTO_LIBRARY,
1875                 INCOMPATIBLE_LIBTASN1_LIBRARY,
1877                 OPENPGP_KEYRING_ERROR,
1878                 X509_UNSUPPORTED_OID,
1880                 RANDOM_FAILED,
1881                 BASE64_UNEXPECTED_HEADER_ERROR,
1883                 OPENPGP_SUBKEY_ERROR,
1885                 CRYPTO_ALREADY_REGISTERED,
1887                 HANDSHAKE_TOO_LARGE,
1889                 UNIMPLEMENTED_FEATURE,
1891                 APPLICATION_ERROR_MAX, // -65000
1892                 APPLICATION_ERROR_MIN;  // -65500
1894                 public bool is_fatal ();
1895                 public AlertDescription to_alert (out AlertLevel level);
1896                 [CCode (cname = "gnutls_perror")]
1897                 public void print ();
1898                 [CCode (cname = "gnutls_strerror")]
1899                 public unowned string to_string ();
1900         }