trunks: introduce `ResponseSerializer::SerializeResponseNvRead()`.
This is to support `TPM2_NvRead` in vtpm.
BUG=b:227463940
TEST=unittests
Change-Id: I0d6b8c4bc4e78352fb3b1aedd68f57c0298163ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3666541
Tested-by: Leo Lai <[email protected]>
Reviewed-by: Yi Chou <[email protected]>
Commit-Queue: Leo Lai <[email protected]>
diff --git a/trunks/real_response_serializer_test.cc b/trunks/real_response_serializer_test.cc
index d999eb2..e1f7c50 100644
--- a/trunks/real_response_serializer_test.cc
+++ b/trunks/real_response_serializer_test.cc
@@ -4,10 +4,13 @@
#include "trunks/real_response_serializer.h"
+#include <algorithm>
+
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "trunks/command_parser.h"
+#include "trunks/password_authorization_delegate.h"
#include "trunks/tpm_generated.h"
namespace trunks {
@@ -89,6 +92,25 @@
EXPECT_EQ(memcmp(&data, &data_out, sizeof(data_out)), 0);
}
+TEST_F(RealResponseSerializerTest, SerializeResponseNvRead) {
+ const std::string fake_data = "fake data";
+ const TPM2B_MAX_NV_BUFFER data = Make_TPM2B_MAX_NV_BUFFER(fake_data);
+
+ std::string response;
+ serializer_.SerializeResponseNvRead(data, &response);
+
+ TPM2B_MAX_NV_BUFFER data_out = {};
+
+ PasswordAuthorizationDelegate fake_password_authorization(
+ "password placeholder");
+
+ ASSERT_EQ(Tpm::ParseResponse_NV_Read(response, &data_out,
+ &fake_password_authorization),
+ TPM_RC_SUCCESS);
+ EXPECT_EQ(std::string(data_out.buffer, data_out.buffer + data_out.size),
+ fake_data);
+}
+
} // namespace
} // namespace trunks