You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/06/20 17:42:24 UTC

[mynewt-artifact] 12/12: artifact: add image.CalcHash() function

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-artifact.git

commit db596e7f6825de31b6f2091741c8841362d4a1f3
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri May 24 12:37:22 2019 -0700

    artifact: add image.CalcHash() function
    
    Prior to this commit, the only way to calculate an image's hash was to
    use image.calcHash() (in `artifact/image/create.go`).  This function is
    private to the `image` package, and it takes a set of parameters that
    are is not convenient for most cases.
    
    This commit adds a new public function to the `image.Image` type:
    ```
    func (i *Image) CalcHash() ([]byte, error)
    ```
---
 image/image.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/image/image.go b/image/image.go
index 7f74cbc..9855223 100644
--- a/image/image.go
+++ b/image/image.go
@@ -348,6 +348,10 @@ func (i *Image) Hash() ([]byte, error) {
 	return tlv.Data, nil
 }
 
+func (i *Image) CalcHash() ([]byte, error) {
+	return calcHash(nil, i.Header, i.Pad, i.Body)
+}
+
 func (i *Image) WritePlusOffsets(w io.Writer) (ImageOffsets, error) {
 	offs := ImageOffsets{}
 	offset := 0