Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiei committed Nov 27, 2024
1 parent adefa5d commit 21620cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions binance/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def _rsa_signature(self, query_string: str):
h = SHA256.new(query_string.encode("utf-8"))
signature = pkcs1_15.new(self.PRIVATE_KEY).sign(h) # type: ignore
res = b64encode(signature).decode()
return self.encode_uri_component(res)
# return self.encode_uri_component(res)
return res

@staticmethod
def encode_uri_component(uri, safe="~()*!.'"):
Expand All @@ -313,7 +314,8 @@ def _ed25519_signature(self, query_string: str):
res = b64encode(
eddsa.new(self.PRIVATE_KEY, "rfc8032").sign(query_string.encode())
).decode() # type: ignore
return self.encode_uri_component(res)
# return self.encode_uri_component(res)
return res

def _hmac_signature(self, query_string: str) -> str:
assert self.API_SECRET, "API Secret required for private endpoints"
Expand All @@ -324,7 +326,7 @@ def _hmac_signature(self, query_string: str) -> str:
)
return m.hexdigest()

def _generate_signature(self, data: Dict) -> str:
def _generate_signature(self, data: Dict, uri_encode=True) -> str:
sig_func = self._hmac_signature
if self.PRIVATE_KEY:
if self._is_rsa:
Expand All @@ -333,7 +335,7 @@ def _generate_signature(self, data: Dict) -> str:
sig_func = self._ed25519_signature
query_string = "&".join([f"{d[0]}={d[1]}" for d in self._order_params(data)])
res = sig_func(query_string)
return res
return self.encode_uri_component(res) if uri_encode else res

def _sign_ws_params(self, params, signature_func):
if "signature" in params:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_encryption():
private_key_pass=case["password"],
ping=False,
)
signature = client._generate_signature(data)
signature = client._generate_signature(data, False)
assert signature == case["expected_signature"], (
f"Test failed: {case['description']}"
)

0 comments on commit 21620cf

Please sign in to comment.