1 // Copyright 2021 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #pragma once 16 17 #include <string_view> 18 19 #include "pw_assert/assert.h" 20 #include "pw_assert/check.h" 21 #include "pw_stream/stream.h" 22 #include "pw_string/util.h" 23 24 namespace pw::tls_client { 25 26 class SessionOptions { 27 public: 28 // Sets the TLS server name. This is typically a domain name (e.g. 29 // www.google.com) used to differentiate any other virtual domain names 30 // resident on the same physical server. The option is used as the Server 31 // Name Indication(SNI) extension during TLS handshake. 32 // 33 // Callers need to ensure that the memory backing |server_name| is valid until 34 // being passed to Session::Create(), where backend has a chance to load or 35 // make a copy. set_server_name(std::string_view server_name)36 constexpr SessionOptions& set_server_name(std::string_view server_name) { 37 server_name_ = server_name; 38 return *this; 39 } 40 41 // Set the underlying transport for the TLS connection. The transport is 42 // provided through an instance of stream::ReaderWriter. Callers should 43 // guarantee that the transport object outlives the Session instance to be 44 // built. set_transport(stream::ReaderWriter & transport)45 constexpr SessionOptions& set_transport(stream::ReaderWriter& transport) { 46 transport_ = &transport; 47 return *this; 48 } 49 transport()50 constexpr pw::stream::ReaderWriter* transport() const { return transport_; } 51 server_name()52 constexpr std::string_view server_name() const { return server_name_; } 53 54 private: 55 std::string_view server_name_; 56 pw::stream::ReaderWriter* transport_ = nullptr; 57 58 // TODO(zyecheng): Expand the list as necessary to cover aspects such as 59 // certificate verification/revocation check policies. 60 }; 61 62 } // namespace pw::tls_client 63