File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
2226def _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
You can’t perform that action at this time.
0 commit comments