From 444d3329cb2174d2fd2f539c34ff7f74b96e82aa Mon Sep 17 00:00:00 2001 From: Sebastien Awwad Date: Fri, 26 Oct 2018 12:47:02 -0400 Subject: [PATCH] ASN.1: improve _list_to_pyasn1 loop setup once before the loop; no need to repeat in every iteration Signed-off-by: Sebastien Awwad --- tuf/encoding/asn1_convert.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tuf/encoding/asn1_convert.py b/tuf/encoding/asn1_convert.py index 8711805d..224e65af 100644 --- a/tuf/encoding/asn1_convert.py +++ b/tuf/encoding/asn1_convert.py @@ -571,16 +571,16 @@ def _list_to_pyasn1(data, datatype): pyasn1_obj = datatype() # DEBUG - for i in range(0,len(data)): - datum = data[i] + if None is getattr(datatype, 'componentType', None): + # TODO: Use a better exception class, if you decide to keep this. + # It's useful in debugging because the error we get if we don't + # specifically detect this may be misleading. + raise tuf.exceptions.Error('Unable to determine type of component in a ' + 'list. datatype of list: ' + str(datatype) + '; componentType ' + 'appears to be None') - if None is getattr(datatype, 'componentType', None): - # TODO: Use a better exception class, if you decide to keep this. - # It's useful in debugging because the error we get if we don't - # specifically detect this may be misleading. - raise tuf.exceptions.Error('Unable to determine type of component in a ' - 'list. datatype of list: ' + str(datatype) + '; componentType ' - 'appears to be None') + for i in range(0, len(data)): + datum = data[i] debug('In conversion of list to type ' + str(datatype) + ', recursing ' 'to convert subcomponent of type ' + str(type(datatype.componentType)))