Search code examples
pythonpython-2.7asn.1pyasn1

How to parse Object Class from ASN1 grammar to use in pyasn1?


I need to use GSM MAP ASN.1, but there is one Information Object Classes (or here) in that specification and I don't know how to parse this grammar to use in pyasn1 lib.

Is there some way (or workaround) to parse it?

Here is the case (Taken from 3GPP TS 29.002 V12.3.0):

MAP-EXTENSION  ::= CLASS {
    &ExtensionType              OPTIONAL,
    &extensionId    OBJECT IDENTIFIER }
    -- The length of the Object Identifier shall not exceed 16 octets and the
    -- number of components of the Object Identifier shall not exceed 16

-- data types

ExtensionContainer ::= SEQUENCE {
    privateExtensionList    [0]PrivateExtensionList OPTIONAL, 
    pcs-Extensions  [1]PCS-Extensions   OPTIONAL,
    ...}

SLR-ArgExtensionContainer ::= SEQUENCE {
    privateExtensionList    [0]PrivateExtensionList OPTIONAL, 
    slr-Arg-PCS-Extensions  [1]SLR-Arg-PCS-Extensions   OPTIONAL,
    ...}

PrivateExtensionList ::= SEQUENCE SIZE (1..maxNumOfPrivateExtensions) OF
                PrivateExtension

PrivateExtension ::= SEQUENCE {
    extId       MAP-EXTENSION.&extensionId
                ({ExtensionSet}),
    extType     MAP-EXTENSION.&ExtensionType
                ({ExtensionSet}{@extId})    OPTIONAL}

maxNumOfPrivateExtensions  INTEGER ::= 10

ExtensionSet        MAP-EXTENSION ::=
        {...
         -- ExtensionSet is the set of all defined private extensions
    }   
    -- Unsupported private extensions shall be discarded if received.

PCS-Extensions ::= SEQUENCE {
    ...}

SLR-Arg-PCS-Extensions ::= SEQUENCE {
    ...,
    na-ESRK-Request [0] NULL        OPTIONAL }

Solution

  • As of this moment, pyasn1 only implements X.208, not X.68*. That means that the newer ASN.1 constructs (such as information object classes) are not directly supported yet.

    The good news is that there is certain degree of backward compatibility between X.68* and X.208 built into the standard. Depending on the X.68* features being used in your ASN.1 spec, you may be able to downgrade your ASN.1 definition from X.68* to X.208 without losing wire-level protocol compatibility with the fully-fledged X.68* entity at the other end of the connection. Once you managed to convert one spec into the other, you should be able to use pyasn1.

    There is also a work-in-progress branch which automates the ANY DEFINED BY X.208 construct's working so that it is all handled automatically by pyasn1.