kimgr / asn1ate

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

VisibleString Bug #18

Closed torombolo17 closed 9 years ago

torombolo17 commented 9 years ago

Hello, I was using pyasn1gen.py and I found a bug. I used it with wireshark's sv.asn and one of the things it gave me was:

namedtype.OptionalNamedType('datSet', VisibleString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))

I tried to run this and it gave me this error:

namedtype.NamedType('svID', VisibleString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))), NameError: name 'VisibleString' is not defined

After I investigated I found that the VisibleString is defined in char.py but it isn't introduced to your _ASN1_BUILTIN_TYPES in pyasn1gen.py. I fixed this by adding 'VisibleString': 'char.VisibleString' to the BUILTIN dictionary so that when you generate the pyasn1 youll get the char.VisibleString(). Another way to solve this is to import the library as follows:

from pyasn1.type.char import VisibleString

If you import VisibleString this way then VisibleString() will work just fine. Besides that I think the library is really useful, great job.

If you want me to make a merge request just let me know. Thanks!

kimgr commented 9 years ago

Thanks for the report!

It would be useful if you could share the original ASN.1 definition (from Wireshark), but if it's licensed for private use, can you reduce the problem to a minimal ASN.1?

torombolo17 commented 9 years ago

Greetings,

Sorry for the delay. Here is the ASN.1 definition:

IEC61850 DEFINITIONS ::= BEGIN

SampledValues ::= CHOICE { savPdu [APPLICATION 0] IMPLICIT SavPdu, ... }

SavPdu ::= SEQUENCE { noASDU [0] IMPLICIT INTEGER(0..65535), seqASDU [2] IMPLICIT SEQUENCE OF ASDU }

ASDU ::= SEQUENCE { svID [0] IMPLICIT VisibleString, datSet [1] IMPLICIT VisibleString OPTIONAL, smpCnt [2] IMPLICIT INTEGER(0..65535), confRef [3] IMPLICIT INTEGER(0..4294967295), refrTm [4] IMPLICIT UtcTime OPTIONAL, smpSynch [5] IMPLICIT INTEGER{none(0),local(1),global(2)} OPTIONAL, smpRate [6] IMPLICIT INTEGER(0..65535) OPTIONAL, seqData [7] IMPLICIT Data, smpMod [8] IMPLICIT INTEGER{samplesPerNormalPeriod(0),samplesPerSecond(1),secondsPerSample(2)} OPTIONAL, ... } UtcTime ::= OCTET STRING Data ::= OCTET STRING END

You can find it in Wireshark's source code download under the asn1 directory

kimgr commented 9 years ago

Thanks, fixed!