Skip to content

Commit

Permalink
Removing some lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Feb 6, 2024
1 parent b4a6a5a commit 8257db6
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions comid/integrityregisters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/veraison/swid"
)

const TextType = "text"

// IRegisterIndex is the interface to hold register index
type IRegisterIndex interface{}

Expand Down Expand Up @@ -60,8 +62,8 @@ func (i *IntegrityRegisters) UnmarshalCBOR(data []byte) error {
}

type keyTypeandVal struct {
Key_type string `json:"key_type"`
Value json.RawMessage
KeyType string `json:"key_type"`
Value json.RawMessage
}

func (i IntegrityRegisters) MarshalJSON() ([]byte, error) {
Expand All @@ -71,10 +73,10 @@ func (i IntegrityRegisters) MarshalJSON() ([]byte, error) {
var ktv keyTypeandVal
switch t := key.(type) {
case uint, uint64:
ktv.Key_type = "uint"
ktv.KeyType = UintType
newkey = fmt.Sprintf("%v", key)
case string:
ktv.Key_type = "text"
ktv.KeyType = TextType
newkey = key.(string)
default:
return nil, fmt.Errorf("unknown type %T for index-type-choice", t)
Expand Down Expand Up @@ -110,19 +112,19 @@ func (i *IntegrityRegisters) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(ktv.Value, &d); err != nil {
return fmt.Errorf("unable to unmarshal Digest: %w", err)
}
switch ktv.Key_type {
case "uint":
switch ktv.KeyType {
case UintType:
u, err := strconv.Atoi(key)
if err != nil {
return fmt.Errorf("unable to convert key to uint: %v", err)
} else if u < 0 {
return fmt.Errorf("invalid negative integer key")
}
index = uint(u)
case "text":
case TextType:
index = key
default:
return fmt.Errorf("unexpected key type for index: %s", ktv.Key_type)
return fmt.Errorf("unexpected key type for index: %s", ktv.KeyType)
}
if err := i.AddDigests(index, d); err != nil {
return fmt.Errorf("unable to add digests into register set: %w", err)
Expand Down

0 comments on commit 8257db6

Please sign in to comment.