File tree Expand file tree Collapse file tree 3 files changed +7
-9
lines changed Expand file tree Collapse file tree 3 files changed +7
-9
lines changed Original file line number Diff line number Diff line change 2626 from .algorithms import AllowedPrivateKeys , AllowedPublicKeys
2727
2828
29- DEFAULT_ALGORITHM = "DEFAULT_ALGORITHM"
30-
31-
3229class PyJWS :
3330 header_typ = "JWT"
3431
@@ -109,7 +106,7 @@ def encode(
109106 self ,
110107 payload : bytes ,
111108 key : AllowedPrivateKeys | PyJWK | str | bytes ,
112- algorithm : str | None = DEFAULT_ALGORITHM ,
109+ algorithm : str | None = None ,
113110 headers : dict [str , Any ] | None = None ,
114111 json_encoder : type [json .JSONEncoder ] | None = None ,
115112 is_payload_detached : bool = False ,
@@ -118,12 +115,13 @@ def encode(
118115 segments = []
119116
120117 # declare a new var to narrow the type for type checkers
121- algorithm_ : str = algorithm if algorithm is not None else "none"
122- if algorithm_ == DEFAULT_ALGORITHM :
118+ if algorithm is None :
123119 if isinstance (key , PyJWK ):
124120 algorithm_ = key .algorithm_name
125121 else :
126122 algorithm_ = "HS256"
123+ else :
124+ algorithm_ = algorithm
127125
128126 # Prefer headers values if present to function parameters.
129127 if headers :
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ def encode(
4646 self ,
4747 payload : dict [str , Any ],
4848 key : AllowedPrivateKeys | PyJWK | str | bytes ,
49- algorithm : str | None = api_jws . DEFAULT_ALGORITHM ,
49+ algorithm : str | None = None ,
5050 headers : dict [str , Any ] | None = None ,
5151 json_encoder : type [json .JSONEncoder ] | None = None ,
5252 sort_headers : bool = True ,
Original file line number Diff line number Diff line change @@ -562,13 +562,13 @@ def test_decode_invalid_crypto_padding(self, jws):
562562 assert "Invalid crypto padding" in str (exc .value )
563563
564564 def test_decode_with_algo_none_should_fail (self , jws , payload ):
565- jws_message = jws .encode (payload , key = None , algorithm = None )
565+ jws_message = jws .encode (payload , key = None , algorithm = "none" )
566566
567567 with pytest .raises (DecodeError ):
568568 jws .decode (jws_message , algorithms = ["none" ])
569569
570570 def test_decode_with_algo_none_and_verify_false_should_pass (self , jws , payload ):
571- jws_message = jws .encode (payload , key = None , algorithm = None )
571+ jws_message = jws .encode (payload , key = None , algorithm = "none" )
572572 jws .decode (jws_message , options = {"verify_signature" : False })
573573
574574 def test_get_unverified_header_returns_header_values (self , jws , payload ):
You can’t perform that action at this time.
0 commit comments