diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-06-21 22:32:27 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-06-25 17:22:19 +0200 |
commit | bbb8bc475593b9ff481ec214c4391fe6aff854f4 (patch) | |
tree | 4452579755867361fc5e6b7b395787f57e9fa2c7 /transport.h | |
parent | 46feba9a7b1e4ed023dcdc3c505b67f3eb8348f0 (diff) |
WIP secure transport using libsodium secretstreamlibsodium-transport
Diffstat (limited to 'transport.h')
-rw-r--r-- | transport.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/transport.h b/transport.h new file mode 100644 index 0000000..21cebd3 --- /dev/null +++ b/transport.h @@ -0,0 +1,38 @@ +#pragma once + +#include <stddef.h> +#include <stdbool.h> + +struct transport; + +// Takes ownership of socket. +// Returns NULL and closes socket if setup fails. +struct transport* tsp_start(int fd, bool is_server); + +// Also closes socket. +void tsp_close(struct transport *tsp); + +// Get file descriptor that can be used in e.g. select(2) to detect possible +// data on the transport. If there is data, the tsp_recv() function must be +// used to handle it, because it may be protocol-level data for the integrity +// of the transport. +int tsp_select_fd(const struct transport *tsp); + +// If successful, returns true. +// If unsuccessful, returns false and closes the transport (after which the +// transport may not be used again). +bool tsp_send(struct transport *tsp, const char *data, size_t length); + +struct received_data { + char *data; + size_t length; + bool error; +}; +void received_data_nullify(struct received_data data); + +// If no data is avilable yet, returns {.data=NULL, length=0, error=false}. +// If an error occurred, returns {.data=NULL, length=0, error=true}. +// If data is avilable, returns {.data=..., length=(length of data), error=false}. +// This function also handles protocol-level actions that do not actually +// return application-level data, but that are indeed necessary. +struct received_data tsp_recv(struct transport *tsp); |