Refactor Update operation to return amount of input consumed.
Per the keymaster "update" API documentation, implementations need not
consume all provided input, and must return information about how much
they did consume, so the caller knows to resend the unprocessed portion.
It's convenient for the AES OCB mode encryption to sometimes process
less than is provided, but the Update operation interfaces didn't
account for not consuming all data.
This change was already reviewed, merged and reverted, so I'm skipping
the review step this time.
Change-Id: Ida401453a6af6c751ea7093e283a101bd8527709
diff --git a/google_keymaster_messages.cpp b/google_keymaster_messages.cpp
index 79e7e1b..13fb3f2 100644
--- a/google_keymaster_messages.cpp
+++ b/google_keymaster_messages.cpp
@@ -188,15 +188,24 @@
}
size_t UpdateOperationResponse::NonErrorSerializedSize() const {
- return output.SerializedSize();
+ if (message_version == 0)
+ return output.SerializedSize();
+ else
+ return output.SerializedSize() + sizeof(uint32_t);
}
uint8_t* UpdateOperationResponse::NonErrorSerialize(uint8_t* buf, const uint8_t* end) const {
- return output.Serialize(buf, end);
+ buf = output.Serialize(buf, end);
+ if (message_version > 0)
+ buf = append_uint32_to_buf(buf, end, input_consumed);
+ return buf;
}
bool UpdateOperationResponse::NonErrorDeserialize(const uint8_t** buf_ptr, const uint8_t* end) {
- return output.Deserialize(buf_ptr, end);
+ bool retval = output.Deserialize(buf_ptr, end);
+ if (retval && message_version > 0)
+ retval = copy_uint32_from_buf(buf_ptr, end, &input_consumed);
+ return retval;
}
size_t FinishOperationRequest::SerializedSize() const {