简体   繁体   中英

How to express a ASN.1 value with universal tags when encoded using BER encoding rule?

According to http://asn1-playground.oss.com/ , with the following ASN.1 schema,

Test DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
    A ::= SEQUENCE {
      int INTEGER,
      seq SEQUENCE { int INTEGER, bool BOOLEAN },
      u UTF8String
    }  
END

the following value (in the ASN.1 Value Notation format)

a A ::= 
{  
    int 1,
    seq { int 2, bool TRUE },
    u "ABC"
}

is expressed in the following 18 bytes using BER encoding rule

30   10
    80   01   01
    A1   06  
        80   01   02
        81   01   FF
    82   03   414243

which is parsed by CyberChef into the following ASN.1 tree

SEQUENCE
  [0] 01
  [1]
    [0] 02
    [1] FF
  [2] 414243

It thus seems that the value is expressed with application tags. Could you help to comment whether and how the value could be transformed with the universal tags into the following 18 bytes

30   10
    02   01   01
    30   06  
        02   01   02
        01   01   FF
    0C   03   414243    

which would give the following better ASN.1 tree when parsed by CyberChef

SEQUENCE
  INTEGER 01..(total 1bytes)..01
  SEQUENCE
    INTEGER 02..(total 1bytes)..02
    BOOLEAN TRUE
  UNKNOWN(0C) 414243

Many thanks for your efforts !

It seems that the reason is "AUTOMATIC TAGS" is used at the beginning of the module, enforcing context specific tags for components of all SEQUENCE, SET and CHOICE types. The value can be expressed with universal tags if "AUTOMATIC" is changed to "EXPLICIT"

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