From 0fa3331b8c7cb6b1bd4476f112cd5d77b9694301 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 23 Aug 2019 23:02:53 +0200 Subject: [PATCH] Add clearer indication of "self encryption" --- libp2p/security/secio/exceptions.py | 9 +++++++++ libp2p/security/secio/transport.py | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libp2p/security/secio/exceptions.py b/libp2p/security/secio/exceptions.py index a5f7464..1461be9 100644 --- a/libp2p/security/secio/exceptions.py +++ b/libp2p/security/secio/exceptions.py @@ -2,6 +2,15 @@ class SecioException(Exception): pass +class SelfEncryption(SecioException): + """ + Raised to indicate that a host is attempting to encrypt communications + with itself. + """ + + pass + + class PeerMismatchException(SecioException): pass diff --git a/libp2p/security/secio/transport.py b/libp2p/security/secio/transport.py index 955c906..f77f353 100644 --- a/libp2p/security/secio/transport.py +++ b/libp2p/security/secio/transport.py @@ -28,6 +28,7 @@ from .exceptions import ( InvalidSignatureOnExchange, PeerMismatchException, SecioException, + SelfEncryption, ) from .pb.spipe_pb2 import Exchange, Propose @@ -195,9 +196,8 @@ def _select_encryption_parameters( elif second_score < first_score: order = 1 - # NOTE: if order is 0, "talking to self" - # TODO(ralexstokes) nicer error handling here... - assert order != 0 + if order == 0: + raise SelfEncryption() return ( _select_parameter_from_order(