0

I have a question about explicit and implicit tagging, in the following example

X ::= [APPLICATION 5] IMPLICIT INTEGER

for X, since the implicit tag will replace the existing tag on INTEGER with [APPLICATION 5], so the encoding in BER of the value 5 would be in hex 45 01 05. How does the decoder know the type from 45 01 05?

Cœur
  • 37,241
  • 25
  • 195
  • 267
ibrahim
  • 37
  • 8

4 Answers4

1

I suspect your real question is, "How can a BER decoder know what to do when implicit tags are used and these tags replace the tags that would otherwise signal the ASN.1 type that needs to be decoded?"

Whether the decoder can handle IMPLICIT tags depends on whether the decoder is informed by the ASN.1 specification, which provides the necessary context. There are requirements imposed on the components of SEQUENCE, SET, and CHOICE to ensure that a decoder can read a tag and know which component needs to be decoded and, therefore, what the type is. This requires knowledge of the ASN.1 specification.

By contrast, a generic BER decoder that is not informed by the ASN.1 specification will have a problem with implicit tags, because it lacks the necessary context to interpret them.

Kevin
  • 1,876
  • 12
  • 17
0

The only way for the decoder to recover original type from octet stream is to know that it is coming. AFAIK, your decoder should be given a hint on what type to expect in given circumstances and, most importantly, into what base ASN.1 type that implicitly tagged type maps.

Consider checking out this book.

Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21
0

Usually, the BER decoder is generated by an ASN.1 compiler based on the given specification (schema). Then, during the decoding, beside the input encoded data, the users will also specify the type that they want to decode. Using the type information the decoder will know what to decode.

Andrei Bozantan
  • 3,781
  • 2
  • 30
  • 40
-1

First ,I have cheked a book of "ASN.1 Communication between Heterogeneous Systems" that send me Ilya Etingof , the following shows more detaills:

"The IMPLICIT marker proceeds as follows: all the following tags, explicitly mentioned or indirectly reached through a type reference are ignored until the next occurrence (included) of the UNIVERSAL class tag (except if the EXPLICIT marker is encountered before). So, for the type T below:

T ::= [1] IMPLICIT T1

T1 ::= [5] IMPLICIT T2*

T2 ::= [APPLICATION 0] IMPLICIT INTEGER

only the tag [1] should be encoded. Another way of explaining the concept of implicit tagging is to say that a tag marked IMPLICIT overwrites the tag that follows it (recursively); hence, for the example above, tag[1] overwrites tag [5], which in turn overwrites tag [APPLICATION 0] which fnally overwrites the default tag [UNIVERSAL 2] of the INTEGER type.

A type tagged in implicit mode can be decoded only if the receiving application `knows' the abstract syntax, i.e. the decoder has been generated from the same ASN.1 module as the encoder was (and such is the case most of the time)."

So i guess that a negociation of (ASN1 specification)should be perfermed in the presentation layaer at the begining of transfert of data.

ibrahim
  • 37
  • 8
  • This answer is incorrect. The ASN.1 standards are free and much easier to use that the various popular books, and also more correct. The answer in this case is found in [X.690](https://www.itu.int/rec/T-REC-X.690-202102-I/en), section 8.14, which comes complete with examples on pages 11 and 12. Their examples are for the value `"Jones"` for types `Type1 ::= VisibleString`, `Type2 ::= [APPLICATION 3] IMPLICIT Type1`, `Type3 ::= [2] Type2`, `Type4 ::= [APPLICATION 7] IMPLICIT Type3`, and `Type5 ::= [2] IMPLICIT Type2`. The encoding of it as Type4 and Type 3 differ only in the outer tag. – user2259432 Nov 01 '22 at 03:33
  • My copy of ASN.1 Communication between Heterogeneous Systems, on page 216 agrees with X.690, and contradicts itself from page 213 (which is where the text you posted is)! Clearly the book itself is in error in one or the other place. But X.690, section 8.14 makes it all abundantly clear by including examples. It is well known that several of the ASN.1 books out there have errors. I recommend using the books only to learn the concepts, then just go straight to the specs. – user2259432 Nov 01 '22 at 03:41