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