简体   繁体   中英

Constrain the indexes for SEQUENCE OF types in ASN.1

Is it possible in ASN.1 to add a constraint for the available indeces of a SEQUENCE OF type? Something along the lines of this

MyArray ::= SEQUENCE (1..10) OF INTEGER -- MyArray has 10 elments indexed from 1-10
Array2  ::= SEQUENCE (-5..5) OF INTEGER -- Array2 has 11 elments indexed from -5-5

I tried to get it out of the ASN.1 book from Dubuisson, but I am not completely sure I understand the grammar description correctly.

My current understanding is that it is possible to create constraints on the sizes of a SEQUENCE OF, but it is not foressen to have any influence on the indexing behavior. I assume this is left to the implementation language to define?

Is this correct?

In ASN.1 there is no concept of "index" for a SEQUENCE OF. Your assignments above are both invalid.

You can specify a constraint on the number of elements of a SEQUENCE OF. For example, if you write

A1::= SEQUENCE (SIZE (10)) OF INTEGER

you are restricting the number of elements to 10. Any value of this SEQUENCE-OF type will have to have exactly 10 elements.

If you write

A2::= SEQUENCE (SIZE (1..10)) OF INTEGER

any value of this SEQUENCE-OF type will have to have at least 1 element and at most 10 elements. In this case, the number of elements is restricted to a range of sizes rather than to a fixed size.

You can also write more complex constraints like the following:

A3::= SEQUENCE (SIZE (1 | 4 | 6..MAX)) OF INTEGER

In this case, any value of this SEQUENCE-OF type must have 1, 4, or 6 or more elements. For example, the values {2} and {-5, 5, 1, -3} are valid values, whereas {1, 2} is not.

You cannot use a negative integer in a size constraint because the integer you use specifies a number of elements, not an index value.

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