ccollins476ad commented on a change in pull request #68: MYNEWT-720; add 'newt 
resign-image' command.
URL: 
https://github.com/apache/incubator-mynewt-newt/pull/68#discussion_r121754133
 
 

 ##########
 File path: newt/image/image.go
 ##########
 @@ -361,6 +369,65 @@ func (image *Image) sigTlvType() uint8 {
        }
 }
 
+func (image *Image) ReSign() error {
+       srcImg, err := os.Open(image.SourceImg)
+       if err != nil {
+               return util.NewNewtError(fmt.Sprintf("Can't open image file %s: 
%s",
+                       image.SourceImg, err.Error()))
+       }
+
+       srcInfo, err := srcImg.Stat()
+       if err != nil {
+               return util.NewNewtError(fmt.Sprintf("Can't stat image file %s: 
%s",
+                       image.SourceImg, err.Error()))
+       }
+
+       var hdr ImageHdr
+
+       err = binary.Read(srcImg, binary.LittleEndian, &hdr)
+       if err != nil {
+               return util.NewNewtError(fmt.Sprintf("Failing to access image 
%s: %s",
+                       image.SourceImg, err.Error()))
+       }
+
+       if uint32(srcInfo.Size()) != uint32(hdr.HdrSz) + hdr.ImgSz + 
uint32(hdr.TlvSz) ||
+               hdr.Magic != IMAGE_MAGIC {
+
+               return util.NewNewtError(fmt.Sprintf("File %s is not an 
image\n",
+                       image.SourceImg))
+       }
+       srcImg.Seek(int64(hdr.HdrSz), 0)
+
+       log.Debugf("Resigning %s (ver %d.%d.%d.%d)", image.SourceImg,
+               hdr.Vers.Major, hdr.Vers.Minor, hdr.Vers.Rev, hdr.Vers.BuildNum)
+
+        tmpBin, err := ioutil.TempFile("", "")
+       if err != nil {
+               return util.NewNewtError(fmt.Sprintf("Creating temp file 
failed: %s",
+                       err.Error()))
+       }
+       tmpBinName := tmpBin.Name()
+//     defer os.Remove(tmpBinName)
 
 Review comment:
   It might be good to delete this commented-out line for clarity.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to