Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
tls_stream.h
Go to the documentation of this file.
1// Copyright 2026 The Symbian SDK Authors.
2// Licensed under the Apache License, Version 2.0.
3
4#ifndef SYMBIAN_API_CONNECTIVITY_TLS_STREAM_H_
5#define SYMBIAN_API_CONNECTIVITY_TLS_STREAM_H_
6
7#include <cstddef>
8#include <cstdint>
9#include <span>
10#include <string_view>
11
12#include "absl/status/status.h"
13#include "absl/status/statusor.h"
14#include "absl/time/time.h"
17
19
21enum class TlsVersion { kTls12, kTls13 };
22
39class TlsStream : public net::ByteStream {
40 public:
47 static absl::StatusOr<TlsStream> Create(std::string_view server_certificate,
48 std::string_view server_private_key,
49 std::string_view client_ca_bundle,
50 TlsVersion version);
51
52 TlsStream(TlsStream&& other) noexcept;
53 TlsStream& operator=(TlsStream&& other) noexcept;
54 TlsStream(const TlsStream&) = delete;
55 TlsStream& operator=(const TlsStream&) = delete;
56 ~TlsStream();
57
62 static absl::StatusOr<TlsStream> Connect(
63 TcpClient client, std::string_view hostname, std::string_view ca_bundle,
64 TlsVersion version, std::string_view alpn = "http/1.1",
65 absl::Time deadline = absl::InfiniteFuture());
67 absl::Status SetAlpnProtocol(std::string_view protocol);
68 std::string_view negotiated_version() const;
69 std::string_view negotiated_protocol() const;
70
71 void Close() override { CloseSession(); }
72
74 absl::Status Accept(TcpClient&& client,
75 absl::Time deadline = absl::InfiniteFuture());
76
78 absl::StatusOr<std::size_t> Read(
79 std::span<std::uint8_t> bytes,
80 absl::Time deadline = absl::InfiniteFuture()) override;
81
83 absl::Status Write(std::span<const std::uint8_t> bytes,
84 absl::Time deadline = absl::InfiniteFuture()) override;
85
87 void CloseSession();
88
89 bool connected() const;
90
91 private:
92 struct Impl;
93
94 static absl::StatusOr<TlsStream> Initialize(bool server, TlsVersion version);
95 absl::Status Handshake(absl::Time deadline);
96
97 explicit TlsStream(Impl* impl) : impl_(impl) {}
98
99 Impl* impl_ = nullptr;
100};
101
102} // namespace symbian::api::connectivity
103
104#endif // SYMBIAN_API_CONNECTIVITY_TLS_STREAM_H_
One connected IPv4 TCP stream backed by Symbian RSocket.
Definition tcp_client.h:31
Worker-owned TLS transport for outbound HTTP and inbound sessions.
Definition tls_stream.h:39
void Close() override
Definition tls_stream.h:71
absl::Status Accept(TcpClient &&client, absl::Time deadline=absl::InfiniteFuture())
Complete TLS 1.2/1.3 handshake by an absolute deadline.
Definition tls_server.cc:298
bool connected() const
Definition tls_server.cc:411
void CloseSession()
Close the current stream and reset its TLS state.
Definition tls_server.cc:402
absl::StatusOr< std::size_t > Read(std::span< std::uint8_t > bytes, absl::Time deadline=absl::InfiniteFuture()) override
Receive application data into at most 32 KiB.
Definition tls_server.cc:343
~TlsStream()
Definition tls_server.cc:291
static absl::StatusOr< TlsStream > Connect(TcpClient client, std::string_view hostname, std::string_view ca_bundle, TlsVersion version, std::string_view alpn="http/1.1", absl::Time deadline=absl::InfiniteFuture())
Authenticate an outbound peer using explicit roots and hostname.
Definition tls_server.cc:198
absl::Status SetAlpnProtocol(std::string_view protocol)
Select the sole server ALPN protocol before Accept.
Definition tls_server.cc:250
TlsStream & operator=(TlsStream &&other) noexcept
Definition tls_server.cc:280
std::string_view negotiated_protocol() const
Definition tls_server.cc:269
static absl::StatusOr< TlsStream > Create(std::string_view server_certificate, std::string_view server_private_key, std::string_view client_ca_bundle, TlsVersion version)
Configure identity, trust roots and one TLS protocol version.
Definition tls_server.cc:117
std::string_view negotiated_version() const
Definition tls_server.cc:265
absl::Status Write(std::span< const std::uint8_t > bytes, absl::Time deadline=absl::InfiniteFuture()) override
Send at most 32 KiB of application data.
Definition tls_server.cc:373
TlsStream(const TlsStream &)=delete
TlsStream & operator=(const TlsStream &)=delete
Single-owner transport shared by HTTP and WebSocket connections.
Definition byte_stream.h:19
Definition active_tcp_listener.cc:11
TlsVersion
One protocol version supported by the vendored Mbed TLS server.
Definition tls_stream.h:21
std::string_view bytes
Definition exports.cc:74