Delete rtc::join
Define a local function in the only place where it is used, for calling SSL_set1_curves_list. Bug: webrtc:6424 Change-Id: I7b9c372aaed15dbc88ced55652f5afd93db55e49 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261313 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36853}
This commit is contained in:

committed by
WebRTC LUCI CQ

parent
9e5aeb9d92
commit
9aa46c6572
@ -44,7 +44,7 @@
|
|||||||
#include "rtc_base/openssl_identity.h"
|
#include "rtc_base/openssl_identity.h"
|
||||||
#endif
|
#endif
|
||||||
#include "rtc_base/openssl_utility.h"
|
#include "rtc_base/openssl_utility.h"
|
||||||
#include "rtc_base/string_encode.h"
|
#include "rtc_base/strings/string_builder.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
@ -166,6 +166,23 @@ static void LogSslError() {
|
|||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
|
namespace webrtc_openssl_adapter_internal {
|
||||||
|
|
||||||
|
// Simple O(n^2) implementation is sufficient for current use case.
|
||||||
|
std::string StrJoin(const std::vector<std::string>& list, char delimiter) {
|
||||||
|
RTC_CHECK(!list.empty());
|
||||||
|
StringBuilder sb;
|
||||||
|
sb << list[0];
|
||||||
|
for (size_t i = 1; i < list.size(); i++) {
|
||||||
|
sb.AppendFormat("%c", delimiter);
|
||||||
|
sb << list[i];
|
||||||
|
}
|
||||||
|
return sb.Release();
|
||||||
|
}
|
||||||
|
} // namespace webrtc_openssl_adapter_internal
|
||||||
|
|
||||||
|
using webrtc_openssl_adapter_internal::StrJoin;
|
||||||
|
|
||||||
bool OpenSSLAdapter::InitializeSSL() {
|
bool OpenSSLAdapter::InitializeSSL() {
|
||||||
if (!SSL_library_init())
|
if (!SSL_library_init())
|
||||||
return false;
|
return false;
|
||||||
@ -354,7 +371,7 @@ int OpenSSLAdapter::BeginSSL() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!elliptic_curves_.empty()) {
|
if (!elliptic_curves_.empty()) {
|
||||||
SSL_set1_curves_list(ssl_, rtc::join(elliptic_curves_, ':').c_str());
|
SSL_set1_curves_list(ssl_, StrJoin(elliptic_curves_, ':').c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that the initial config is done, transfer ownership of `bio` to the
|
// Now that the initial config is done, transfer ownership of `bio` to the
|
||||||
|
@ -37,6 +37,14 @@
|
|||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
|
namespace webrtc_openssl_adapter_internal {
|
||||||
|
|
||||||
|
// Local definition, since absl::StrJoin is not allow-listed. Declared in header
|
||||||
|
// file only for unittests.
|
||||||
|
std::string StrJoin(const std::vector<std::string>& list, char delimiter);
|
||||||
|
|
||||||
|
} // namespace webrtc_openssl_adapter_internal
|
||||||
|
|
||||||
class OpenSSLAdapter final : public SSLAdapter,
|
class OpenSSLAdapter final : public SSLAdapter,
|
||||||
public MessageHandlerAutoCleanup {
|
public MessageHandlerAutoCleanup {
|
||||||
public:
|
public:
|
||||||
|
@ -113,4 +113,19 @@ TEST(OpenSSLAdapterFactoryTest, CreateWorksWithCustomVerifier) {
|
|||||||
EXPECT_NE(simple_adapter, nullptr);
|
EXPECT_NE(simple_adapter, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(StrJoinTest, SingleElement) {
|
||||||
|
EXPECT_EQ(webrtc_openssl_adapter_internal::StrJoin({"a"}, ','), "a");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StrJoinTest, TwoElements) {
|
||||||
|
EXPECT_EQ(webrtc_openssl_adapter_internal::StrJoin({"first", "second"}, ':'),
|
||||||
|
"first:second");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StrJoinTest, WithEmptyElement) {
|
||||||
|
EXPECT_EQ(
|
||||||
|
webrtc_openssl_adapter_internal::StrJoin({"first", "", "second"}, ':'),
|
||||||
|
"first::second");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace rtc
|
} // namespace rtc
|
||||||
|
@ -174,28 +174,6 @@ bool tokenize_first(absl::string_view source,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string join(const std::vector<std::string>& source, char delimiter) {
|
|
||||||
if (source.size() == 0) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
// Find length of the string to be returned to pre-allocate memory.
|
|
||||||
size_t source_string_length = 0;
|
|
||||||
for (size_t i = 0; i < source.size(); ++i) {
|
|
||||||
source_string_length += source[i].length();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the joined string.
|
|
||||||
std::string joined_string;
|
|
||||||
joined_string.reserve(source_string_length + source.size() - 1);
|
|
||||||
for (size_t i = 0; i < source.size(); ++i) {
|
|
||||||
if (i != 0) {
|
|
||||||
joined_string += delimiter;
|
|
||||||
}
|
|
||||||
joined_string += source[i];
|
|
||||||
}
|
|
||||||
return joined_string;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<absl::string_view> split(absl::string_view source, char delimiter) {
|
std::vector<absl::string_view> split(absl::string_view source, char delimiter) {
|
||||||
std::vector<absl::string_view> fields;
|
std::vector<absl::string_view> fields;
|
||||||
size_t last = 0;
|
size_t last = 0;
|
||||||
|
@ -43,10 +43,6 @@ size_t hex_decode_with_delimiter(ArrayView<char> buffer,
|
|||||||
absl::string_view source,
|
absl::string_view source,
|
||||||
char delimiter);
|
char delimiter);
|
||||||
|
|
||||||
// Joins the source vector of strings into a single string, with each
|
|
||||||
// field in source being separated by delimiter. No trailing delimiter is added.
|
|
||||||
std::string join(const std::vector<std::string>& source, char delimiter);
|
|
||||||
|
|
||||||
// Splits the source string into multiple fields separated by delimiter,
|
// Splits the source string into multiple fields separated by delimiter,
|
||||||
// with duplicates of delimiter creating empty fields. Empty input produces a
|
// with duplicates of delimiter creating empty fields. Empty input produces a
|
||||||
// single, empty, field.
|
// single, empty, field.
|
||||||
|
Reference in New Issue
Block a user