Skip to content

Commit

Permalink
Simplify re-encoded substrate DER comparison logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CBonnell committed Jul 16, 2024
1 parent fa12349 commit 57dcfba
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkilint/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,16 @@ def decode_substrate(source_document: Document, substrate: bytes,

try:
encoded = encode(decoded)
if encoded != substrate:
raise SubstrateDecodingFailedError(
source_document, pdu_instance, parent_node,
f'Substrate of type "{type_name}" is not binary equal to re-encoded DER representation'
)
except (ValueError, PyAsn1Error) as e:

substrate_is_der = encoded == substrate
except (ValueError, PyAsn1Error):
substrate_is_der = False

if not substrate_is_der:
raise SubstrateDecodingFailedError(
source_document, pdu_instance, parent_node,
f'Substrate of type "{type_name}" is not DER-encoded'
) from e
)

node = PDUNode(source_document, decoded_pdu_name, decoded, parent_node)

Expand Down

0 comments on commit 57dcfba

Please sign in to comment.