Skip to content

Commit

Permalink
[fix] #132 - return serial numbers with leading zero
Browse files Browse the repository at this point in the history
  • Loading branch information
grindsa committed Feb 6, 2024
1 parent efc07db commit 05f0b23
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions acme_srv/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ def cert_serial_get(logger: logging.Logger, certificate: str, hexformat: bool =
cert = cert_load(logger, certificate, recode=True)
if hexformat:
serial_number = f'{cert.serial_number:x}'
# add leading zero if needed
serial_number = serial_number.zfill(len(serial_number) + len(serial_number) % 2)
else:
serial_number = cert.serial_number
logger.debug('cert_serial_get() ended with: %s', serial_number)
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_043_helper_cert_serial_get(self):
bta75ocePrurdNxsxKJhLlXbnKD6lurCb4khRhrmLmpK8JxhuaevEVklSQX0gqlR
fxAH4XQsaqcaedPNI+W5OUITMz40ezDCbUqxS9KEMCGPoOTXNRAjbr72sc4Vkw7H
t+eRUDECE+0UnjyeCjTn3EU="""
self.assertEqual('a', self.cert_serial_get(self.logger, cert, hexformat=True))
self.assertEqual('0a', self.cert_serial_get(self.logger, cert, hexformat=True))

def test_044_helper_cert_issuer_get(self):
""" test cert_issuer_get """
Expand Down

0 comments on commit 05f0b23

Please sign in to comment.