scorpiox-bot-plugin-fetch
←fetch_tls.hc
34 lines · 1 KBHEADBlameDownload
1/*
2 * fetch_tls.h - minimal TLS stream over an already-connected socket.
3 *
4 * POSIX: vendored mbedTLS (verify peer + hostname against a CA bundle).
5 * _WIN32: this layer is not used (WinHTTP does TLS itself), so the module is
6 * an empty translation unit there and fx_tls_supported() reports 0.
7 */
8#ifndef SX_FETCH_TLS_H
9#define SX_FETCH_TLS_H
10
11#include <stddef.h>
12
13#if !defined(_WIN32)
14
15typedef struct fx_tls fx_tls;
16
17/* Takes ownership of `fd` on success (closed by fx_tls_close). hostname is
18 * used for SNI and certificate verification. Returns NULL + err on failure
19 * (fd closed). */
20fx_tls *fx_tls_connect_fd(int fd, const char *hostname, char *err, size_t errsz);
21
22/* Returns bytes read, 0 at EOF, -1 on error. */
23int fx_tls_read(fx_tls *t, char *buf, size_t n);
24/* Returns bytes written or -1. */
25int fx_tls_write(fx_tls *t, const char *buf, size_t n);
26
27void fx_tls_close(fx_tls *t);
28
29/* 1 when the binary was built with the TLS stack (POSIX), 0 otherwise. */
30int fx_tls_supported(void);
31
32#endif /* !_WIN32 */
33
34#endif /* SX_FETCH_TLS_H */