[erlang-questions] ASN1 - DEFAULT clause problem

Kenneth Lundin kenneth.lundin@REDACTED
Mon Dec 10 12:45:26 CET 2012


See embedded comments below

On Mon, Dec 10, 2012 at 11:37 AM, Bohuslav Svancara <bsvancara@REDACTED>wrote:

> Hello!
>
> I have some problem with ASN1.
>
> - I have this ASN1 definition in the Test.asn file:
>
> Test DEFINITIONS IMPLICIT TAGS ::=
>
> BEGIN
> EXPORTS Test;
>
> Test ::= SEQUENCE
> {
>    a INTEGER,
>    b INTEGER DEFAULT 0
> }
>
> END
>
> - I am using this comand:
>
> erl -eval asn1ct:compile(\"Test.asn\").
>

Recommended way to invoke the ASN.1 compiler is
erlc Test.asn # this is equivalent to what you did above.

This will generate code for BER encoding rules with input/output as a list
och integers 0..255

The most modern and fastest BER backend is invoked like this:
erlc -bber_bin +driver Test.asn

This will generate code for BER encoding rules with input/output as
binaries


> It works fine.
>
> But when I add a "DEFAULT 0" clause to the line "a INTEGER," so it looks
> like this:
>
>    a INTEGER DEFAULT 0,
>
> then asn1ct fails:
>
> 1> asn1error:7:'Test':'Test'
> {asn1,{duplicates_of_the_tags,[{'UNIVERSAL','INTEGER'}]}}
> 1>
>
> Why please?
>
> - Release of Erlang 5.9/OTP R15B
> - Windows 7 Prof 64-bit
>
> Sincerely,
> Bob
>
> ----------------------------------------------------
> Just for recap: Failing Test.asn looks like this:
>
> Test DEFINITIONS IMPLICIT TAGS ::=
>
> BEGIN
> EXPORTS Test;
>
> Test ::= SEQUENCE
> {
>    a INTEGER DEFAULT 0,
>    b INTEGER DEFAULT 0
> }
>
> END
>
>
The DEFAULT property on a component in a  SEQUENCE makes that property
optional , meaning that it can be omitted by the sender.

Since the BER encoding rules are used and the module default is IMPLICIT
TAGS
the tags for the components in a SEQUENCE must be unique (if there are 2 or
more optionals in a row). In this case , since no tags are introduced in
the syntax the
tags for both a and b component will be UNIVERSAL, INTEGER and the 2
components can not be distinguished from each other. That's why the
compiler reports an error.

In order to correct this you can either change module default to AUTOMATIC
TAGS or
add you own tags into the declaration like this:

Test ::= SEQUENCE
{
   a [0] INTEGER DEFAULT 0,
   b [1] INTEGER DEFAULT 0
}

Now you have two context specific unique tags 0 and 1 for the components
which will make it possible to distinguish as a receiver which component
(or both) that are
part of the message.

This is how ASN.1 works , it is not specific to the ASN.1 compiler in OTP


/Kenneth, Erlang/OTP, Ericsson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121210/c6dbd753/attachment.htm>


More information about the erlang-questions mailing list