This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Difference between IMPLICIT and EXPLICIT tags (ASN.1)

0

Can someone explain to me with an example how implicit tagging reduces overhead of number of bytes transfered in ASN.1 ?

Thanks.

asked 08 Jan '12, 12:17

mmalik10's gravatar image

mmalik10
1222
accept rate: 0%


2 Answers:

1

When using BER (BASIC ENCODING RULES) or DER (DISTINGUISHED ENCODING RULES), data for types are encoding using a Type-Length-Value format. Each primitive ASN.1 Type such as INTEGER has a UNIVERSAL TAG assigned by the ASN.1 standard. If you have just

A ::= INTEGER

This has a tag of UNIVERSAL 2, so an encoding of the interger value 5 in BER would be in hex 02 01 05.

B ::= [2] IMPLICIT INTEGER

For B, with an implicit tag, this says to replace the existing tag on INTEGER with [2], so the encoding in BER of the value 5 would be in hex 82 01 05.

C ::= [2] EXPLICIT INTEGER

For C, with an explicit tag, this says to add [2] in front of the existing tag, so the encoding in BER of the value 5 would be in hex A2 03 02 01 05.

There is a free ASN.1 book you can download from http://www.oss.com/asn1/resources/books-whitepapers-pubs/asn1-books.html which explains tagging in much more detail.

Paul

answered 18 Jan '12, 09:40

Paul's gravatar image

Paul
723
accept rate: 33%

edited 18 Jan '12, 10:46

which one of the books in that page do you recommend?

(29 May '12, 09:27) hablutzel1

Either of the first two books on that page are excellent. I have heard comments that the first one (by Olivier Dubuisson) might be easier to understand, while others enjoy the British humor punctuating the thorough explanations in the second one (by John Larmouth). Both are excellent resources.

(29 May '12, 10:03) Paul

0

Take this ASN1 description

Foo SEQUENCE of {

bar [1] Bar,

bar2 [2] Bar2 }

Bar ::= INTEGER

When EXPLICIT the encoding of the INTEGER type for Bar will be included adding at least 2 bytes, for IMPLICIT only the encoding of the tag will be there.

answered 09 Jan '12, 22:49

Anders's gravatar image

Anders ♦
4.6k952
accept rate: 17%

the encoding is clear but How decoder knows the real type of ASN.1 data?

(15 Dec '16, 02:05) IBrahim El-K...