Skip to content

Commit

Permalink
Some more fixes!
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Feb 5, 2024
1 parent b9a212f commit ef048bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions comid/integrityregisters.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func (i *IntegrityRegisters) UnmarshalJSON(data []byte) error {
for key, val := range jmap {
index, err := unmarshalIndex(key)
if err != nil {
return fmt.Errorf("unable to unMarshal index: %w", err)
return fmt.Errorf("unable to unmarshal index: %w", err)
}
var d Digests

if err = json.Unmarshal(val, &d); err != nil {
return fmt.Errorf("unable to UnMarshal Digests: %w", err)
return fmt.Errorf("unable to unmarshal Digests: %w", err)
}
if err = i.AddDigests(index, d); err != nil {
return fmt.Errorf("unable to insert register into register set: %w", err)
Expand All @@ -117,19 +117,19 @@ func (i *IntegrityRegisters) UnmarshalJSON(data []byte) error {
func unmarshalIndex(key string) (IRegisterIndex, error) {
var v tnv
if err := json.Unmarshal([]byte(key), &v); err != nil {
return nil, fmt.Errorf("unable to unMarshal key: %w", err)
return nil, fmt.Errorf("unable to unmarshal key: %w", err)
}
switch v.Type {
case "uint":
var key uint
if err := json.Unmarshal(v.Value, &key); err != nil {
return nil, fmt.Errorf("unable to unMarshal uint key: %w", err)
return nil, fmt.Errorf("unable to unmarshal uint key: %w", err)
}
return key, nil
case "text":
var key string
if err := json.Unmarshal(v.Value, &key); err != nil {
return nil, fmt.Errorf("unable to unMarshal uint key: %w", err)
return nil, fmt.Errorf("unable to unmarshal uint key: %w", err)
}
return key, nil
default:
Expand Down
4 changes: 2 additions & 2 deletions comid/integrityregisters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ func TestIntegrityRegisters_UnmarshalJSON_InvalidIndex(t *testing.T) {
{
Name: "invalid input integer",
Input: `{"{\"type\":\"int\",\"value\":0}":["sha-384;MTI0MzU0NjU4Njk3OTA4MDEyNDM1NDY1ODY5NzkwODAxMjQzNTQ2NTg2OTc5MDgw"]}`,
Err: "unable to unMarshal index: invalid type: int",
Err: "unable to unmarshal index: invalid type: int",
},
{
Name: "invalid type",
Input: `{"{abcd}":["sha-384;MTI0MzU0NjU4Njk3OTA4MDEyNDM1NDY1ODY5NzkwODAxMjQzNTQ2NTg2OTc5MDgw"]}`,
Err: `unable to unMarshal index: unable to unMarshal key: invalid character 'a' looking for beginning of object key string`,
Err: `unable to unmarshal index: unable to unmarshal key: invalid character 'a' looking for beginning of object key string`,
},
} {
t.Run(tv.Name, func(t *testing.T) {
Expand Down

0 comments on commit ef048bb

Please sign in to comment.