@@ -248,7 +248,7 @@ def hex_str_to_pyasn1_octets(hex_string):
248
248
# TODO: Verify hex_string type.
249
249
250
250
if len (hex_string ) % 2 :
251
- raise tuf .exceptions .Error (
251
+ raise tuf .exceptions .ASN1ConversionError (
252
252
'Expecting hex strings with an even number of digits, since hex '
253
253
'strings provide 2 characters per byte. We prefer not to pad values '
254
254
'implicitly.' )
@@ -283,7 +283,7 @@ def hex_str_from_pyasn1_octets(octets_pyasn1):
283
283
284
284
for x in octets :
285
285
if x < 0 or x > 255 :
286
- raise tuf .exceptions .Error (
286
+ raise tuf .exceptions .ASN1ConversionError (
287
287
'Unable to generate hex string from OctetString: integer value of '
288
288
'octet provided is not in range: ' + str (x ))
289
289
hex_string += '%.2x' % x
@@ -359,7 +359,7 @@ def to_pyasn1(data, datatype):
359
359
debug ('Converting a (hopefully-)primitive value to ' + str (datatype )) # DEBUG
360
360
tuf .formats .HEX_SCHEMA .check_match (data )
361
361
if len (data ) % 2 :
362
- raise tuf .exceptions .Error (
362
+ raise tuf .exceptions .ASN1ConversionError (
363
363
'Expecting hex strings with an even number of digits, since hex '
364
364
'strings provide 2 characters per byte. We prefer not to pad values '
365
365
'implicitly.' )
@@ -436,9 +436,9 @@ def to_pyasn1(data, datatype):
436
436
return pyasn1_obj
437
437
438
438
else :
439
- # TODO: Use a better error class for ASN.1 conversion errors.
440
439
recursion_level -= 1
441
- raise tuf .exceptions .Error ('Unable to determine how to automatically '
440
+ raise tuf .exceptions .ASN1ConversionError (
441
+ 'Unable to determine how to automatically '
442
442
'convert data into pyasn1 data. Can only handle primitives to Integer/'
443
443
'VisibleString/OctetString, or list to list-like pyasn1, or list-like '
444
444
'dict to list-like pyasn1, or struct-like dict to struct-like pyasn1. '
@@ -531,8 +531,8 @@ def _structlike_dict_to_pyasn1(data, datatype):
531
531
# pyasn1_obj[element_name] = len(data[relevant_element_name_python])
532
532
533
533
# else:
534
- # # TODO: Use a better exception class, relevant to ASN1 conversion.
535
- # raise tuf.exceptions.Error( 'When converting dict into pyasn1, '
534
+ # raise tuf.exceptions.ASN1ConversionError(
535
+ # 'When converting dict into pyasn1, '
536
536
# 'found an element that appeared to be a "num-"-prefixed '
537
537
# 'length-of-list for another element; however, did not find '
538
538
# 'corresponding element to calculate length of. Element name: ' +
@@ -542,8 +542,8 @@ def _structlike_dict_to_pyasn1(data, datatype):
542
542
else :
543
543
# Found an element name in datatype that does not match anything in
544
544
# data (MOOT: and does not begin with 'num-').
545
- # TODO: Use a better exception class, relevant to ASN1 conversion.
546
- raise tuf . exceptions . Error ( 'Unable to convert dict into pyasn1: it '
545
+ raise tuf . exceptions . ASN1ConversionError (
546
+ 'Unable to convert dict into pyasn1: it '
547
547
'seems to be missing elements. dict does not contain "' +
548
548
element_name + '". Datatype for conversion: ' + str (datatype ) +
549
549
'; dict contents: ' + str (data ))
@@ -572,10 +572,11 @@ def _list_to_pyasn1(data, datatype):
572
572
pyasn1_obj = datatype () # DEBUG
573
573
574
574
if None is getattr (datatype , 'componentType' , None ):
575
- # TODO: Use a better exception class, if you decide to keep this.
575
+ # TODO: Determine whether or not to keep this error .
576
576
# It's useful in debugging because the error we get if we don't
577
577
# specifically detect this may be misleading.
578
- raise tuf .exceptions .Error ('Unable to determine type of component in a '
578
+ raise tuf .exceptions .ASN1ConversionError (
579
+ 'Unable to determine type of component in a '
579
580
'list. datatype of list: ' + str (datatype ) + '; componentType '
580
581
'appears to be None' )
581
582
@@ -660,7 +661,7 @@ def _listlike_dict_to_pyasn1(data, datatype):
660
661
# We are assuming that we can convert in={k1: v1, k2: v2, ...} to
661
662
# out[i][0] = k1, out[0][1] = v1,
662
663
# TODO: more useful error message and conversion-specific exception class
663
- raise tuf .exceptions .Error ()
664
+ raise tuf .exceptions .ASN1ConversionError ()
664
665
665
666
i = 0
666
667
for key in data :
@@ -746,9 +747,9 @@ def from_pyasn1(data, datatype):
746
747
747
748
748
749
else :
749
- # TODO: Use a better error class for ASN.1 conversion errors.
750
750
recursion_level -= 1
751
- raise tuf .exceptions .Error ('Unable to determine how to automatically '
751
+ raise tuf .exceptions .ASN1ConversionError (
752
+ 'Unable to determine how to automatically '
752
753
'convert data from pyasn1 data. Can only handle primitives to Integer/'
753
754
'VisibleString/OctetString, or list-like dict from list-like pyasn1, '
754
755
'or struct-like dict to struct-like pyasn1. '
@@ -831,10 +832,11 @@ def _list_from_pyasn1(data, datatype):
831
832
list_python = []
832
833
833
834
if None is getattr (datatype , 'componentType' , None ):
834
- # TODO: Use a better exception class, if you decide to keep this.
835
+ # TODO: Determine whether or not to keep this error .
835
836
# It's useful in debugging because the error we get if we don't
836
837
# specifically detect this may be misleading.
837
- raise tuf .exceptions .Error ('Unable to determine type of component in a '
838
+ raise tuf .exceptions .ASN1ConversionError (
839
+ 'Unable to determine type of component in a '
838
840
'list. datatype of list: ' + str (datatype ) + '; componentType '
839
841
'appears to be None' )
840
842
0 commit comments