Use std::move to avoid making copies of payload.
Also cleared some return std::move statements. go/totw/labs/should-i-return-std-move
PiperOrigin-RevId: 484023440
diff --git a/quiche/oblivious_http/buffers/oblivious_http_request.cc b/quiche/oblivious_http/buffers/oblivious_http_request.cc
index 76029a3..5a43eb2 100644
--- a/quiche/oblivious_http/buffers/oblivious_http_request.cc
+++ b/quiche/oblivious_http/buffers/oblivious_http_request.cc
@@ -95,23 +95,23 @@
// Request Encapsulation.
absl::StatusOr<ObliviousHttpRequest>
ObliviousHttpRequest::CreateClientObliviousRequest(
- absl::string_view plaintext_payload, absl::string_view hpke_public_key,
+ std::string plaintext_payload, absl::string_view hpke_public_key,
const ObliviousHttpHeaderKeyConfig& ohttp_key_config) {
- return EncapsulateWithSeed(plaintext_payload, hpke_public_key,
+ return EncapsulateWithSeed(std::move(plaintext_payload), hpke_public_key,
ohttp_key_config, "");
}
absl::StatusOr<ObliviousHttpRequest>
ObliviousHttpRequest::CreateClientWithSeedForTesting(
- absl::string_view plaintext_payload, absl::string_view hpke_public_key,
+ std::string plaintext_payload, absl::string_view hpke_public_key,
const ObliviousHttpHeaderKeyConfig& ohttp_key_config,
absl::string_view seed) {
return ObliviousHttpRequest::EncapsulateWithSeed(
- plaintext_payload, hpke_public_key, ohttp_key_config, seed);
+ std::move(plaintext_payload), hpke_public_key, ohttp_key_config, seed);
}
absl::StatusOr<ObliviousHttpRequest> ObliviousHttpRequest::EncapsulateWithSeed(
- absl::string_view plaintext_payload, absl::string_view hpke_public_key,
+ std::string plaintext_payload, absl::string_view hpke_public_key,
const ObliviousHttpHeaderKeyConfig& ohttp_key_config,
absl::string_view seed) {
if (plaintext_payload.empty() || hpke_public_key.empty()) {
@@ -182,7 +182,7 @@
return ObliviousHttpRequest(
std::move(client_ctx), std::move(encapsulated_key), ohttp_key_config,
- std::move(ciphertext), std::string(plaintext_payload));
+ std::move(ciphertext), std::move(plaintext_payload));
}
// Request Serialize.
diff --git a/quiche/oblivious_http/buffers/oblivious_http_request.h b/quiche/oblivious_http/buffers/oblivious_http_request.h
index 1963693..5ff195c 100644
--- a/quiche/oblivious_http/buffers/oblivious_http_request.h
+++ b/quiche/oblivious_http/buffers/oblivious_http_request.h
@@ -60,12 +60,12 @@
// On success, returns obj that callers will use to `EncapsulateAndSerialize`
// OHttp request.
static absl::StatusOr<ObliviousHttpRequest> CreateClientObliviousRequest(
- absl::string_view plaintext_payload, absl::string_view hpke_public_key,
+ std::string plaintext_payload, absl::string_view hpke_public_key,
const ObliviousHttpHeaderKeyConfig& ohttp_key_config);
// Same as above but accepts a random number seed for testing.
static absl::StatusOr<ObliviousHttpRequest> CreateClientWithSeedForTesting(
- absl::string_view plaintext_payload, absl::string_view hpke_public_key,
+ std::string plaintext_payload, absl::string_view hpke_public_key,
const ObliviousHttpHeaderKeyConfig& ohttp_key_config,
absl::string_view seed);
@@ -104,7 +104,7 @@
std::string req_ciphertext, std::string req_plaintext);
static absl::StatusOr<ObliviousHttpRequest> EncapsulateWithSeed(
- absl::string_view plaintext_payload, absl::string_view hpke_public_key,
+ std::string plaintext_payload, absl::string_view hpke_public_key,
const ObliviousHttpHeaderKeyConfig& ohttp_key_config,
absl::string_view seed);
diff --git a/quiche/oblivious_http/buffers/oblivious_http_request_test.cc b/quiche/oblivious_http/buffers/oblivious_http_request_test.cc
index e313bb8..546de96 100644
--- a/quiche/oblivious_http/buffers/oblivious_http_request_test.cc
+++ b/quiche/oblivious_http/buffers/oblivious_http_request_test.cc
@@ -116,7 +116,7 @@
uint16_t test_kem_id = EVP_HPKE_DHKEM_X25519_HKDF_SHA256;
uint16_t test_kdf_id = EVP_HPKE_HKDF_SHA256;
uint16_t test_aead_id = EVP_HPKE_AES_256_GCM;
- absl::string_view plaintext = "test";
+ std::string plaintext = "test";
auto instance = ObliviousHttpRequest::CreateClientObliviousRequest(
plaintext, GetHpkePublicKey(),
GetOhttpKeyConfig(test_key_id, test_kem_id, test_kdf_id, test_aead_id));
diff --git a/quiche/oblivious_http/buffers/oblivious_http_response.cc b/quiche/oblivious_http/buffers/oblivious_http_response.cc
index 4ab7092..b81ea8e 100644
--- a/quiche/oblivious_http/buffers/oblivious_http_response.cc
+++ b/quiche/oblivious_http/buffers/oblivious_http_response.cc
@@ -37,9 +37,9 @@
ObliviousHttpResponse::ObliviousHttpResponse(std::string resp_nonce,
std::string resp_ciphertext,
std::string resp_plaintext)
- : response_nonce_(resp_nonce),
- response_ciphertext_(resp_ciphertext),
- response_plaintext_(resp_plaintext) {}
+ : response_nonce_(std::move(resp_nonce)),
+ response_ciphertext_(std::move(resp_ciphertext)),
+ response_plaintext_(std::move(resp_plaintext)) {}
// Response Decapsulation.
// 1. Extract resp_nonce
@@ -119,9 +119,10 @@
"Failed to decrypt the response with derived AEAD key and nonce.");
}
decrypted.resize(decrypted_len);
- ObliviousHttpResponse oblivious_response(
- std::string(response_nonce), std::string(encrypted_response), decrypted);
- return std::move(oblivious_response);
+ ObliviousHttpResponse oblivious_response(std::string(response_nonce),
+ std::string(encrypted_response),
+ std::move(decrypted));
+ return oblivious_response;
}
// Response Encapsulation.
@@ -131,7 +132,7 @@
// encrypt) the response back to the Sender(client)
absl::StatusOr<ObliviousHttpResponse>
ObliviousHttpResponse::CreateServerObliviousResponse(
- absl::string_view plaintext_payload,
+ std::string plaintext_payload,
ObliviousHttpRequest::Context& oblivious_http_request_context,
QuicheRandom* quiche_random) {
if (oblivious_http_request_context.hpke_context_ == nullptr) {
@@ -196,9 +197,10 @@
(response_nonce.empty() ? "Generated nonce is empty." : ""),
(ciphertext.empty() ? "Generated Encrypted payload is empty." : "")));
}
- ObliviousHttpResponse oblivious_response(response_nonce, ciphertext,
- std::string(plaintext_payload));
- return std::move(oblivious_response);
+ ObliviousHttpResponse oblivious_response(std::move(response_nonce),
+ std::move(ciphertext),
+ std::move(plaintext_payload));
+ return oblivious_response;
}
// Serialize.
@@ -233,7 +235,7 @@
const size_t secret_len = std::max(aead_key_len, aead_nonce_len);
CommonAeadParamsResult result{evp_hpke_aead, aead_key_len, aead_nonce_len,
secret_len};
- return std::move(result);
+ return result;
}
// Common Steps of AEAD key and AEAD nonce derivation common to both
@@ -346,7 +348,7 @@
"Failed to initialize AEAD context with derived key.");
}
CommonOperationsResult result{std::move(aead_ctx), std::move(aead_nonce)};
- return std::move(result);
+ return result;
}
} // namespace quiche
diff --git a/quiche/oblivious_http/buffers/oblivious_http_response.h b/quiche/oblivious_http/buffers/oblivious_http_response.h
index 40279fc..70198cf 100644
--- a/quiche/oblivious_http/buffers/oblivious_http_response.h
+++ b/quiche/oblivious_http/buffers/oblivious_http_response.h
@@ -37,7 +37,7 @@
// string generation. `quiche_random` is required to stay alive only for the
// lifetime of this factory method call.
static absl::StatusOr<ObliviousHttpResponse> CreateServerObliviousResponse(
- absl::string_view plaintext_payload,
+ std::string plaintext_payload,
ObliviousHttpRequest::Context& oblivious_http_request_context,
QuicheRandom* quiche_random = nullptr);
diff --git a/quiche/oblivious_http/buffers/oblivious_http_response_test.cc b/quiche/oblivious_http/buffers/oblivious_http_response_test.cc
index f19020d..b2147d7 100644
--- a/quiche/oblivious_http/buffers/oblivious_http_response_test.cc
+++ b/quiche/oblivious_http/buffers/oblivious_http_response_test.cc
@@ -50,7 +50,7 @@
auto ohttp_key_config =
ObliviousHttpHeaderKeyConfig::Create(key_id, kem_id, kdf_id, aead_id);
EXPECT_TRUE(ohttp_key_config.ok());
- return std::move(ohttp_key_config.value());
+ return ohttp_key_config.value();
}
bssl::UniquePtr<EVP_HPKE_CTX> GetSeededClientContext(uint8_t key_id,
@@ -90,11 +90,12 @@
ObliviousHttpRequest SetUpObliviousHttpContext(uint8_t key_id, uint16_t kem_id,
uint16_t kdf_id,
uint16_t aead_id,
- absl::string_view plaintext) {
+ std::string plaintext) {
auto ohttp_key_config = GetOhttpKeyConfig(key_id, kem_id, kdf_id, aead_id);
auto client_request_encapsulate =
ObliviousHttpRequest::CreateClientWithSeedForTesting(
- plaintext, GetHpkePublicKey(), ohttp_key_config, GetSeed());
+ std::move(plaintext), GetHpkePublicKey(), ohttp_key_config,
+ GetSeed());
EXPECT_TRUE(client_request_encapsulate.ok());
auto oblivious_request =
client_request_encapsulate->EncapsulateAndSerialize();
diff --git a/quiche/oblivious_http/oblivious_http_client.cc b/quiche/oblivious_http/oblivious_http_client.cc
index 4379096..8a77c75 100644
--- a/quiche/oblivious_http/oblivious_http_client.cc
+++ b/quiche/oblivious_http/oblivious_http_client.cc
@@ -75,17 +75,17 @@
absl::StatusOr<ObliviousHttpRequest>
ObliviousHttpClient::CreateObliviousHttpRequest(
- absl::string_view plaintext_data) const {
+ std::string plaintext_data) const {
return ObliviousHttpRequest::CreateClientObliviousRequest(
- plaintext_data, hpke_public_key_, ohttp_key_config_);
+ std::move(plaintext_data), hpke_public_key_, ohttp_key_config_);
}
absl::StatusOr<ObliviousHttpResponse>
ObliviousHttpClient::DecryptObliviousHttpResponse(
- absl::string_view encrypted_data,
+ std::string encrypted_data,
ObliviousHttpRequest::Context& oblivious_http_request_context) const {
return ObliviousHttpResponse::CreateClientObliviousResponse(
- encrypted_data, oblivious_http_request_context);
+ std::move(encrypted_data), oblivious_http_request_context);
}
} // namespace quiche
diff --git a/quiche/oblivious_http/oblivious_http_client.h b/quiche/oblivious_http/oblivious_http_client.h
index 93cf1a2..9527b68 100644
--- a/quiche/oblivious_http/oblivious_http_client.h
+++ b/quiche/oblivious_http/oblivious_http_client.h
@@ -54,14 +54,14 @@
// auto encrypted_request2 =
// ohttp_client_object.CreateObliviousHttpRequest("binary http string 2");
absl::StatusOr<ObliviousHttpRequest> CreateObliviousHttpRequest(
- absl::string_view plaintext_data) const;
+ std::string plaintext_data) const;
// After `CreateObliviousHttpRequest` operation, callers on client-side will
// extract `oblivious_http_request_context` from the returned object
// `ObliviousHttpRequest` and pass in to this method in order to decrypt the
// response that's received from Gateway for the given request at hand.
absl::StatusOr<ObliviousHttpResponse> DecryptObliviousHttpResponse(
- absl::string_view encrypted_data,
+ std::string encrypted_data,
ObliviousHttpRequest::Context& oblivious_http_request_context) const;
private:
diff --git a/quiche/oblivious_http/oblivious_http_client_test.cc b/quiche/oblivious_http/oblivious_http_client_test.cc
index 9abfbd3..a2768a5 100644
--- a/quiche/oblivious_http/oblivious_http_client_test.cc
+++ b/quiche/oblivious_http/oblivious_http_client_test.cc
@@ -36,17 +36,17 @@
auto ohttp_key_config =
ObliviousHttpHeaderKeyConfig::Create(key_id, kem_id, kdf_id, aead_id);
EXPECT_TRUE(ohttp_key_config.ok());
- return std::move(ohttp_key_config.value());
+ return ohttp_key_config.value();
}
bssl::UniquePtr<EVP_HPKE_KEY> ConstructHpkeKey(
absl::string_view hpke_key,
- const ObliviousHttpHeaderKeyConfig &ohttp_key_config) {
+ const ObliviousHttpHeaderKeyConfig& ohttp_key_config) {
bssl::UniquePtr<EVP_HPKE_KEY> bssl_hpke_key(EVP_HPKE_KEY_new());
EXPECT_NE(bssl_hpke_key, nullptr);
EXPECT_TRUE(EVP_HPKE_KEY_init(
bssl_hpke_key.get(), ohttp_key_config.GetHpkeKem(),
- reinterpret_cast<const uint8_t *>(hpke_key.data()), hpke_key.size()));
+ reinterpret_cast<const uint8_t*>(hpke_key.data()), hpke_key.size()));
return bssl_hpke_key;
}
@@ -150,7 +150,7 @@
auto client_request_context =
std::move(encapsulate_req_on_client.value()).ReleaseContext();
auto decapsulate_resp_on_client = client->DecryptObliviousHttpResponse(
- absl::string_view(encapsulate_resp_on_gateway->EncapsulateAndSerialize()),
+ encapsulate_resp_on_gateway->EncapsulateAndSerialize(),
client_request_context);
ASSERT_TRUE(decapsulate_resp_on_client.ok());
EXPECT_EQ(decapsulate_resp_on_client->GetPlaintextData(), "test response");
@@ -182,7 +182,7 @@
ObliviousHttpClient::Create(GetHpkePublicKey(), ohttp_key_config);
ASSERT_TRUE(client.ok());
auto decapsulate_resp_on_client = client->DecryptObliviousHttpResponse(
- absl::string_view(encapsulate_resp_on_gateway->EncapsulateAndSerialize()),
+ encapsulate_resp_on_gateway->EncapsulateAndSerialize(),
gateway_request_context);
ASSERT_TRUE(decapsulate_resp_on_client.ok());
EXPECT_EQ(decapsulate_resp_on_client->GetPlaintextData(), "test response");
diff --git a/quiche/oblivious_http/oblivious_http_gateway.cc b/quiche/oblivious_http/oblivious_http_gateway.cc
index 0c5cf6b..b2d2e88 100644
--- a/quiche/oblivious_http/oblivious_http_gateway.cc
+++ b/quiche/oblivious_http/oblivious_http_gateway.cc
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <memory>
+#include <string>
#include <utility>
#include "absl/memory/memory.h"
@@ -57,10 +58,11 @@
absl::StatusOr<ObliviousHttpResponse>
ObliviousHttpGateway::CreateObliviousHttpResponse(
- absl::string_view plaintext_data,
+ std::string plaintext_data,
ObliviousHttpRequest::Context& oblivious_http_request_context) const {
return ObliviousHttpResponse::CreateServerObliviousResponse(
- plaintext_data, oblivious_http_request_context, quiche_random_);
+ std::move(plaintext_data), oblivious_http_request_context,
+ quiche_random_);
}
} // namespace quiche
diff --git a/quiche/oblivious_http/oblivious_http_gateway.h b/quiche/oblivious_http/oblivious_http_gateway.h
index 299f2bb..ae6c746 100644
--- a/quiche/oblivious_http/oblivious_http_gateway.h
+++ b/quiche/oblivious_http/oblivious_http_gateway.h
@@ -2,6 +2,7 @@
#define QUICHE_OBLIVIOUS_HTTP_OBLIVIOUS_HTTP_GATEWAY_H_
#include <memory>
+#include <string>
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
@@ -61,7 +62,7 @@
// `ObliviousHttpRequest` and pass in to this method in order to handle the
// response flow back to the client.
absl::StatusOr<ObliviousHttpResponse> CreateObliviousHttpResponse(
- absl::string_view plaintext_data,
+ std::string plaintext_data,
ObliviousHttpRequest::Context& oblivious_http_request_context) const;
private: