Place TLV size into TLV itself

To allow the signatures to be replaced, move the size of the TLV into a
small "info" header at the start of the TLV.

Note that this causes image swapping to lose robustness.  This is fixed
by a later commit.

Based on work by Marko Kiiskila <marko@runtime.io>

Signed-off-by: Marko Kiiskila <marko@runtime.io>
Signed-off-by: David Brown <david.brown@linaro.org>
JIRA: MCUB-65
diff --git a/sim/src/tlv.rs b/sim/src/tlv.rs
index c9e4a6d..f2191f6 100644
--- a/sim/src/tlv.rs
+++ b/sim/src/tlv.rs
@@ -60,7 +60,7 @@
 
     /// Retrieve the size that the TLV will occupy.  This can be called at any time.
     pub fn get_size(&self) -> u16 {
-        self.size
+        4 + self.size
     }
 
     /// Add bytes to the covered hash.
@@ -72,6 +72,12 @@
     pub fn make_tlv(self) -> Vec<u8> {
         let mut result: Vec<u8> = vec![];
 
+        let size = self.get_size();
+        result.push(0x07);
+        result.push(0x69);
+        result.push((size & 0xFF) as u8);
+        result.push(((size >> 8) & 0xFF) as u8);
+
         if self.kinds.contains(&TlvKinds::SHA256) {
             let hash = digest::digest(&digest::SHA256, &self.payload);
             let hash = hash.as_ref();