简体   繁体   中英

ASN.1 BER Sequence with undefined tags

I need to decode some BER messages that are quite long, and I have two different situations. One has a couple of mandatory parameters with no specific tags, and a lot of optional parameters with implicit tags. The other has only optional implicit tags, for instance :

Case 1:

MySeq ::= SEQUENCE  
{  
a TYPE1,  
b TYPE1,  
C TYPE1,  
-- first 3 elements have same type  
d IMPLICT [1] TYPEd OPTIONAL,  
e IMPLICT [1] TYPEe OPTIONAL,  

etc, and many more parameters, around 40, some of them constructed, with also constructed parameters inside.

Case 2:

MySeq ::= SEQUENCE  
{  
a IMPLICT [1] TYPEa OPTIONAL,  
b IMPLICT [2] TYPEb OPTIONAL,  
c IMPLICT [3] TYPEc OPTIONAL,  
d IMPLICT [4] TYPEd OPTIONAL,  
e IMPLICT [5] TYPEe OPTIONAL,  
etc  

The point is, I really need just 3 or 4 parameters from those messages.
I do not care about the rest. I don't want my decoder to spend so much processing time decoding the full message if I dont need it. Is there any standard way to do this ?
In the second case I came with an idea, to change the ASN.1 definition from SEQUENCE to SET,like :

MySeq ::= SET  
{  
a IMPLICT [1] TYPEa OPTIONAL,  
a20 IMPLICT [20] TYPEa OPTIONAL,  
a40 IMPLICT [40] TYPEa OPTIONAL,  
...  
}  

I mean, the parse will just decode those 3 parameters as a SET. Of course I will have to modify the binary message on reception to convert it from SEQUENCE to SET (just one bit). But I can't do that with the first SEQUENCE.
Is there any way to indicate to "ignore unknown tags" ?
I have read about the "EXTENSIBILITY IMPLIED", but I can't understand if that is what I need, or it just implies extensibility at the end of SEQUENCE, as if I was using the extensibility marker "...".

Thanks in advance,

Luis

Trying to fiddle with the SEQUENCE tag to change it to a SET tag is dangerous since a sequence can contain the same tag multiple times as long as there is a non-optional component between them. A SET cannot handle this. Also, decoding a SET is inherently more complicated than decoding a SEQUENCE in a robust manner since the decoder must be able to handle the components in any order.

Regarding EXTENSIBILITY IMPLIED, you are correct that it is the equivalent of adding the ... extension mark to the end of each SEQUENCE, SET and CHOICE type, so I am not sure this would help you. If it is not just at the end of each SEQUENCE that you need an extension mark, this may not be useful to you.

One alternative is to try using the "partial decoding" feature of the OSS ASN.1 Tools ( http://www.oss.com ) which allows you to select particular components of a message that you are interested in and skip past the others.

Disclosure: I work for OSS Nokalva, Inc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM