@@ -7,7 +7,7 @@ use clap::{Parser, ValueEnum};
7
7
use hubtools:: RawHubrisArchive ;
8
8
use sha2:: { digest:: DynDigest , Digest as _, Sha256 } ;
9
9
use sha3:: Sha3_256 ;
10
- use std:: { ops:: Range , str} ;
10
+ use std:: { fmt , ops:: Range , str} ;
11
11
12
12
pub const LPC55_FLASH_PAGE_SIZE : usize = 512 ;
13
13
@@ -43,6 +43,17 @@ enum Digest {
43
43
Sha3_256 ,
44
44
}
45
45
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
+
46
57
impl Digest {
47
58
fn to_dyn_digest ( & self ) -> Box < dyn DynDigest > {
48
59
match self {
@@ -203,7 +214,10 @@ fn main() -> Result<()> {
203
214
204
215
let digest = digest. finalize ( ) ;
205
216
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) ) ;
207
221
208
222
Ok ( ( ) )
209
223
}
0 commit comments