2020
2121from cryptodatahub .dnsrec .algorithm import DnsRrType , DnsSecAlgorithm , DnsSecDigestType
2222
23- from cryptoparser .common .base import OneByteEnumParsable , Serializable , TwoByteEnumParsable
23+ from cryptoparser .common .base import NumericRangeParsableBase , OneByteEnumParsable , Serializable , TwoByteEnumParsable
2424from cryptoparser .common .exception import NotEnoughData
2525from cryptoparser .common .parse import ByteOrder , ComposerBinary , ParsableBase , ParserBinary
2626
@@ -318,6 +318,20 @@ def compose(self):
318318 raise NotImplementedError ()
319319
320320
321+ class DnsRrTypePrivate (NumericRangeParsableBase ):
322+ @classmethod
323+ def _get_value_min (cls ):
324+ return 0xff00
325+
326+ @classmethod
327+ def _get_value_max (cls ):
328+ return 0xfffe
329+
330+ @classmethod
331+ def _get_value_length (cls ):
332+ return 2
333+
334+
321335@attr .s
322336class DnsNameUncompressed (ParsableBase , Serializable ):
323337 labels = attr .ib (
@@ -373,7 +387,7 @@ def compose(self):
373387class DnsRecordRrsig (ParsableBase ): # pylint: disable=too-many-instance-attributes
374388 HEADER_SIZE = 24
375389
376- type_covered = attr .ib (validator = attr .validators .instance_of (DnsRrType ))
390+ type_covered = attr .ib (validator = attr .validators .instance_of (( DnsRrType , DnsRrTypePrivate ) ))
377391 algorithm = attr .ib (validator = attr .validators .instance_of (DnsSecAlgorithm ))
378392 labels = attr .ib (validator = attr .validators .instance_of (six .integer_types ))
379393 original_ttl = attr .ib (
@@ -396,7 +410,10 @@ def _parse(cls, parsable):
396410
397411 parser = ParserBinary (parsable )
398412
399- parser .parse_parsable ('type_covered' , DnsRrTypeFactory )
413+ try :
414+ parser .parse_parsable ('type_covered' , DnsRrTypeFactory )
415+ except InvalidValue :
416+ parser .parse_parsable ('type_covered' , DnsRrTypePrivate )
400417 parser .parse_parsable ('algorithm' , DnsSecAlgorithmFactory )
401418 parser .parse_numeric ('labels' , 1 )
402419 parser .parse_numeric ('original_ttl' , 4 )
@@ -411,7 +428,10 @@ def _parse(cls, parsable):
411428 def compose (self ):
412429 composer = ComposerBinary ()
413430
414- composer .compose_numeric_enum_coded (self .type_covered )
431+ if isinstance (self .type_covered , DnsRrType ):
432+ composer .compose_numeric_enum_coded (self .type_covered )
433+ else :
434+ composer .compose_parsable (self .type_covered )
415435 composer .compose_numeric_enum_coded (self .algorithm )
416436 composer .compose_numeric (self .labels , 1 )
417437 composer .compose_numeric (self .original_ttl , 4 )
0 commit comments