Skip to content

Commit a58706b

Browse files
author
Jon Flatley
committed
[opentitantool] Output OTP image overlays with hex values
Signed-off-by: Jon Flatley <[email protected]>
1 parent 39b6772 commit a58706b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

sw/host/opentitanlib/src/otp/otp_img.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use anyhow::{anyhow, bail, Result};
1212
use serde::de::{self, Unexpected};
1313
use serde::{Deserialize, Serialize};
1414

15-
#[derive(Serialize, Debug, PartialEq, Eq)]
15+
use serde_annotate::Annotate;
16+
17+
#[derive(Annotate, Serialize, Debug, PartialEq, Eq)]
1618
#[serde(untagged)]
1719
pub enum OtpImgValue {
1820
Word(u64),
@@ -90,22 +92,25 @@ impl<'de> Deserialize<'de> for OtpImgValue {
9092
}
9193
}
9294

93-
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
95+
#[derive(Annotate, Serialize, Deserialize, Debug, PartialEq, Eq)]
9496
pub struct OtpImgItem {
9597
pub name: String,
9698
pub value: OtpImgValue,
9799
}
98100

99-
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
101+
#[derive(Annotate, Serialize, Deserialize, Debug, PartialEq, Eq)]
100102
pub struct OtpImgPartition {
101103
pub name: String,
102104
pub items: Option<Vec<OtpImgItem>>,
103105
}
104106

105-
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
107+
#[derive(Annotate, Serialize, Deserialize, Debug, PartialEq, Eq)]
106108
pub struct OtpImg {
107109
#[serde(skip_serializing_if = "Option::is_none")]
108110
pub seed: Option<u64>,
111+
// This attribute shouldn't be here, it should be in `OtpImgValue`, but due to a bug in
112+
// serde_annotate this is needed to get values serialized in hex.
113+
#[annotate(format = hex)]
109114
pub partitions: Vec<OtpImgPartition>,
110115
}
111116

sw/host/opentitantool/src/command/otp.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99

1010
use anyhow::{bail, Result};
1111

12-
use serde_annotate::{serialize, Annotate};
12+
use serde_annotate::{serialize, Annotate, Base};
1313

1414
use structopt::StructOpt;
1515

@@ -91,7 +91,13 @@ impl CommandDispatch for AlertDigest {
9191

9292
if let Some(output) = &self.output {
9393
let mut file = File::create(&output)?;
94-
file.write_all(serialize(&img_out)?.to_json().to_string().as_bytes())?;
94+
file.write_all(
95+
serialize(&img_out)?
96+
.to_json()
97+
.bases(&[Base::Hex])
98+
.to_string()
99+
.as_bytes(),
100+
)?;
95101
Ok(None)
96102
} else {
97103
Ok(Some(Box::new(img_out)))

0 commit comments

Comments
 (0)