/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "Licence").
 * You may not use this file except in compliance with the Licence.
 *
 * CDDL HEADER END
 *
 * Copyright (c) RISC OS Developments 2026. All rights reserved.
 * SPDX-License-Identifier: CDDL-1.0
 */
#ifndef TLSMANAGER_TRANSPORT_H
#define TLSMANAGER_TRANSPORT_H

#include <stddef.h>
#include <stdint.h>
#include "kernel.h"

#define TLSMANAGER_ABI_VERSION 1u
#define TLSMANAGER_STATUS_COMPLETE 0
#define TLSMANAGER_STATUS_READABLE 1
#define TLSMANAGER_STATUS_WRITABLE 2
#define TLSMANAGER_STATUS_YIELD 3
#define TLSMANAGER_STATUS_EOF 4

typedef struct tlsmanager_open_block {
    uint32_t size;
    uint32_t abi;
    const char *hostname;
    uint32_t hostname_length;
    uint32_t port;
    uint32_t connect_timeout_cs;
    uint32_t io_timeout_cs;
    uint32_t minimum_tls;
    uint32_t trust_policy;
    const char *proxy_hostname;
    uint32_t proxy_hostname_length;
    uint32_t proxy_port;
    uint32_t proxy_secure;
    uint32_t target_secure;
} tlsmanager_open_block;

_kernel_oserror *TLSManagerTransportInit(void);
void TLSManagerTransportFinal(void);
unsigned int TLSManagerTransportCount(void);
const char *TLSManagerOpenSSLVersion(void);
const char *TLSManagerCABundleVersion(void);

_kernel_oserror *TLSManagerTransportOpen(const tlsmanager_open_block *,
                                         size_t, unsigned int *);
_kernel_oserror *TLSManagerTransportStep(unsigned int, int *, int *);
_kernel_oserror *TLSManagerTransportRead(unsigned int, void *, size_t,
                                         size_t *, int *);
_kernel_oserror *TLSManagerTransportWrite(unsigned int, const void *, size_t,
                                          size_t *, int *);
_kernel_oserror *TLSManagerTransportClose(unsigned int, unsigned int);

#endif
