Skip to content

Commit

Permalink
[Python] Fix Cert API argument type errors
Browse files Browse the repository at this point in the history
NativeLibraryHandleMethodArguments correctly setting the argument
types causes argument type errors:
ctypes.ArgumentError: argument 1: TypeError: expected LP_c_ubyte instance instead of bytes

We can safely cast bytes as the native side marks it const.
  • Loading branch information
agners committed Jun 17, 2024
1 parent 759b7b0 commit d7f7219
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/controller/python/chip/credentials/cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def convert_x509_cert_to_chip_cert(x509Cert: bytes) -> bytes:
output_buffer = (ctypes.c_uint8 * 1024)()
output_size = ctypes.c_size_t(1024)

_handle().pychip_ConvertX509CertToChipCert(x509Cert, len(x509Cert), output_buffer, ctypes.byref(output_size)).raise_on_error()
_handle().pychip_ConvertX509CertToChipCert(ctypes.cast(x509Cert, ctypes.POINTER(ctypes.c_uint8)),
len(x509Cert), output_buffer, ctypes.byref(output_size)).raise_on_error()

return bytes(output_buffer)[:output_size.value]

Expand All @@ -46,6 +47,7 @@ def convert_chip_cert_to_x509_cert(chipCert: bytes) -> bytes:
output_buffer = (ctypes.c_byte * 1024)()
output_size = ctypes.c_size_t(1024)

_handle().pychip_ConvertChipCertToX509Cert(chipCert, len(chipCert), output_buffer, ctypes.byref(output_size)).raise_on_error()
_handle().pychip_ConvertChipCertToX509Cert(ctypes.cast(chipCert, ctypes.POINTER(ctypes.c_uint8)),
len(chipCert), output_buffer, ctypes.byref(output_size)).raise_on_error()

return bytes(output_buffer)[:output_size.value]

0 comments on commit d7f7219

Please sign in to comment.