Skip to content

Commit 48c624e

Browse files
committed
fwidgen: Include string identifier for the digest in output.
1 parent 05a25f4 commit 48c624e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

fwidgen/src/main.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clap::{Parser, ValueEnum};
77
use hubtools::RawHubrisArchive;
88
use sha2::{digest::DynDigest, Digest as _, Sha256};
99
use sha3::Sha3_256;
10-
use std::{ops::Range, str};
10+
use std::{fmt, ops::Range, str};
1111

1212
pub const LPC55_FLASH_PAGE_SIZE: usize = 512;
1313

@@ -43,6 +43,17 @@ enum Digest {
4343
Sha3_256,
4444
}
4545

46+
// Display string names for digest algorithms from IANA named information
47+
// hash algorithm registry
48+
impl fmt::Display for Digest {
49+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50+
match self {
51+
Self::Sha256 => write!(f, "sha-256"),
52+
Self::Sha3_256 => write!(f, "sha3-256"),
53+
}
54+
}
55+
}
56+
4657
impl Digest {
4758
fn to_dyn_digest(&self) -> Box<dyn DynDigest> {
4859
match self {
@@ -203,7 +214,10 @@ fn main() -> Result<()> {
203214

204215
let digest = digest.finalize();
205216

206-
println!("{}", hex::encode(digest));
217+
// Display FWID as the string name for the digest from IANA registry and
218+
// the output from the selected digest encoded as hex & separated by a
219+
// `;`.
220+
println!("{};{}", args.digest, hex::encode(digest));
207221

208222
Ok(())
209223
}

0 commit comments

Comments
 (0)