Skip to content

Commit

Permalink
Use len(var) instead of tlv_length for values.
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-palmer committed Jun 25, 2024
1 parent cab0ba1 commit 5f5b047
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions enccnf
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def parse_enc_file(enc_file, tftp_certificate_file):
elif tlv_tag == HEADER_SIGNATURE:
signature = tlv_data[tlv_index:tlv_index + tlv_length]

print(f'Signature: {tlv_length} bytes')
print(f'Signature: {len(signature)} bytes')

signature_index = tlv_index - 3
signature_length = tlv_length
Expand All @@ -171,10 +171,14 @@ def parse_enc_file(enc_file, tftp_certificate_file):
pass

elif tlv_tag == HEADER_ENCRYPTION_IV:
print(f'Encryption IV: {tlv_length} bytes')
encryption_iv = tlv_data[tlv_index:tlv_index + tlv_length]

print(f'Encryption IV: {len(encryption_iv)} bytes')

elif tlv_tag == HEADER_ENCRYPTION_KEY:
print(f'Encryption Key: {tlv_length} bytes')
encryption_key = tlv_data[tlv_index:tlv_index + tlv_length]

print(f'Encryption Key: {len(encryption_key)} bytes')

elif tlv_tag == HEADER_ENCRYPTION_HASH_ALGORITHM:
encryption_hash_algorithm = tlv_data[tlv_index]
Expand Down
2 changes: 1 addition & 1 deletion sgnfile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def parse_sgn_file(sgn_file, tftp_certificate_file):
elif tlv_tag == HEADER_SIGNATURE:
signature = tlv_data[tlv_index:tlv_index + tlv_length]

print(f'Signature: {tlv_length} bytes')
print(f'Signature: {len(signature)} bytes')

signature_index = tlv_index - 3
signature_length = tlv_length
Expand Down
8 changes: 4 additions & 4 deletions tlvfile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def parse_tlv_file(tlv_file):
elif tlv_tag == HEADER_SIGNATURE:
signature = tlv_data[tlv_index:tlv_index + tlv_length]

print(f'Signature: {tlv_length} bytes')
print(f'Signature: {len(signature)} bytes')

signature_index = tlv_index - 3
signature_length = tlv_length
Expand Down Expand Up @@ -272,17 +272,17 @@ def parse_tlv_file(tlv_file):
elif tlv_tag == RECORD_PUBLIC_KEY:
public_key = tlv_data[tlv_index:tlv_index + tlv_length]

print(f'Public Key: {tlv_length} bytes')
print(f'Public Key: {len(public_key)} bytes')

elif tlv_tag == RECORD_SIGNATURE:
signature = tlv_data[tlv_index:tlv_index + tlv_length]

print(f'Signature: {tlv_length} bytes')
print(f'Signature: {len(signature)} bytes')

elif tlv_tag == RECORD_CERTIFICATE:
certificate = tlv_data[tlv_index:tlv_index + tlv_length]

print(f'Certificate: {tlv_length} bytes')
print(f'Certificate: {len(certificate)} bytes')

try:
certificate = x509.load_der_x509_certificate(certificate, backends.default_backend())
Expand Down

0 comments on commit 5f5b047

Please sign in to comment.