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/10/24 16:45:21 UTC

[mynewt-artifact] 05/06: sec: function to get the hash from a signing key

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 03992ce9f73dbccfc7d1f9206b2035a79b0c124e
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Oct 23 14:59:09 2019 -0700

    sec: function to get the hash from a signing key
    
    func (key *PubSignKey) Hash() ([]byte, error)
    
    This is just a convenience function.
---
 sec/sign.go | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/sec/sign.go b/sec/sign.go
index 01a9cad..a718c8b 100644
--- a/sec/sign.go
+++ b/sec/sign.go
@@ -338,12 +338,20 @@ func (key *PubSignKey) SigType() (SigType, error) {
 	return 0, errors.Errorf("invalid key: no non-nil members")
 }
 
+func (key *PubSignKey) Hash() ([]byte, error) {
+	pubBytes, err := key.Bytes()
+	if err != nil {
+		return nil, errors.WithStack(err)
+	}
+
+	return RawKeyHash(pubBytes), nil
+}
+
 func checkOneKeyOneSig(k PubSignKey, sig Sig, hash []byte) (bool, error) {
-	pubBytes, err := k.Bytes()
+	keyHash, err := k.Hash()
 	if err != nil {
-		return false, errors.WithStack(err)
+		return false, err
 	}
-	keyHash := RawKeyHash(pubBytes)
 
 	if !bytes.Equal(keyHash, sig.KeyHash) {
 		return false, nil