Flesh out all remaining message structures, with serialization.
Still didn't implement recsoping messages, since they're not relevant
for 0.3.
Change-Id: Ia05a04349ff0329557b01d14f6c501540cc74439
diff --git a/google_keymaster_utils.cpp b/google_keymaster_utils.cpp
index 89e6968..a877c65 100644
--- a/google_keymaster_utils.cpp
+++ b/google_keymaster_utils.cpp
@@ -18,6 +18,13 @@
namespace keymaster {
+uint8_t* dup_buffer(const void* buf, size_t size) {
+ uint8_t* retval = new uint8_t[size];
+ if (retval != NULL)
+ memcpy(retval, buf, size);
+ return retval;
+}
+
Buffer::~Buffer() {
delete[] buffer_;
}
@@ -71,6 +78,23 @@
return true;
}
+size_t Buffer::SerializedSize() const {
+ return sizeof(uint32_t) + available_read();
+}
+
+uint8_t* Buffer::Serialize(uint8_t* buf, const uint8_t* end) const {
+ return append_size_and_data_to_buf(buf, end, peek_read(), available_read());
+}
+
+bool Buffer::Deserialize(const uint8_t** buf_ptr, const uint8_t* end) {
+ delete[] buffer_;
+ if (!copy_size_and_data_from_buf(buf_ptr, end, &buffer_size_, &buffer_))
+ return false;
+ read_position_ = 0;
+ write_position_ = buffer_size_;
+ return true;
+}
+
int memcmp_s(const void* p1, const void* p2, size_t length) {
const uint8_t* s1 = static_cast<const uint8_t*>(p1);
const uint8_t* s2 = static_cast<const uint8_t*>(p2);