2021-01-02 13:10:00 -05:00
|
|
|
#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;
|
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
typedef enum _tf_tls_handshake_t
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
k_tls_handshake_done,
|
|
|
|
k_tls_handshake_more,
|
|
|
|
k_tls_handshake_failed,
|
|
|
|
} tf_tls_handshake_t;
|
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
typedef enum _tf_tls_read_t
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
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);
|