Skip to content

Commit cda9803

Browse files
committed
use consts for curve strings
1 parent eea3e5c commit cda9803

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

ee/localserver/jwk_keys.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ type jwk struct {
2020
KeyID string `json:"kid"`
2121
}
2222

23+
const (
24+
curveP256 string = "P-256"
25+
curveP384 string = "P-384"
26+
curveP521 string = "P-521"
27+
)
28+
2329
func parseEllipticCurve(str string) (elliptic.Curve, error) {
24-
switch strings.ToLower(str) {
25-
case "p-256":
30+
switch strings.ToUpper(str) {
31+
case curveP256:
2632
return elliptic.P256(), nil
27-
case "p-384":
33+
case curveP384:
2834
return elliptic.P384(), nil
29-
case "p-521":
35+
case curveP521:
3036
return elliptic.P521(), nil
3137
default:
3238
return &elliptic.CurveParams{}, fmt.Errorf("unsupported curve: %s", str)

ee/localserver/zta_auth_middleware_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ func toJWK(key any, kid string) (*jwk, error) {
358358
var crv string
359359
switch k.Curve {
360360
case elliptic.P256():
361-
crv = "P-256"
361+
crv = curveP256
362362
case elliptic.P384():
363-
crv = "P-384"
363+
crv = curveP384
364364
case elliptic.P521():
365-
crv = "P-521"
365+
crv = curveP521
366366
default:
367367
return nil, fmt.Errorf("unsupported elliptic curve, %s", crv)
368368
}

0 commit comments

Comments
 (0)