Skip to content

Commit

Permalink
Consolidate API names related to Key (#161)
Browse files Browse the repository at this point in the history
Signed-off-by: qmuntal <[email protected]>
  • Loading branch information
qmuntal authored Aug 1, 2023
1 parent a5dc571 commit 160b7e0
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 196 deletions.
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

0 comments on commit 160b7e0

Please sign in to comment.