tildefriends/src/tls.h

42 lines
1.7 KiB
C
Raw Normal View History

#pragma once
#include <stdbool.h>
#include <stddef.h>
typedef struct _tf_tls_context_t tf_tls_context_t;
typedef struct _tf_tls_session_t tf_tls_session_t;
typedef enum _tf_tls_handshake_t
{
k_tls_handshake_done,
k_tls_handshake_more,
k_tls_handshake_failed,
} tf_tls_handshake_t;
typedef enum _tf_tls_read_t
{
k_tls_read_zero = -1,
k_tls_read_failed = -2,
} tf_tls_read_t;
tf_tls_context_t* tf_tls_context_create();
bool tf_tls_context_set_certificate(tf_tls_context_t* context, const char* certificate);
bool tf_tls_context_set_private_key(tf_tls_context_t* context, const char* private_key);
bool tf_tls_context_add_trusted_certificate(tf_tls_context_t* context, const char* certificate);
tf_tls_session_t* tf_tls_context_create_session(tf_tls_context_t* context);
void tf_tls_context_destroy(tf_tls_context_t* context);
void tf_tls_session_destroy(tf_tls_session_t* session);
void tf_tls_session_set_hostname(tf_tls_session_t* session, const char* hostname);
void tf_tls_session_start_accept(tf_tls_session_t* session);
void tf_tls_session_start_connect(tf_tls_session_t* session);
void tf_tls_session_shutdown(tf_tls_session_t* session);
int tf_tls_session_get_peer_certificate(tf_tls_session_t* session, char* buffer, size_t bytes);
tf_tls_handshake_t tf_tls_session_handshake(tf_tls_session_t* session);
int tf_tls_session_read_plain(tf_tls_session_t* session, char* buffer, size_t bytes);
int tf_tls_session_write_plain(tf_tls_session_t* session, const char* buffer, size_t bytes);
int tf_tls_session_read_encrypted(tf_tls_session_t* session, char* buffer, size_t bytes);
int tf_tls_session_write_encrypted(tf_tls_session_t* session, const char* buffer, size_t bytes);
bool tf_tls_session_get_error(tf_tls_session_t* session, char* buffer, size_t bytes);