Decoding ASN1 UPER in Python
<p>I need to decode ASN1 message using python. I looked into the pyasn1 library but it doesn't support UPER. What can I use to decode ASN1 UPER in python</p>

<p><strong>Got the Schema?</strong></p>

<p>Assuming you have the ASN.1 schema for the data you're trying to decode, you could start by taking a look at the <a href="http://taste.tuxfamily.org/wiki/index.php?title=ASN.1_generators" rel="nofollow">TASTE framework from the European Space Agency</a>. This is a large application development framework based on ASN.1 for spacecraft system.</p>

<p>The framework is irrelevant to you and your needs. However, lurking somewhere in the core of it as an ASN.1 schema compiler that supports Python code generation and uPER. You might best start by trying out their pre-built VM image that gives you a linux with everything already installed: <a href="http://taste.tuxfamily.org/wiki/index.php?title=Main_Page#Tool_availability" rel="nofollow">see here</a>. You'd use this to compile the schema into python source code that can then encode / decode uPER data from/to Python classes. As an aside, you could also do the same for C, C++, C#, Java, ADA. </p>

<p>I've not tried it out in much anger myself, but there's many an ESA spacecraft flying having been built using it, so it's probably all OK.</p>

<p><strong>Not Got the Schema?</strong></p>

<p>If you don't have the schema, well then you're going to have some problems. uPER cannot be decoded without the schema file. This is because the uPER data is sufficiently packed that there's little evidence of the data's structure left. You'd be reduced to guessing what the schema might have been, trying out a decode, see if it works on all your data, try again if not. </p>

<p>If it were known to be Cannonical PER encoded then you can decode it without the schema, but that's still a lot of effort.</p>

<p>This is in sharp contrast to BER encoded data, which does retain details of the data's structure by incorporating tag, type and value information for every encoded PDU field. But then BER encoded data is much larger that PER, so it's not used on radio systems or other bandwidth constrained transmission channels.</p>

<p>==EDIT==</p>

<p>Having just taken a look over there at TASTE I'm now not sure that it does generate Python code. Python is a dependency for the framework, but it's not claiming anywhere that it generates Python code. Looks like it's just C/C++ or ADA.</p>

<p>Regardless, the ASN.1 compiler seems to have ended up <a href="https://github.com/ttsiodras/asn1scc" rel="nofollow">here on GITHUB</a>. That will generate C code (and ADA, wow!), which you could call from your Python one way or another. It' won't be quite as tidy, but still better than nothing. </p>

<p><strong>Note</strong> This compiler is limited in what schema it will compile (it needs size constraints on arrays, etc, presumably to end up with static sized objects).</p>

<p>Your best bet might be to call C, C++, or Java or C# code generated by other ASN.1 compilers - there's commercial ones over at <a href="http://www.obj-sys.com/" rel="nofollow">Objective Systems</a> and <a href="http://www.oss.com/index.html" rel="nofollow">OSS Nokalva</a>.</p>

<p>==Yet Another Edit==</p>

<p><a href="https://www.thanassis.space/asn1.html" rel="nofollow">This page</a> talks about Python, ASN.1 uPER.</p>

<p>==Encore un Edit==</p>

<p>The <a href="http://pyasn1.sourceforge.net/" rel="nofollow">PyASN1</a> page refers to <a href="https://github.com/kimgr/asn1ate" rel="nofollow">asn1ate</a>, which is a code generator for Python. It is reported to be 'alpha quality', but for a simple schema it may be adequate. It's certainly worth a look.</p>

python decode asn.1