Skip to content
Snippets Groups Projects
Commit 7cfc7170 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

removed error return from ndf.Compare

parent 020ff58f
Branches
Tags
No related merge requests found
...@@ -90,26 +90,13 @@ func (file *Ndf) GetPb() *pb.NDF { ...@@ -90,26 +90,13 @@ func (file *Ndf) GetPb() *pb.NDF {
return file.pb return file.pb
} }
//evaluates if the passed ndf hash is the same as the stored one // 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 func (file *Ndf) CompareHash(h []byte) bool {
//and true if they are the same
func (file *Ndf) CompareHash(h []byte) (bool, error) {
file.lock.RLock() file.lock.RLock()
defer file.lock.RUnlock() defer file.lock.RUnlock()
//return the NO_NDF error if no NDF is available // Return whether the hashes are different
if len(file.hash) == 0 { return bytes.Compare(file.hash, h) == 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
} }
// helper function to generate a hash of the NDF // helper function to generate a hash of the NDF
......
...@@ -72,25 +72,15 @@ func TestNdf_GetPb(t *testing.T) { ...@@ -72,25 +72,15 @@ func TestNdf_GetPb(t *testing.T) {
func TestNdf_CompareHash(t *testing.T) { func TestNdf_CompareHash(t *testing.T) {
ndf := &Ndf{} ndf := &Ndf{}
_, err := ndf.CompareHash([]byte("test"))
if err == nil {
t.Error("CompareHash should error when it has no ndf")
}
ndf = setup() ndf = setup()
b, err := ndf.CompareHash(ndf.hash) b := ndf.CompareHash(ndf.hash)
if !b { if !b {
t.Error("Should return true when hashes are the same") 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 { if b {
t.Error("Should return false when hashes are different") t.Error("Should return false when hashes are different")
} }
if err != nil {
t.Errorf("Should not error when hashes are different: %+v", err)
}
} }
...@@ -60,6 +60,6 @@ func (sndf *SecuredNdf) GetPb() *pb.NDF { ...@@ -60,6 +60,6 @@ func (sndf *SecuredNdf) GetPb() *pb.NDF {
} }
// Compare a hash to the stored // 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) return sndf.f.CompareHash(h)
} }
...@@ -107,7 +107,7 @@ func TestSecuredNdf_GetHash(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestSecuredNdf_GetHash(t *testing.T) {
func TestSecuredNdf_CompareHash(t *testing.T) { func TestSecuredNdf_CompareHash(t *testing.T) {
sn := SecuredNdf{f: setup()} sn := SecuredNdf{f: setup()}
b, _ := sn.CompareHash(sn.f.GetHash()) b := sn.CompareHash(sn.f.GetHash())
if !b { if !b {
t.Error("Should have received true for comparison") t.Error("Should have received true for comparison")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment