diff --git a/network/dataStructures/ndf.go b/network/dataStructures/ndf.go index 4945727e97bfe167ddb0c3a78a7c3da53a953015..c6490bea831e64f05e71cff42414392ad88480c4 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 8fd9c500e7f0bdf120141ec64a438d5110e09f10..99940fd74be02bae662284f99f9b430331d05c73 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 831b75a3f1d08ac7285fe8f7f369dd2d5cc33ddb..34cc6a4b48aedfac7a46aef0c5bc55b8922d9e14 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 3cb102915f022af5fca3d69aa8b8a326b7cfd25d..e03e7e70ad54270fcc25000a81c5d0f4a969e6bd 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") }