test_state.cc: serialize the test clock.
This is needed for some TLS 1.3 split-handshake tests. Because
TestState::Deserialize doesn't check for CBS_len() == 0, it should be
a compatible change to tack additional data onto the end of the
serialized test state.
Change-Id: I16464b6e27ab2e9afd0d505719095b4895e652a4
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39546
Commit-Queue: Matt Braithwaite <mab@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/ssl/test/test_state.cc b/ssl/test/test_state.cc
index b9767e0..86deb55 100644
--- a/ssl/test/test_state.cc
+++ b/ssl/test/test_state.cc
@@ -138,6 +138,8 @@
!CBB_add_bytes(
&text, reinterpret_cast<const uint8_t *>(msg_callback_text.data()),
msg_callback_text.length()) ||
+ !CBB_add_asn1_uint64(&out, g_clock.tv_sec) ||
+ !CBB_add_asn1_uint64(&out, g_clock.tv_usec) ||
!CBB_flush(cbb)) {
return false;
}
@@ -149,6 +151,7 @@
std::unique_ptr<TestState> out_state(new TestState());
uint16_t version;
constexpr uint16_t kVersion = 0;
+ uint64_t sec, usec;
if (!CBS_get_u24_length_prefixed(cbs, &in) ||
!CBS_get_u16(&in, &version) ||
version > kVersion ||
@@ -165,5 +168,14 @@
}
out_state->msg_callback_text = std::string(
reinterpret_cast<const char *>(CBS_data(&text)), CBS_len(&text));
+ // TODO(2020-05-01): Make this unconditional & merge into above.
+ if (CBS_len(&in) > 0) {
+ if (!CBS_get_asn1_uint64(&in, &sec) ||
+ !CBS_get_asn1_uint64(&in, &usec)) {
+ return nullptr;
+ }
+ g_clock.tv_sec = sec;
+ g_clock.tv_usec = usec;
+ }
return out_state;
}