Eliminate in-place serialization.
Not doing in-place serialization will result in greater heap
consumption, but eliminates many alignment-related issues. Given more
time, I'd prefer to solve the alignment issues by computing and
inserting appropriate padding, but we don't have the time.
Change-Id: I86e4bdf57263db26c73372ae2963f21c5f5f00aa
diff --git a/serializable.cpp b/serializable.cpp
index 12917b2..c00d913 100644
--- a/serializable.cpp
+++ b/serializable.cpp
@@ -26,4 +26,15 @@
return true;
}
+bool copy_size_and_data_from_buf(const uint8_t** buf, const uint8_t* end, size_t* size,
+ uint8_t** dest) {
+ uint32_t data_len;
+ if (!copy_from_buf(buf, end, &data_len)) {
+ return false;
+ }
+ *size = data_len;
+ *dest = new uint8_t[*size];
+ return copy_from_buf(buf, end, *dest, *size);
+}
+
} // namespace keymaster