[RFC PATCH v2 1/8] dtoc: openssl: Add GetHexOctet method
Manorit Chawdhry
m-chawdhry at ti.com
Tue Oct 3 12:41:28 CEST 2023
Hi Simon,
On 19:17-20231001, Simon Glass wrote:
> 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?
>
It is actually a Hex number in Octet form, basically using 0x0a instead
of 0xa type of thing.
OpenSSL has complained when we use FORMAT:HEX,OCT:0 type of string
instead of FORMAT:HEX,OCT:00. Tbvh I still haven't been able to find a
clear documentation for this but this is what I have been able to figure
out based on my tests.
> > + """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}'
>
With the following suggestion I don't think I need the patch at all
anymore given that no one else seems to be requiring this HEX,OCT just
yet and am still in the process of finding a clear documentation for it.
Will be dropping that patch after testing if not required to be generic.
Thanks!
Regards,
Manorit
> ?
>
>
> > +
> > def GetInt(node, propname, default=None):
> > """Get an integer from a property
> >
> >
> > --
> > 2.41.0
> >
More information about the U-Boot
mailing list