custom_prov.py 854 B

1234567891011121314151617181920212223242526
  1. # SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. #
  4. # APIs for interpreting and creating protobuf packets for `custom-config` protocomm endpoint
  5. from utils import str_to_bytes
  6. def print_verbose(security_ctx, data):
  7. if (security_ctx.verbose):
  8. print(f'\x1b[32;20m++++ {data} ++++\x1b[0m')
  9. def custom_data_request(security_ctx, data):
  10. # Encrypt the custom data
  11. enc_cmd = security_ctx.encrypt_data(str_to_bytes(data))
  12. print_verbose(security_ctx, f'Client -> Device (CustomData cmd): 0x{enc_cmd.hex()}')
  13. return enc_cmd.decode('latin-1')
  14. def custom_data_response(security_ctx, response_data):
  15. # Decrypt response packet
  16. decrypt = security_ctx.decrypt_data(str_to_bytes(response_data))
  17. print(f'++++ CustomData response: {str(decrypt)}++++')
  18. return 0