Skip to content

Commit

Permalink
don't validate KeyOp
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Jul 4, 2023
1 parent 42d29c5 commit d91d35a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
3 changes: 3 additions & 0 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,22 @@ func Test_intOrStr_CBOR(t *testing.T) {
}

func requireNoError(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Errorf("Unexpected error: %q", err)
t.Fail()
}
}

func assertEqualError(t *testing.T, err error, expected string) {
t.Helper()
if err == nil || err.Error() != expected {
t.Errorf("Unexpected error: want %q, got %q", expected, err)
}
}

func assertEqual(t *testing.T, expected, actual interface{}) {
t.Helper()
if !objectsAreEqualValues(expected, actual) {
t.Errorf("Unexpected value: want %v, got %v", expected, actual)
}
Expand Down
11 changes: 0 additions & 11 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ func (ko KeyOp) String() string {
}
}

// IsSupported returnns true if the specified value is represents one of the
// key_ops defined in
// https://www.rfc-editor.org/rfc/rfc9052.html#name-cose-key-common-parameters
func (ko KeyOp) IsSupported() bool {
return ko >= 1 && ko <= 10
}

// MarshalCBOR marshals the KeyOp as a CBOR int.
func (ko KeyOp) MarshalCBOR() ([]byte, error) {
return encMode.Marshal(int64(ko))
Expand All @@ -141,10 +134,6 @@ func (ko *KeyOp) UnmarshalCBOR(data []byte) error {
} else {
v := raw.Int()
*ko = KeyOp(v)

if !ko.IsSupported() {
return fmt.Errorf("unknown key_ops value %d", v)
}
}

return nil
Expand Down
10 changes: 1 addition & 9 deletions key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,8 @@ func Test_KeyOp(t *testing.T) {

var ko KeyOp

data := []byte{0x20}
data := []byte{0x63, 0x66, 0x6f, 0x6f}
err := ko.UnmarshalCBOR(data)
assertEqualError(t, err, "unknown key_ops value -1")

data = []byte{0x18, 0xff}
err = ko.UnmarshalCBOR(data)
assertEqualError(t, err, "unknown key_ops value 255")

data = []byte{0x63, 0x66, 0x6f, 0x6f}
err = ko.UnmarshalCBOR(data)
assertEqualError(t, err, `unknown key_ops value "foo"`)

data = []byte{0x40}
Expand Down

0 comments on commit d91d35a

Please sign in to comment.