From 4fae8b87437a8698d568c5d5fc3b5604383c2b5f Mon Sep 17 00:00:00 2001 From: David Brown Date: Thu, 5 Dec 2019 11:26:59 -0700 Subject: [PATCH] sim: Use 16 bit writes for length fields Previous changes have used 16-bit writes for calculated lengths, but are using a pair of 8-bit writes for hard-coded values. Change these to also use 16-bit writes for consistency, and clarity. Signed-off-by: David Brown --- sim/src/tlv.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sim/src/tlv.rs b/sim/src/tlv.rs index bad91405..187baec8 100644 --- a/sim/src/tlv.rs +++ b/sim/src/tlv.rs @@ -268,8 +268,7 @@ impl ManifestGen for TlvGen { protected_tlv.write_u16::(self.protect_size()).unwrap(); for dep in &self.dependencies { protected_tlv.write_u16::(TlvKinds::DEPENDENCY as u16).unwrap(); - protected_tlv.push(12); - protected_tlv.push(0); + protected_tlv.write_u16::(12).unwrap(); // The dependency. protected_tlv.push(dep.id); @@ -309,8 +308,7 @@ impl ManifestGen for TlvGen { assert!(hash.len() == 32); result.write_u16::(TlvKinds::SHA256 as u16).unwrap(); - result.push(32); - result.push(0); + result.write_u16::(32).unwrap(); result.extend_from_slice(hash); } @@ -329,8 +327,7 @@ impl ManifestGen for TlvGen { assert!(hash.len() == 32); result.write_u16::(TlvKinds::KEYHASH as u16).unwrap(); - result.push(32); - result.push(0); + result.write_u16::(32).unwrap(); result.extend_from_slice(hash); // For now assume PSS. @@ -365,8 +362,7 @@ impl ManifestGen for TlvGen { assert!(keyhash.len() == 32); result.write_u16::(TlvKinds::KEYHASH as u16).unwrap(); - result.push(32); - result.push(0); + result.write_u16::(32).unwrap(); result.extend_from_slice(keyhash); let key_bytes = pem::parse(include_bytes!("../../root-ec-p256-pkcs8.pem").as_ref()).unwrap(); @@ -396,8 +392,7 @@ impl ManifestGen for TlvGen { assert!(keyhash.len() == 32); result.write_u16::(TlvKinds::KEYHASH as u16).unwrap(); - result.push(32); - result.push(0); + result.write_u16::(32).unwrap(); result.extend_from_slice(keyhash); let hash = digest::digest(&digest::SHA256, &sig_payload); @@ -432,8 +427,7 @@ impl ManifestGen for TlvGen { assert!(encbuf.len() == 256); result.write_u16::(TlvKinds::ENCRSA2048 as u16).unwrap(); - result.push(0); - result.push(1); + result.write_u16::(256).unwrap(); result.extend_from_slice(&encbuf); } @@ -450,8 +444,7 @@ impl ManifestGen for TlvGen { assert!(encbuf.len() == 24); result.write_u16::(TlvKinds::ENCKW128 as u16).unwrap(); - result.push(24); - result.push(0); + result.write_u16::(24).unwrap(); result.extend_from_slice(&encbuf); } @@ -516,8 +509,7 @@ impl ManifestGen for TlvGen { assert!(buf.len() == 113); result.write_u16::(TlvKinds::ENCEC256 as u16).unwrap(); - result.push(113); - result.push(0); + result.write_u16::(113).unwrap(); result.extend_from_slice(&buf); }