Add ChunkedObliviousHttpGateway::CanEncrypt()

PiperOrigin-RevId: 938626207
diff --git a/quiche/oblivious_http/oblivious_http_gateway.h b/quiche/oblivious_http/oblivious_http_gateway.h
index a7fbe6d..d3a1089 100644
--- a/quiche/oblivious_http/oblivious_http_gateway.h
+++ b/quiche/oblivious_http/oblivious_http_gateway.h
@@ -124,6 +124,12 @@
   absl::StatusOr<std::string> EncryptResponse(
       absl::string_view plaintext_payload, bool is_final_chunk);
 
+  // Returns true if the gateway has successfully decrypted the request and has
+  // the context necessary to encrypt responses.
+  bool CanEncrypt() const {
+    return oblivious_http_request_context_.has_value();
+  }
+
  private:
   enum class RequestMessageSection {
     kHeader,
diff --git a/quiche/oblivious_http/oblivious_http_gateway_test.cc b/quiche/oblivious_http/oblivious_http_gateway_test.cc
index 4ac95b0..c8d59b5 100644
--- a/quiche/oblivious_http/oblivious_http_gateway_test.cc
+++ b/quiche/oblivious_http/oblivious_http_gateway_test.cc
@@ -433,6 +433,7 @@
   ASSERT_TRUE(absl::HexStringToBytes(kEncapsulatedChunkedRequest,
                                      &encapsulated_request_bytes));
   QUICHE_EXPECT_OK(instance->DecryptRequest(encapsulated_request_bytes, true));
+  EXPECT_TRUE(instance->CanEncrypt());
 
   // 63 byte response to test final chunk indicator length.
   std::string plaintext_response =
@@ -467,6 +468,7 @@
   EXPECT_TRUE(
       absl::HexStringToBytes(plaintext_response, &plaintext_response_bytes));
   std::vector<std::string> encrypted_response_chunks;
+  EXPECT_TRUE(instance->CanEncrypt());
   absl::StatusOr<std::string> encrypted_response_chunk =
       instance->EncryptResponse(plaintext_response_bytes, false);
   QUICHE_EXPECT_OK(encrypted_response_chunk);
@@ -507,6 +509,7 @@
   ASSERT_TRUE(absl::HexStringToBytes(kEncapsulatedChunkedRequest,
                                      &encapsulated_request_bytes));
   QUICHE_EXPECT_OK(instance->DecryptRequest(encapsulated_request_bytes, true));
+  EXPECT_TRUE(instance->CanEncrypt());
 
   std::string plaintext_response = "0140c8";
   absl::StatusOr<std::string> encrypted_response =
@@ -520,6 +523,7 @@
 TEST(ChunkedObliviousHttpGateway, EncryptingBeforeDecryptingFails) {
   TestChunkHandler chunk_handler;
   auto instance = CreateChunkedObliviousHttpGateway(chunk_handler);
+  EXPECT_FALSE(instance->CanEncrypt());
 
   std::string plaintext_response = "0140c8";
   EXPECT_EQ(
@@ -530,6 +534,7 @@
 TEST(ChunkedObliviousHttpGateway, EncryptionErrorMarksGatewayInvalid) {
   TestChunkHandler chunk_handler;
   auto instance = CreateChunkedObliviousHttpGateway(chunk_handler);
+  EXPECT_FALSE(instance->CanEncrypt());
 
   std::string plaintext_response = "0140c8";
   EXPECT_EQ(