mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
9aefcb12f5
- Removed python 2 compatibility - Removed dependencies on redundant external modules - Interactive provisioning input for security scheme 2 - Style changes: Updated print statements to format strings Colored verbose logging Raised exceptions on errors instead of clean exits
25 lines
592 B
Python
25 lines
592 B
Python
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
# Convenience functions for commonly used data type conversions
|
|
|
|
def bytes_to_long(s: bytes) -> int:
|
|
return int.from_bytes(s, 'big')
|
|
|
|
|
|
def long_to_bytes(n: int) -> bytes:
|
|
if n == 0:
|
|
return b'\x00'
|
|
return n.to_bytes((n.bit_length() + 7) // 8, 'big')
|
|
|
|
|
|
# 'deadbeef' -> b'deadbeef'
|
|
def str_to_bytes(s: str) -> bytes:
|
|
return bytes(s, encoding='latin-1')
|
|
|
|
|
|
# 'deadbeef' -> b'\xde\xad\xbe\xef'
|
|
def hex_str_to_bytes(s: str) -> bytes:
|
|
return bytes.fromhex(s)
|