lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZddIzlOHxYCrQibb@nanopsycho>
Date: Thu, 22 Feb 2024 14:14:54 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: Jakub Kicinski <kuba@...nel.org>
Cc: netdev@...r.kernel.org, pabeni@...hat.com, davem@...emloft.net,
	edumazet@...gle.com, jacob.e.keller@...el.com,
	swarupkotikalapudi@...il.com, donald.hunter@...il.com,
	sdf@...gle.com, lorenzo@...nel.org, alessandromarcolini99@...il.com
Subject: Re: [patch net-next v2 3/3] tools: ynl: allow user to pass enum
 string instead of scalar value

Wed, Feb 21, 2024 at 07:49:36PM CET, kuba@...nel.org wrote:
>On Wed, 21 Feb 2024 16:54:15 +0100 Jiri Pirko wrote:
>> +    def _encode_enum(self, attr_spec, value):
>> +        try:
>> +            return int(value)
>> +        except (ValueError, TypeError) as e:
>> +            if 'enum' not in attr_spec:
>> +                raise e
>> +        enum = self.consts[attr_spec['enum']]
>> +        if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
>> +            scalar = 0
>> +            if isinstance(value, str):
>> +                value = [value]
>> +            for single_value in value:
>> +                scalar += enum.entries[single_value].user_value(as_flags = True)
>> +            return scalar
>> +        else:
>> +            return enum.entries[value].user_value()
>
>That's not symmetric with _decode_enum(), I said:
>
>                     vvvvvvvvvvvvvvvvvvvvvv
>  It'd be cleaner to make it more symmetric with _decode_enum(), and
>  call it _encode_enum().
>
>How about you go back to your _get_scalar name and only factor out the
>parts which encode the enum to be a _encode_enum() ?

Okay.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ