Add GetVersion to GoogleKeymaster implementation.

The GetVersion command will be used by the GoogleKeymaster HAL
implementation to verify that HAL implementation and keymaster
implementation are compatible.  Note that the GetVersion API is not
exposed through the HAL, and there's no requirement that other keymaster
implementations provide versioning (it's a good idea, though).

This change also enables message versioning support.

Bug: 18409838
Change-Id: Ia22791356db3453deab4c21f06a16a08fac32d0e
diff --git a/google_keymaster_messages.cpp b/google_keymaster_messages.cpp
index 90c22f4..79e7e1b 100644
--- a/google_keymaster_messages.cpp
+++ b/google_keymaster_messages.cpp
@@ -336,4 +336,30 @@
     return true;
 }
 
+size_t GetVersionResponse::NonErrorSerializedSize() const {
+    return sizeof(major_ver) + sizeof(minor_ver) + sizeof(subminor_ver);
+}
+
+uint8_t* GetVersionResponse::NonErrorSerialize(uint8_t* buf, const uint8_t* end) const {
+    if (buf + NonErrorSerializedSize() <= end) {
+        *buf++ = major_ver;
+        *buf++ = minor_ver;
+        *buf++ = subminor_ver;
+    } else {
+        buf += NonErrorSerializedSize();
+    }
+    return buf;
+}
+
+bool GetVersionResponse::NonErrorDeserialize(const uint8_t** buf_ptr, const uint8_t* end) {
+    if (*buf_ptr + NonErrorSerializedSize() > end)
+        return false;
+    const uint8_t* tmp = *buf_ptr;
+    major_ver = *tmp++;
+    minor_ver = *tmp++;
+    subminor_ver = *tmp++;
+    *buf_ptr = tmp;
+    return true;
+}
+
 }  // namespace keymaster