KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
tls.h
Go to the documentation of this file.
1#ifndef KEEL_TLS_H
2#define KEEL_TLS_H
3
4#include <keel/allocator.h>
5#include <stddef.h>
6#include <sys/types.h>
7
17
25typedef struct KlTls KlTls;
26
27struct KlTls {
34 KlTlsResult (*handshake)(KlTls *self, int fd);
35
40 ssize_t (*read)(KlTls *self, int fd, void *buf, size_t len);
41
46 ssize_t (*write)(KlTls *self, int fd, const void *buf, size_t len);
47
52 KlTlsResult (*shutdown)(KlTls *self, int fd);
53
61 size_t (*pending)(KlTls *self);
62
66 void (*reset)(KlTls *self);
67
71 void (*destroy)(KlTls *self);
72
77 const char *(*alpn_protocol)(KlTls *self);
78
87 int (*set_hostname)(KlTls *self, const char *hostname);
88};
89
94typedef struct KlTlsCtx KlTlsCtx;
95
103typedef KlTls *(*KlTlsFactory)(KlTlsCtx *ctx, KlAllocator *alloc);
104
108typedef struct {
111 void (*ctx_destroy)(KlTlsCtx *ctx);
113
114#endif
Bring-your-own allocator vtable.
Definition allocator.h:12
TLS configuration for KlConfig.
Definition tls.h:108
KlTlsFactory factory
Definition tls.h:110
KlTlsCtx * ctx
Definition tls.h:109
Definition tls.h:27
void(* destroy)(KlTls *self)
Free all resources.
Definition tls.h:71
ssize_t(* read)(KlTls *self, int fd, void *buf, size_t len)
Decrypt: read up to len bytes of plaintext into buf.
Definition tls.h:40
KlTlsResult(* shutdown)(KlTls *self, int fd)
Initiate TLS shutdown (close_notify).
Definition tls.h:52
size_t(* pending)(KlTls *self)
Bytes buffered inside TLS that can be read without a syscall.
Definition tls.h:61
int(* set_hostname)(KlTls *self, const char *hostname)
Set the expected server hostname for SNI (client mode). Optional — set to NULL if not supported by th...
Definition tls.h:87
void(* reset)(KlTls *self)
Reset for connection reuse (keep-alive). TLS session persists.
Definition tls.h:66
ssize_t(* write)(KlTls *self, int fd, const void *buf, size_t len)
Encrypt: write up to len bytes of plaintext from buf.
Definition tls.h:46
KlTlsResult(* handshake)(KlTls *self, int fd)
Non-blocking handshake step. Call repeatedly until OK or ERROR.
Definition tls.h:34
KlTlsResult
Result codes for non-blocking TLS operations.
Definition tls.h:11
@ KL_TLS_OK
Definition tls.h:12
@ KL_TLS_WANT_READ
Definition tls.h:13
@ KL_TLS_WANT_WRITE
Definition tls.h:14
@ KL_TLS_ERROR
Definition tls.h:15
struct KlTlsCtx KlTlsCtx
Opaque per-server TLS context (certificates, keys, ciphers). User-owned — KEEL never inspects or modi...
Definition tls.h:94
KlTls *(* KlTlsFactory)(KlTlsCtx *ctx, KlAllocator *alloc)
Factory creates a per-connection KlTls session from the shared context. Called once per connection sl...
Definition tls.h:103