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 <memory>
10#include <span>
11#include <string_view>
12
13#include <absl/base/nullability.h>
14
15#include "absl/status/status.h"
16#include "absl/status/statusor.h"
17#include "absl/time/time.h"
20
22
24enum class TlsVersion { kTls12, kTls13 };
25
42class TlsStream {
43 public:
50 static absl::StatusOr<TlsStream> Create(std::string_view server_certificate,
51 std::string_view server_private_key,
52 std::string_view client_ca_bundle,
53 TlsVersion version);
54 static absl::StatusOr<std::unique_ptr<TlsStream>> CreateUnique(
55 std::string_view server_certificate, std::string_view server_private_key,
56 std::string_view client_ca_bundle, TlsVersion version);
57
58 TlsStream(TlsStream&& other) noexcept;
59 TlsStream& operator=(TlsStream&& other) noexcept;
60 TlsStream(const TlsStream&) = delete;
61 TlsStream& operator=(const TlsStream&) = delete;
62 ~TlsStream();
63
68 static absl::StatusOr<TlsStream> Connect(
69 TcpClient client, std::string_view hostname, std::string_view ca_bundle,
70 TlsVersion version, std::string_view alpn = "http/1.1",
71 absl::Time deadline = absl::InfiniteFuture());
73 absl::Status SetAlpnProtocol(std::string_view protocol);
74 std::string_view negotiated_version() const;
75 std::string_view negotiated_protocol() const;
76
77 void Close() { CloseSession(); }
78
80 absl::Status Accept(TcpClient&& client,
81 absl::Time deadline = absl::InfiniteFuture());
82
84 absl::StatusOr<std::size_t> Read(
85 std::span<std::uint8_t> bytes,
86 absl::Time deadline = absl::InfiniteFuture());
87
89 absl::Status Write(std::span<const std::uint8_t> bytes,
90 absl::Time deadline = absl::InfiniteFuture());
91
93 void CloseSession();
94
95 bool connected() const;
96
97 private:
98 struct Impl;
99
100 static absl::StatusOr<TlsStream> Initialize(bool server, TlsVersion version);
101 absl::Status Handshake(absl::Time deadline);
102
103 explicit TlsStream(Impl* absl_nonnull impl) : impl_(impl) {}
104
105 Impl* absl_nullable impl_ = nullptr;
106};
107
108} // namespace symbian::api::connectivity
109
110#endif // SYMBIAN_API_CONNECTIVITY_TLS_STREAM_H_
One connected IPv4 TCP stream backed by Symbian RSocket.
Definition tcp_client.h:33
Worker-owned TLS transport for outbound HTTP and inbound sessions.
Definition tls_stream.h:42
absl::StatusOr< std::size_t > Read(std::span< std::uint8_t > bytes, absl::Time deadline=absl::InfiniteFuture())
Receive application data into at most 32 KiB.
Definition tls_server.cc:354
absl::Status Write(std::span< const std::uint8_t > bytes, absl::Time deadline=absl::InfiniteFuture())
Send at most 32 KiB of application data.
Definition tls_server.cc:382
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:309
bool connected() const
Definition tls_server.cc:418
void CloseSession()
Close the current stream and reset its TLS state.
Definition tls_server.cc:409
static absl::StatusOr< std::unique_ptr< TlsStream > > CreateUnique(std::string_view server_certificate, std::string_view server_private_key, std::string_view client_ca_bundle, TlsVersion version)
Definition tls_server.cc:167
~TlsStream()
Definition tls_server.cc:302
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:213
absl::Status SetAlpnProtocol(std::string_view protocol)
Select the sole server ALPN protocol before Accept.
Definition tls_server.cc:260
void Close()
Definition tls_stream.h:77
TlsStream & operator=(TlsStream &&other) noexcept
Definition tls_server.cc:291
std::string_view negotiated_protocol() const
Definition tls_server.cc:279
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:121
std::string_view negotiated_version() const
Definition tls_server.cc:275
TlsStream(const TlsStream &)=delete
TlsStream & operator=(const TlsStream &)=delete
Definition active_tcp_listener.cc:13
TlsVersion
One protocol version supported by the vendored Mbed TLS server.
Definition tls_stream.h:24
std::string_view bytes
Definition exports.cc:76