Is there a good C ++ library for reading, creating and modifying BER-encoded files?

There are several tools that can automatically generate C ++ (or other) code for reading and writing BER-encoded files. In my C ++ project, I need libraries to read and modify BER-encoded files. I cannot generate C ++ classes based on a given data structure because there is no data structure data. The user should be able to add and remove integers, strings, etc. I found an open source project that has an editor with the following features: http://www.codeproject.com/Articles/4910/ASN-1-Editor

However, this is in C # ....

Please let me know if you know how I can get a good C ++ library with this functionality that I can use for my C ++ project.

+7
source share
2 answers

Make sure you have the correct ASN definition file. Then go to the link http://lionet.info/asn1c/asn1c.cgi

Paste your ASN definition into the specified window. Click the Continue with ASN.1 Compilation button. If you get a compilation error, fix them. After successful compilation, it will generate code for your decoder. Give it a try.

+2
source

There are not many common BER reading libraries, because it is IMPOSSIBLE to unambiguously analyze arbitrary BER data without at least some knowledge of the schema.

The tool that you point to CodeProject edits the ASN.1 schemes that are used to create BER encodings, but you CANNOT go in the other direction without knowing the data or guessing. It is impossible to tell by looking at the id and length of the BER element whether this element contains primitive data or other BER elements.

Here is the smallest example I gave to demonstrate the problem, with only 5 bytes, with two radically different interpretations:

0xA0 0x03 0x02 0x01 0x00 

Now this is an explicitly constructed, context-sensitive type. It also has a certain length. But what's inside? You can not say!

It can be an integer (0x02 is a primitive tag for an integer, 0x01 is len, value 0x00).

But it can also be a bit string (you can put the bit string in the constructed type, and then 2 is the number of bits not used at the end, which means that we have 14 bits that go 0000 0001 0000 00xxb = 00 0000 0100 0000b = 0x0040.

You can write an editor that will read / modify / write BER files, but it must know the scheme, or it will not be able to read anything correctly.

+2
source

All Articles