This is an automated email from the ASF dual-hosted git repository. ccollins pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-imgmod.git
commit 9e6ead5589ee76080c961ab86c0f24a0bafd1056 Author: Christopher Collins <ccoll...@apache.org> AuthorDate: Fri Feb 28 16:23:30 2020 -0800 image hashable: Include padding and protected TLVs Header padding and protected TLVs are inputs during hash calculation. Update the `image hashable` command to account for this. --- cli/image_cmds.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/cli/image_cmds.go b/cli/image_cmds.go index 2b75b59..9dcb171 100644 --- a/cli/image_cmds.go +++ b/cli/image_cmds.go @@ -323,14 +323,43 @@ func runHashableCmd(cmd *cobra.Command, args []string) { } defer f.Close() - if err := binary.Write(f, binary.LittleEndian, &img.Header); err != nil { + err = binary.Write(f, binary.LittleEndian, &img.Header) + if err != nil { ImgmodUsage(nil, errors.Wrapf(err, "error writing image header")) } + + _, err = f.Write(img.Pad) + if err != nil { + ImgmodUsage(nil, errors.Wrapf(err, "error writing image padding")) + } + _, err = f.Write(img.Body) if err != nil { ImgmodUsage(nil, errors.Wrapf(err, "error writing image body")) } + if len(img.ProtTlvs) > 0 { + trailer := image.ImageTrailer{ + Magic: image.IMAGE_PROT_TRAILER_MAGIC, + TlvTotLen: img.Header.ProtSz, + } + err = binary.Write(f, binary.LittleEndian, trailer) + if err != nil { + ImgmodUsage(nil, errors.Wrapf(err, "error writing image protected TLV trailer")) + } + + for _, t := range img.ProtTlvs { + err = binary.Write(f, binary.LittleEndian, t.Header) + if err != nil { + ImgmodUsage(nil, errors.Wrapf(err, "error writing image protected TLVs")) + } + _, err = f.Write(t.Data) + if err != nil { + ImgmodUsage(nil, errors.Wrapf(err, "error writing image protected TLVs")) + } + } + } + iutil.Printf("Wrote hashable content to %s\n", outFilename) }