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 <david.brown@linaro.org>
This commit is contained in:
parent
6972118ce3
commit
4fae8b8743
|
@ -268,8 +268,7 @@ impl ManifestGen for TlvGen {
|
||||||
protected_tlv.write_u16::<LittleEndian>(self.protect_size()).unwrap();
|
protected_tlv.write_u16::<LittleEndian>(self.protect_size()).unwrap();
|
||||||
for dep in &self.dependencies {
|
for dep in &self.dependencies {
|
||||||
protected_tlv.write_u16::<LittleEndian>(TlvKinds::DEPENDENCY as u16).unwrap();
|
protected_tlv.write_u16::<LittleEndian>(TlvKinds::DEPENDENCY as u16).unwrap();
|
||||||
protected_tlv.push(12);
|
protected_tlv.write_u16::<LittleEndian>(12).unwrap();
|
||||||
protected_tlv.push(0);
|
|
||||||
|
|
||||||
// The dependency.
|
// The dependency.
|
||||||
protected_tlv.push(dep.id);
|
protected_tlv.push(dep.id);
|
||||||
|
@ -309,8 +308,7 @@ impl ManifestGen for TlvGen {
|
||||||
|
|
||||||
assert!(hash.len() == 32);
|
assert!(hash.len() == 32);
|
||||||
result.write_u16::<LittleEndian>(TlvKinds::SHA256 as u16).unwrap();
|
result.write_u16::<LittleEndian>(TlvKinds::SHA256 as u16).unwrap();
|
||||||
result.push(32);
|
result.write_u16::<LittleEndian>(32).unwrap();
|
||||||
result.push(0);
|
|
||||||
result.extend_from_slice(hash);
|
result.extend_from_slice(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,8 +327,7 @@ impl ManifestGen for TlvGen {
|
||||||
|
|
||||||
assert!(hash.len() == 32);
|
assert!(hash.len() == 32);
|
||||||
result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
|
result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
|
||||||
result.push(32);
|
result.write_u16::<LittleEndian>(32).unwrap();
|
||||||
result.push(0);
|
|
||||||
result.extend_from_slice(hash);
|
result.extend_from_slice(hash);
|
||||||
|
|
||||||
// For now assume PSS.
|
// For now assume PSS.
|
||||||
|
@ -365,8 +362,7 @@ impl ManifestGen for TlvGen {
|
||||||
|
|
||||||
assert!(keyhash.len() == 32);
|
assert!(keyhash.len() == 32);
|
||||||
result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
|
result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
|
||||||
result.push(32);
|
result.write_u16::<LittleEndian>(32).unwrap();
|
||||||
result.push(0);
|
|
||||||
result.extend_from_slice(keyhash);
|
result.extend_from_slice(keyhash);
|
||||||
|
|
||||||
let key_bytes = pem::parse(include_bytes!("../../root-ec-p256-pkcs8.pem").as_ref()).unwrap();
|
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);
|
assert!(keyhash.len() == 32);
|
||||||
result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
|
result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
|
||||||
result.push(32);
|
result.write_u16::<LittleEndian>(32).unwrap();
|
||||||
result.push(0);
|
|
||||||
result.extend_from_slice(keyhash);
|
result.extend_from_slice(keyhash);
|
||||||
|
|
||||||
let hash = digest::digest(&digest::SHA256, &sig_payload);
|
let hash = digest::digest(&digest::SHA256, &sig_payload);
|
||||||
|
@ -432,8 +427,7 @@ impl ManifestGen for TlvGen {
|
||||||
|
|
||||||
assert!(encbuf.len() == 256);
|
assert!(encbuf.len() == 256);
|
||||||
result.write_u16::<LittleEndian>(TlvKinds::ENCRSA2048 as u16).unwrap();
|
result.write_u16::<LittleEndian>(TlvKinds::ENCRSA2048 as u16).unwrap();
|
||||||
result.push(0);
|
result.write_u16::<LittleEndian>(256).unwrap();
|
||||||
result.push(1);
|
|
||||||
result.extend_from_slice(&encbuf);
|
result.extend_from_slice(&encbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,8 +444,7 @@ impl ManifestGen for TlvGen {
|
||||||
|
|
||||||
assert!(encbuf.len() == 24);
|
assert!(encbuf.len() == 24);
|
||||||
result.write_u16::<LittleEndian>(TlvKinds::ENCKW128 as u16).unwrap();
|
result.write_u16::<LittleEndian>(TlvKinds::ENCKW128 as u16).unwrap();
|
||||||
result.push(24);
|
result.write_u16::<LittleEndian>(24).unwrap();
|
||||||
result.push(0);
|
|
||||||
result.extend_from_slice(&encbuf);
|
result.extend_from_slice(&encbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,8 +509,7 @@ impl ManifestGen for TlvGen {
|
||||||
|
|
||||||
assert!(buf.len() == 113);
|
assert!(buf.len() == 113);
|
||||||
result.write_u16::<LittleEndian>(TlvKinds::ENCEC256 as u16).unwrap();
|
result.write_u16::<LittleEndian>(TlvKinds::ENCEC256 as u16).unwrap();
|
||||||
result.push(113);
|
result.write_u16::<LittleEndian>(113).unwrap();
|
||||||
result.push(0);
|
|
||||||
result.extend_from_slice(&buf);
|
result.extend_from_slice(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue