kimgr / asn1ate

A Python library for translating ASN.1 into other forms.
Other
69 stars 41 forks source link

asn1ate generates incorrect code for DefaultedNamedType #69

Open russhousley opened 5 years ago

russhousley commented 5 years ago

RFC 4108 includes this syntax:

FirmwarePackageLoadReceipt ::= SEQUENCE { version FWReceiptVersion DEFAULT v1, hwType OBJECT IDENTIFIER, hwSerialNum OCTET STRING, ... }

FWReceiptVersion ::= INTEGER { v1(1) }

When I used asn1ate to compile the module, it did not handle this part properly.

It produced:

class FWReceiptVersion(univ.Integer): pass

FWReceiptVersion.namedValues = namedval.NamedValues( ('v1', 1) )

FirmwarePackageLoadReceipt.componentType = namedtype.NamedTypes( namedtype.DefaultedNamedType('version', FWReceiptVersion().subtype(value=v1)), namedtype.NamedType('hwType', univ.ObjectIdentifier()), namedtype.NamedType('hwSerialNum', univ.OctetString()), ... )

It should have produced:

class FWReceiptVersion(univ.Integer): pass

FWReceiptVersion.namedValues = namedval.NamedValues( ('v1', 1) )

FirmwarePackageLoadReceipt.componentType = namedtype.NamedTypes( namedtype.DefaultedNamedType('version', FWReceiptVersion().subtype(value='v1')), namedtype.NamedType('hwType', univ.ObjectIdentifier()), namedtype.NamedType('hwSerialNum', univ.OctetString()), .... )