Skip to content

Commit 0b9d1ec

Browse files
fix(tests): use fixed RFC 7518 coordinate byte length in EC JWK fixtures (#116)
1 parent fbc11ac commit 0b9d1ec

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎tests/test_jwk_rsa_ec.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def _b64u_int(value: int) -> str:
1919
return base64.urlsafe_b64encode(value.to_bytes(length, "big")).decode().rstrip("=")
2020

2121

22+
def _b64u_coord(value: int, length: int) -> str:
23+
return base64.urlsafe_b64encode(value.to_bytes(length, "big")).decode().rstrip("=")
24+
25+
2226
def _private_pem(key: object) -> bytes:
2327
return key.private_bytes(
2428
serialization.Encoding.PEM,
@@ -47,14 +51,15 @@ def ec_jwk_dict(
4751
kid: str,
4852
) -> dict[str, Any]:
4953
pub = key.public_key().public_numbers()
54+
coord_len = 32 if crv == "P-256" else (48 if crv == "P-384" else 66)
5055
return {
5156
"kty": "EC",
5257
"kid": kid,
5358
"use": "sig",
5459
"alg": alg,
5560
"crv": crv,
56-
"x": _b64u_int(pub.x),
57-
"y": _b64u_int(pub.y),
61+
"x": _b64u_coord(pub.x, coord_len),
62+
"y": _b64u_coord(pub.y, coord_len),
5863
}
5964

6065

0 commit comments

Comments
 (0)