From ac5da928934abf64e461a17a9e6495072fc6ce91 Mon Sep 17 00:00:00 2001 From: Yogesh Deshpande Date: Tue, 6 Feb 2024 09:44:25 -0500 Subject: [PATCH] Address some of the comments Signed-off-by: Yogesh Deshpande --- comid/integrityregisters.go | 17 ++++++++--------- comid/integrityregisters_test.go | 12 +++++------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/comid/integrityregisters.go b/comid/integrityregisters.go index 1daf3cf0..e8df59f3 100644 --- a/comid/integrityregisters.go +++ b/comid/integrityregisters.go @@ -17,12 +17,11 @@ type IRegisterIndex interface{} // IntegrityRegisters holds the Integrity Registers type IntegrityRegisters struct { - Register map[IRegisterIndex]Digests + m map[IRegisterIndex]Digests } func NewIntegrityRegisters() *IntegrityRegisters { - reg := make(map[IRegisterIndex]Digests) - return &IntegrityRegisters{Register: reg} + return &IntegrityRegisters{m: make(map[IRegisterIndex]Digests)} } // AddDigests allows inserting a series of Digests at a specific RegisterIndex @@ -38,15 +37,15 @@ func (i *IntegrityRegisters) AddDigests(index IRegisterIndex, digests Digests) e return nil } -// AddDigest allows inserting a Digest at a specific RegisterIndex +// AddDigest allows inserting a Digest at a specific registerIndex func (i *IntegrityRegisters) AddDigest(index IRegisterIndex, digest swid.HashEntry) error { - if i.Register == nil { + if i.m == nil { return fmt.Errorf("no register to add digest") } switch t := index.(type) { case string, uint, uint64: - i.Register[t] = append(i.Register[t], digest) + i.m[t] = append(i.m[t], digest) default: return fmt.Errorf("unexpected type for index: %T", t) } @@ -54,11 +53,11 @@ func (i *IntegrityRegisters) AddDigest(index IRegisterIndex, digest swid.HashEnt } func (i IntegrityRegisters) MarshalCBOR() ([]byte, error) { - return em.Marshal(i.Register) + return em.Marshal(i.m) } func (i *IntegrityRegisters) UnmarshalCBOR(data []byte) error { - return dm.Unmarshal(data, &i.Register) + return dm.Unmarshal(data, &i.m) } type keyTypeandVal struct { @@ -69,7 +68,7 @@ type keyTypeandVal struct { func (i IntegrityRegisters) MarshalJSON() ([]byte, error) { jmap := make(map[string]json.RawMessage) var newkey string - for key, val := range i.Register { + for key, val := range i.m { var ktv keyTypeandVal switch t := key.(type) { case uint, uint64: diff --git a/comid/integrityregisters_test.go b/comid/integrityregisters_test.go index f8a3279a..71cf186c 100644 --- a/comid/integrityregisters_test.go +++ b/comid/integrityregisters_test.go @@ -70,7 +70,6 @@ func TestIntegrityRegisters_MarshalCBOR_UIntIndex_OK(t *testing.T) { bytes, err := reg.MarshalCBOR() require.NoError(t, err) fmt.Printf("CBOR Payload = %x", bytes) - } func TestIntegrityRegisters_UnmarshalCBOR_UIntIndex_OK(t *testing.T) { @@ -78,7 +77,7 @@ func TestIntegrityRegisters_UnmarshalCBOR_UIntIndex_OK(t *testing.T) { reg := NewIntegrityRegisters() err := reg.UnmarshalCBOR(bstr) require.NoError(t, err) - for index, digests := range reg.Register { + for index, digests := range reg.m { _, ok := index.(uint64) assert.True(t, ok) err = digests.Valid() @@ -100,7 +99,6 @@ func TestIntegrityRegisters_MarshalCBOR_TextIndex_OK(t *testing.T) { bytes, err := reg.MarshalCBOR() require.NoError(t, err) fmt.Printf("CBOR Payload = %x", bytes) - } func TestIntegrityRegisters_UnmarshalCBOR_TextIndex_OK(t *testing.T) { @@ -108,7 +106,7 @@ func TestIntegrityRegisters_UnmarshalCBOR_TextIndex_OK(t *testing.T) { reg := NewIntegrityRegisters() err := reg.UnmarshalCBOR(bstr) require.NoError(t, err) - for index, digests := range reg.Register { + for index, digests := range reg.m { _, ok := index.(string) assert.True(t, ok) err = digests.Valid() @@ -129,7 +127,7 @@ func TestIntegrityRegisters_UnmarshalJSON_TextIndex_OK(t *testing.T) { reg := NewIntegrityRegisters() err := reg.UnmarshalJSON([]byte(j)) require.NoError(t, err) - for index, digests := range reg.Register { + for index, digests := range reg.m { _, ok := index.(string) assert.True(t, ok) err = digests.Valid() @@ -149,7 +147,7 @@ func TestIntegrityRegisters_UnmarshalJSON_UIntIndex_OK(t *testing.T) { reg := NewIntegrityRegisters() err := reg.UnmarshalJSON([]byte(j)) require.NoError(t, err) - for index, digests := range reg.Register { + for index, digests := range reg.m { _, ok := index.(uint) assert.True(t, ok) err = digests.Valid() @@ -168,7 +166,7 @@ func TestIntegrityRegisters_UnmarshalJSON_TextUInt_Index_OK(t *testing.T) { reg := NewIntegrityRegisters() err := reg.UnmarshalJSON([]byte(j)) require.NoError(t, err) - for index, digests := range reg.Register { + for index, digests := range reg.m { _, uok := index.(uint) _, sok := index.(string) assert.True(t, (uok || sok))