From 7cfc7170896294c0eec848242d5ad9fc4cb5e9d5 Mon Sep 17 00:00:00 2001 From: jaketaylor <jake@privategrity.com> Date: Wed, 4 Mar 2020 13:33:50 -0800 Subject: [PATCH] removed error return from ndf.Compare --- network/dataStructures/ndf.go | 21 ++++----------------- network/dataStructures/ndf_test.go | 14 ++------------ network/securedNdf.go | 2 +- network/securedNdf_test.go | 2 +- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/network/dataStructures/ndf.go b/network/dataStructures/ndf.go index 4945727e..c6490bea 100644 --- a/network/dataStructures/ndf.go +++ b/network/dataStructures/ndf.go @@ -90,26 +90,13 @@ func (file *Ndf) GetPb() *pb.NDF { return file.pb } -//evaluates if the passed ndf hash is the same as the stored one -//returns an error if no ndf is available, returns false if they are different -//and true if they are the same -func (file *Ndf) CompareHash(h []byte) (bool, error) { +// Evaluates if the passed ndf hash is the same as the stored one +func (file *Ndf) CompareHash(h []byte) bool { file.lock.RLock() defer file.lock.RUnlock() - //return the NO_NDF error if no NDF is available - if len(file.hash) == 0 { - errMsg := errors.Errorf(ndf.NO_NDF) - return false, errMsg - } - - //return true if the hashes are the same - if bytes.Compare(file.hash, h) == 0 { - return true, nil - } - - //return false if the hashes are different - return false, nil + // Return whether the hashes are different + return bytes.Compare(file.hash, h) == 0 } // helper function to generate a hash of the NDF diff --git a/network/dataStructures/ndf_test.go b/network/dataStructures/ndf_test.go index 8fd9c500..99940fd7 100644 --- a/network/dataStructures/ndf_test.go +++ b/network/dataStructures/ndf_test.go @@ -72,25 +72,15 @@ func TestNdf_GetPb(t *testing.T) { func TestNdf_CompareHash(t *testing.T) { ndf := &Ndf{} - _, err := ndf.CompareHash([]byte("test")) - if err == nil { - t.Error("CompareHash should error when it has no ndf") - } ndf = setup() - b, err := ndf.CompareHash(ndf.hash) + b := ndf.CompareHash(ndf.hash) if !b { t.Error("Should return true when hashes are the same") } - if err != nil { - t.Errorf("Returned error comparing identical ndfs: %+v", err) - } - b, err = ndf.CompareHash([]byte("test")) + b = ndf.CompareHash([]byte("test")) if b { t.Error("Should return false when hashes are different") } - if err != nil { - t.Errorf("Should not error when hashes are different: %+v", err) - } } diff --git a/network/securedNdf.go b/network/securedNdf.go index 831b75a3..34cc6a4b 100644 --- a/network/securedNdf.go +++ b/network/securedNdf.go @@ -60,6 +60,6 @@ func (sndf *SecuredNdf) GetPb() *pb.NDF { } // Compare a hash to the stored -func (sndf *SecuredNdf) CompareHash(h []byte) (bool, error) { +func (sndf *SecuredNdf) CompareHash(h []byte) bool { return sndf.f.CompareHash(h) } diff --git a/network/securedNdf_test.go b/network/securedNdf_test.go index 3cb10291..e03e7e70 100644 --- a/network/securedNdf_test.go +++ b/network/securedNdf_test.go @@ -107,7 +107,7 @@ func TestSecuredNdf_GetHash(t *testing.T) { func TestSecuredNdf_CompareHash(t *testing.T) { sn := SecuredNdf{f: setup()} - b, _ := sn.CompareHash(sn.f.GetHash()) + b := sn.CompareHash(sn.f.GetHash()) if !b { t.Error("Should have received true for comparison") } -- GitLab