Adopt absl::string_view in function parameters under rtc_base/

This is part of a large-scale effort to increase adoption of
absl::string_view across the WebRTC code base.

This CL converts the majority of "const std::string&"s in function
parameters under rtc_base/ to absl::string_view.

Bug: webrtc:13579
Change-Id: I2b1e3776aa42326aa405f76bb324a2d233b21dca
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/254081
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Xavier Lepaul‎ <xalep@webrtc.org>
Reviewed-by: Anders Lilienthal <andersc@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36239}
This commit is contained in:
Ali Tofigh
2022-03-17 15:47:49 +01:00
committed by WebRTC LUCI CQ
parent 1a08096998
commit 7fa9057a05
96 changed files with 677 additions and 495 deletions

View File

@ -9,6 +9,8 @@
*/
#include "rtc_base/openssl_utility.h"
#include "absl/strings/string_view.h"
#if defined(WEBRTC_WIN)
// Must be included first before openssl headers.
#include "rtc_base/win32.h" // NOLINT
@ -184,7 +186,7 @@ bool ParseCertificate(CRYPTO_BUFFER* cert_buffer,
}
#endif // OPENSSL_IS_BORINGSSL
bool VerifyPeerCertMatchesHost(SSL* ssl, const std::string& host) {
bool VerifyPeerCertMatchesHost(SSL* ssl, absl::string_view host) {
if (host.empty()) {
RTC_DLOG(LS_ERROR) << "Hostname is empty. Cannot verify peer certificate.";
return false;
@ -211,8 +213,7 @@ bool VerifyPeerCertMatchesHost(SSL* ssl, const std::string& host) {
return false;
}
LogCertificates(ssl, x509.get());
return X509_check_host(x509.get(), host.c_str(), host.size(), 0, nullptr) ==
1;
return X509_check_host(x509.get(), host.data(), host.size(), 0, nullptr) == 1;
#else // OPENSSL_IS_BORINGSSL
X509* certificate = SSL_get_peer_certificate(ssl);
if (certificate == nullptr) {
@ -224,13 +225,13 @@ bool VerifyPeerCertMatchesHost(SSL* ssl, const std::string& host) {
LogCertificates(ssl, certificate);
bool is_valid_cert_name =
X509_check_host(certificate, host.c_str(), host.size(), 0, nullptr) == 1;
X509_check_host(certificate, host.data(), host.size(), 0, nullptr) == 1;
X509_free(certificate);
return is_valid_cert_name;
#endif // !defined(OPENSSL_IS_BORINGSSL)
}
void LogSSLErrors(const std::string& prefix) {
void LogSSLErrors(absl::string_view prefix) {
char error_buf[200];
unsigned long err; // NOLINT