Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions cbor/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"math/big"
"reflect"
"sort"
"strings"
)
Expand Down Expand Up @@ -70,16 +71,11 @@ func (v *Value) UnmarshalCBOR(data []byte) error {
v.value = tmpConstr
} else {
// Fall back to standard CBOR tag parsing for our supported types
var tmpTagDecode interface{}
var tmpTagDecode any
if _, err := Decode(data, &tmpTagDecode); err != nil {
return err
}
switch tmpTagDecode.(type) {
case int, uint, int64, uint64, bool, big.Int, WrappedCbor, Rat, Set, Map:
v.value = tmpTagDecode
default:
return fmt.Errorf("unsupported CBOR tag number: %d", tmpTag.Number)
}
v.value = tmpTagDecode
}
default:
var tmpValue interface{}
Expand Down Expand Up @@ -132,14 +128,19 @@ func (v *Value) processMap(data []byte) (err error) {
)
}
}()
tmpValue := map[Value]Value{}
tmpValue := map[*Value]Value{}
if _, err = Decode(data, &tmpValue); err != nil {
return err
}
// Extract actual value from each child value
newValue := map[interface{}]interface{}{}
newValue := map[any]any{}
for key, value := range tmpValue {
newValue[key.Value()] = value.Value()
keyValue := key.Value()
// Use a pointer for unhashable key types
if !reflect.TypeOf(keyValue).Comparable() {
keyValue = &keyValue
}
newValue[keyValue] = value.Value()
}
v.value = newValue
return nil
Expand All @@ -151,7 +152,7 @@ func (v *Value) processArray(data []byte) error {
return err
}
// Extract actual value from each child value
newValue := []interface{}{}
newValue := []any{}
for _, value := range tmpValue {
newValue = append(newValue, value.Value())
}
Expand Down
7 changes: 0 additions & 7 deletions cbor/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ var testDefs = []struct {
expectedObject: nil,
expectedDecodeError: io.ErrUnexpectedEOF,
},
// Invalid map key type
{
cborHex: "A1810000",
expectedDecodeError: fmt.Errorf(
"decode failure, probably due to type unsupported by Go: runtime error: hash of unhashable type []interface {}",
),
},
// [1, 2, 3]
{
cborHex: "83010203",
Expand Down
Loading