2022-01-13 03:50:51 -05:00
|
|
|
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-07-30 12:10:10 -04:00
|
|
|
#
|
|
|
|
|
|
|
|
# APIs for interpreting and creating protobuf packets for `custom-config` protocomm endpoint
|
|
|
|
|
2022-06-22 05:44:19 -04:00
|
|
|
from utils import str_to_bytes
|
2018-07-30 12:10:10 -04:00
|
|
|
|
2018-12-04 07:46:48 -05:00
|
|
|
|
2018-07-30 12:10:10 -04:00
|
|
|
def print_verbose(security_ctx, data):
|
|
|
|
if (security_ctx.verbose):
|
2022-06-22 05:44:19 -04:00
|
|
|
print(f'\x1b[32;20m++++ {data} ++++\x1b[0m')
|
2018-12-04 07:46:48 -05:00
|
|
|
|
2018-07-30 12:10:10 -04:00
|
|
|
|
2020-01-05 13:06:48 -05:00
|
|
|
def custom_data_request(security_ctx, data):
|
|
|
|
# Encrypt the custom data
|
2022-06-22 05:44:19 -04:00
|
|
|
enc_cmd = security_ctx.encrypt_data(str_to_bytes(data))
|
|
|
|
print_verbose(security_ctx, f'Client -> Device (CustomData cmd): 0x{enc_cmd.hex()}')
|
2022-06-07 12:16:23 -04:00
|
|
|
return enc_cmd.decode('latin-1')
|
2020-01-05 13:06:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
def custom_data_response(security_ctx, response_data):
|
|
|
|
# Decrypt response packet
|
2022-06-22 05:44:19 -04:00
|
|
|
decrypt = security_ctx.decrypt_data(str_to_bytes(response_data))
|
|
|
|
print(f'++++ CustomData response: {str(decrypt)}++++')
|
2020-01-05 13:06:48 -05:00
|
|
|
return 0
|