Delete utils in favor of serialization module

This commit is contained in:
Alex Stokes 2019-09-24 09:31:35 -07:00
parent 5fdca2ffb2
commit 6e53849604
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086
2 changed files with 4 additions and 19 deletions

View File

@ -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}"
)

View File

@ -2,7 +2,7 @@ from typing import Optional
from libp2p.crypto.keys import PrivateKey, PublicKey from libp2p.crypto.keys import PrivateKey, PublicKey
from libp2p.crypto.pb import crypto_pb2 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.io.abc import ReadWriteCloser
from libp2p.network.connection.exceptions import RawConnError from libp2p.network.connection.exceptions import RawConnError
from libp2p.network.connection.raw_connection_interface import IRawConnection 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` # Verify if the given `pubkey` matches the given `peer_id`
try: try:
received_pubkey = pubkey_from_protobuf(remote_msg.pubkey) received_pubkey = deserialize_public_key(
remote_msg.pubkey.SerializeToString()
)
except ValueError: except ValueError:
raise HandshakeFailure( raise HandshakeFailure(
f"unknown `key_type` of remote_msg.pubkey={remote_msg.pubkey}" f"unknown `key_type` of remote_msg.pubkey={remote_msg.pubkey}"