#ifndef TURTLS_H
#define TURTLS_H
#include <stddef.h>
#include <stdint.h>
#define TURTLS_ECDSA_SECP256R1 1
#define TURTLS_SECP256R1 1
enum TurtlsAlert {
TURTLS_ALERT_CLOSE_NOTIFY = 0,
TURTLS_ALERT_UNEXPECTED_MESSAGE = 10,
TURTLS_ALERT_BAD_RECORD_MAC = 20,
TURTLS_ALERT_RECORD_OVERFLOW = 22,
TURTLS_ALERT_HANDSHAKE_FAILURE = 40,
TURTLS_ALERT_BAD_CERT = 42,
TURTLS_ALERT_UNSUPPORTED_CERT = 43,
TURTLS_ALERT_CERT_REVOKED = 44,
TURTLS_ALERT_CERT_EXPIRED = 45,
TURTLS_ALERT_CERT_UNKNOWN = 46,
TURTLS_ALERT_ILLEGAL_PARAM = 47,
TURTLS_ALERT_UNKNOWN_CA = 48,
TURTLS_ALERT_ACCESS_DENIED = 49,
TURTLS_ALERT_DECODE_ERROR = 50,
TURTLS_ALERT_DECRYPT_ERORR = 51,
TURTLS_ALERT_PROTOCOL_VERSION = 70,
TURTLS_ALERT_INSUFFICIENT_SECURITY = 71,
TURTLS_ALERT_INTERNAL_ERROR = 80,
TURTLS_ALERT_INAPPROPRIATE_FALLBACK = 86,
TURTLS_ALERT_USER_CANCELLED = 90,
TURTLS_ALERT_MISSING_EXTENSION = 109,
TURTLS_ALERT_UNSUPPORTED_EXTENSION = 110,
TURTLS_ALERT_UNRECOGNIZED_NAME = 112,
TURTLS_ALERT_BAD_CERT_STATUS_RESPONSE = 113,
TURTLS_ALERT_UNKNOWN_PSK_IDENTITY = 115,
TURTLS_ALERT_CERT_REQUIRED = 116,
TURTLS_ALERT_NO_APP_PROTOCOL = 120,
};
enum TurtlsError {
TURTLS_ERROR_TLS,
TURTLS_ERROR_TLS_PEER,
TURTLS_ERROR_RNG,
TURTLS_ERROR_WANT_READ,
TURTLS_ERROR_WANT_WRITE,
TURTLS_ERROR_PRIV_KEY_IS_ZERO,
TURTLS_ERROR_MISSING_EXTENSIONS,
};
struct TurtlsConn;
struct TurtlsExts {
const char *server_name;
uint16_t sig_algs;
uint16_t sup_groups;
const char *app_protos;
size_t app_protos_len;
};
typedef uint8_t TurtlsCipherList;
#define TurtlsCipherList_TURTLS_CHA_CHA_POLY1305_SHA256 1
#define TurtlsCipherList_TURTLS_AES_128_GCM_SHA256 2
struct TurtlsConfig {
struct TurtlsExts extensions;
TurtlsCipherList cipher_suites;
};
struct TurtlsIo {
ptrdiff_t (*write_fn)(const void *buf, size_t amt, const void *ctx);
ptrdiff_t (*read_fn)(void *buf, size_t amt, const void *ctx);
void (*close_fn)(const void *ctx);
void *ctx;
};
#ifdef __cplusplus
extern "C" {
#endif
const char *turtls_app_proto(const struct TurtlsConn *tls_conn);
void turtls_close(struct TurtlsConn *tls_conn);
int turtls_connect(struct TurtlsConn *tls_conn);
void turtls_free(struct TurtlsConn *tls_conn);
struct TurtlsConfig *turtls_get_config(struct TurtlsConn *tls_conn);
enum TurtlsError turtls_get_error(const struct TurtlsConn *tls_conn);
enum TurtlsAlert turtls_get_tls_error(const struct TurtlsConn *tls_conn);
struct TurtlsConn *turtls_new(struct TurtlsIo io);
const char *turtls_stringify_alert(enum TurtlsAlert alert);
#ifdef __cplusplus
} #endif
#endif