Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate API names related to Key #161

Merged
merged 6 commits into from
Aug 1, 2023
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
6 changes: 4 additions & 2 deletions algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const (
// PureEdDSA by RFC 8152.
AlgorithmEdDSA Algorithm = -8

// An invalid/unrecognised algorithm.
AlgorithmInvalid Algorithm = 0
// Reserved value.
AlgorithmReserved Algorithm = 0
)

// Algorithm represents an IANA algorithm entry in the COSE Algorithms registry.
Expand Down Expand Up @@ -75,6 +75,8 @@ func (a Algorithm) String() string {
// As stated in RFC 8152 8.2, only the pure EdDSA version is used for
// COSE.
return "EdDSA"
case AlgorithmReserved:
return "Reserved"
default:
return "unknown algorithm value " + strconv.Itoa(int(a))
}
Expand Down
17 changes: 10 additions & 7 deletions algorithm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ import (
func TestAlgorithm_String(t *testing.T) {
// run tests
tests := []struct {
name string
alg Algorithm
want string
}{
{
name: "unknown algorithm",
alg: 0,
want: "unknown algorithm value 0",
},
{AlgorithmPS256, "PS256"},
{AlgorithmPS384, "PS384"},
{AlgorithmPS512, "PS512"},
{AlgorithmES256, "ES256"},
{AlgorithmES384, "ES384"},
{AlgorithmES512, "ES512"},
{AlgorithmEdDSA, "EdDSA"},
{AlgorithmReserved, "Reserved"},
{7, "unknown algorithm value 7"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Run(tt.want, func(t *testing.T) {
if got := tt.alg.String(); got != tt.want {
t.Errorf("Algorithm.String() = %v, want %v", got, tt.want)
}
Expand Down
4 changes: 2 additions & 2 deletions headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func (h ProtectedHeader) Algorithm() (Algorithm, error) {
case int64:
return Algorithm(alg), nil
case string:
return AlgorithmInvalid, fmt.Errorf("unknown algorithm value %q", alg)
return AlgorithmReserved, fmt.Errorf("unknown algorithm value %q", alg)
default:
return AlgorithmInvalid, ErrInvalidAlgorithm
return AlgorithmReserved, ErrInvalidAlgorithm
}
}

Expand Down
Loading