This commit is contained in:
NIC619 2019-11-14 14:22:23 +08:00
parent 86e0fa4563
commit cbe57cd5d7
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17
2 changed files with 2 additions and 7 deletions

View File

@ -25,7 +25,7 @@ class RSAPublicKey(PublicKey):
h = SHA256.new(data)
try:
# NOTE: the typing in ``pycryptodome`` is wrong on the arguments to ``verify``.
pkcs1_15.new(self.impl).verify(h, signature) # type: ignore
pkcs1_15.new(self.impl).verify(h, signature)
except (ValueError, TypeError):
return False
return True
@ -49,7 +49,7 @@ class RSAPrivateKey(PrivateKey):
def sign(self, data: bytes) -> bytes:
h = SHA256.new(data)
# NOTE: the typing in ``pycryptodome`` is wrong on the arguments to ``sign``.
return pkcs1_15.new(self.impl).sign(h) # type: ignore
return pkcs1_15.new(self.impl).sign(h)
def get_public_key(self) -> PublicKey:
return RSAPublicKey(self.impl.publickey())

View File

@ -25,18 +25,15 @@ async def _handle_ping(stream: INetStream, peer_id: PeerID) -> bool:
logger.debug("Other side closed while waiting for ping from %s", peer_id)
return False
except StreamReset as error:
print("peer", peer_id, "ping reset")
logger.debug(
"Other side reset while waiting for ping from %s: %s", peer_id, error
)
raise
except Exception as error:
print("peer", peer_id, "ping", type(error))
logger.debug("Error while waiting to read ping for %s: %s", peer_id, error)
raise
logger.debug("Received ping from %s with data: 0x%s", peer_id, payload.hex())
print("receive ping from", peer_id)
try:
await stream.write(payload)
@ -51,13 +48,11 @@ async def handle_ping(stream: INetStream) -> None:
or closes the ``stream``."""
peer_id = stream.muxed_conn.peer_id
print("handling ping from", peer_id)
while True:
try:
should_continue = await _handle_ping(stream, peer_id)
if not should_continue:
return
except Exception:
print("error finish ping")
await stream.reset()
return