[RFC PATCH v2 1/8] dtoc: openssl: Add GetHexOctet method

Simon Glass sjg at chromium.org
Mon Oct 2 03:17:07 CEST 2023


Hi Manorit,

On Tue, 26 Sept 2023 at 01:58, Manorit Chawdhry <m-chawdhry at ti.com> wrote:
>
> HexOctet format is used by openssl for FORMAT:HEX,OCT property in x509
> certificates. Add a helper function to extract the integer numbers in
> HEX,OCT format to pass to openssl directly.
>
> Signed-off-by: Manorit Chawdhry <m-chawdhry at ti.com>
> ---
>  tools/dtoc/fdt_util.py | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py
> index f1f70568cfef..d51dbf5633d0 100644
> --- a/tools/dtoc/fdt_util.py
> +++ b/tools/dtoc/fdt_util.py
> @@ -100,6 +100,26 @@ def EnsureCompiled(fname, tmpdir=None, capture_stderr=False):
>      command.run(dtc, *args, capture_stderr=capture_stderr)
>      return dtb_output
>
> +def GetHexOctet(node, propname, default=None):

What is a hex octet?

> +    """Get an integer from a property in hex octet form required by openssl
> +

You should mention what size property is permitted.

> +    Args:
> +        node: Node object to read from
> +        propname: property name to read
> +        default: Default value to use if the node/property do not exist
> +
> +    Returns:
> +        Integer value read as a String in Hex Octet Form
> +    """
> +    prop = node.props.get(propname)
> +    if not isinstance(prop.value, list) or len(prop.value) != 2:
> +        value = GetInt(node, propname)
> +    elif isinstance(prop.value, list) and len(prop.value) == 2:
> +        value = GetInt64(node, propname)

What if it is neither of those?

> +
> +    hex_value = '%x' % (value)
> +    return ('0' * (len(hex_value) & 1)) + hex_value

Can you do:

return f'{value:02x}'

?


> +
>  def GetInt(node, propname, default=None):
>      """Get an integer from a property
>
>
> --
> 2.41.0
>


More information about the U-Boot mailing list