Delete utils in favor of serialization module
This commit is contained in:
parent
5fdca2ffb2
commit
6e53849604
|
@ -1,17 +0,0 @@
|
|||
from .keys import PublicKey
|
||||
from .pb import crypto_pb2 as protobuf
|
||||
from .rsa import RSAPublicKey
|
||||
from .secp256k1 import Secp256k1PublicKey
|
||||
|
||||
|
||||
def pubkey_from_protobuf(pubkey_pb: protobuf.PublicKey) -> PublicKey:
|
||||
if pubkey_pb.key_type == protobuf.RSA:
|
||||
return RSAPublicKey.from_bytes(pubkey_pb.data)
|
||||
# TODO: Test against secp256k1 keys
|
||||
elif pubkey_pb.key_type == protobuf.Secp256k1:
|
||||
return Secp256k1PublicKey.from_bytes(pubkey_pb.data)
|
||||
# TODO: Support `Ed25519` and `ECDSA` in the future?
|
||||
else:
|
||||
raise ValueError(
|
||||
f"unsupported key_type={pubkey_pb.key_type}, data={pubkey_pb.data!r}"
|
||||
)
|
|
@ -2,7 +2,7 @@ from typing import Optional
|
|||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.crypto.pb import crypto_pb2
|
||||
from libp2p.crypto.utils import pubkey_from_protobuf
|
||||
from libp2p.crypto.serialization import deserialize_public_key
|
||||
from libp2p.io.abc import ReadWriteCloser
|
||||
from libp2p.network.connection.exceptions import RawConnError
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
|
@ -75,7 +75,9 @@ class InsecureSession(BaseSession):
|
|||
|
||||
# Verify if the given `pubkey` matches the given `peer_id`
|
||||
try:
|
||||
received_pubkey = pubkey_from_protobuf(remote_msg.pubkey)
|
||||
received_pubkey = deserialize_public_key(
|
||||
remote_msg.pubkey.SerializeToString()
|
||||
)
|
||||
except ValueError:
|
||||
raise HandshakeFailure(
|
||||
f"unknown `key_type` of remote_msg.pubkey={remote_msg.pubkey}"
|
||||
|
|
Loading…
Reference in New Issue
Block a user