Skip to content

Commit 160b7e0

Browse files
authored
Consolidate API names related to Key (#161)
Signed-off-by: qmuntal <[email protected]>
1 parent a5dc571 commit 160b7e0

File tree

5 files changed

+208
-196
lines changed

5 files changed

+208
-196
lines changed

algorithm.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ const (
4343
// PureEdDSA by RFC 8152.
4444
AlgorithmEdDSA Algorithm = -8
4545

46-
// An invalid/unrecognised algorithm.
47-
AlgorithmInvalid Algorithm = 0
46+
// Reserved value.
47+
AlgorithmReserved Algorithm = 0
4848
)
4949

5050
// Algorithm represents an IANA algorithm entry in the COSE Algorithms registry.
@@ -75,6 +75,8 @@ func (a Algorithm) String() string {
7575
// As stated in RFC 8152 8.2, only the pure EdDSA version is used for
7676
// COSE.
7777
return "EdDSA"
78+
case AlgorithmReserved:
79+
return "Reserved"
7880
default:
7981
return "unknown algorithm value " + strconv.Itoa(int(a))
8082
}

algorithm_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ import (
1212
func TestAlgorithm_String(t *testing.T) {
1313
// run tests
1414
tests := []struct {
15-
name string
1615
alg Algorithm
1716
want string
1817
}{
19-
{
20-
name: "unknown algorithm",
21-
alg: 0,
22-
want: "unknown algorithm value 0",
23-
},
18+
{AlgorithmPS256, "PS256"},
19+
{AlgorithmPS384, "PS384"},
20+
{AlgorithmPS512, "PS512"},
21+
{AlgorithmES256, "ES256"},
22+
{AlgorithmES384, "ES384"},
23+
{AlgorithmES512, "ES512"},
24+
{AlgorithmEdDSA, "EdDSA"},
25+
{AlgorithmReserved, "Reserved"},
26+
{7, "unknown algorithm value 7"},
2427
}
2528
for _, tt := range tests {
26-
t.Run(tt.name, func(t *testing.T) {
29+
t.Run(tt.want, func(t *testing.T) {
2730
if got := tt.alg.String(); got != tt.want {
2831
t.Errorf("Algorithm.String() = %v, want %v", got, tt.want)
2932
}

headers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ func (h ProtectedHeader) Algorithm() (Algorithm, error) {
119119
case int64:
120120
return Algorithm(alg), nil
121121
case string:
122-
return AlgorithmInvalid, fmt.Errorf("unknown algorithm value %q", alg)
122+
return AlgorithmReserved, fmt.Errorf("unknown algorithm value %q", alg)
123123
default:
124-
return AlgorithmInvalid, ErrInvalidAlgorithm
124+
return AlgorithmReserved, ErrInvalidAlgorithm
125125
}
126126
}
127127

0 commit comments

Comments
 (0)