2020 Course Design Week1 Asn.1 format learning

2020 Course Design Week1 Asn.1 format learning

1. Introduction

  • ASN.1 (Abstract Syntax Notation dotone) , Abstract Syntax Notation 1. It is a standard that defines the form of abstract data types, and is a notation for describing data representation, representation, transmission, and encoding.

  • ASN.1 only contains information structure, does not deal with specific business data , it is not a programming language .

  • ASN.1 encoding method is not limited , various ASN.1 encoding rules provided by the transfer syntax ASN.1 value syntax description abstract data (specific expression), a common encoding rules are: Basic Encoding Rules (the BER) , Canonical encoding rules (CERs, CanonicalEncoding rules) , the unique code rules (DER, DistinguishedEncoding rules) , Packed encoding rules (PER, PackedEncoding rules) and X- ML encoding rules (the XER, xmlEncoding rules) . These coding rules describe how to translate the values ​​defined in ASN.1 into suitable transmission codes.

  • ASN.1 is specified in OSI's ISO8824 / ITU X.208 (explaining syntax) and ISO8825 / ITU X.209 (explaining basic encoding rules) .

  • Several concepts:

  • Actual grammar: refers to actual programming languages ​​such as C, ObjectiveCaml, etc .;
  • Abstract syntax (AbstractSyntax): Refers to ASN.1, which is the description text described by the protocol using the ASN.1 specification. Depicts a general data structure that is independent of any encoding technology that represents data. Abstract syntax enables people to define data types and specify the values ​​of these types. The abstract syntax only describes the structure of the data and has nothing to do with the specific encoding format, nor does it involve how these data structures are stored in the computer.
  • Transfer Syntax (TransferSyntax): Refers to the representation method of data exchange at the presentation layer, which is the code stream between actual communication systems. When data is transferred between two presentation layer entities, the actual bit pattern representation of these data is the transfer syntax.
  • Coding: refers to the conversion of abstract language methods into bit streams between actual communication systems;
  • Encoding rules: the grammatical rules followed by converting abstract language methods into bit streams between actual communication systems;

2. Basic grammar rules of ASN.1

  • ASN.1 uses the Bacos paradigm (BNF):
  • The word ("word") in double quotes represents these characters themselves. And double_quote is used to represent double quotes.
  • The words outside the double quotes (there may be underscores) represent the grammatical part.
  • The angle brackets (<>) are required.
  • The square brackets ([]) are optional.
  • The braces ({}) contain items that can be repeated from 0 to countless times.
  • The vertical bar (|) indicates that you can choose one of the left and right sides, which is equivalent to "OR".
  • :: = means "defined as".
  • In ASN.1, the definition of symbols has no order: as long as the definition of the symbol can be found.
  • All identifiers, references, and keywords must start with a letter, followed by a letter (both uppercase and lowercase), digits, or the hyphen "-" (but cannot end with a hyphen "-", or two consecutive characters Hyphens), the underscore "_" cannot appear. Comments start with-and end with-or end of line.
  • Keywords are generally all capitalized.
  • Among identifiers, only type and module names begin with uppercase letters, and other identifiers begin with lowercase letters.
  • In ASN.1, real numbers are actually defined as three integers: mantissa, cardinality, and exponent. There is no decimal representation.
  • ASN.1 does not translate spaces, tabs, line breaks and comments. However, there must be no delimiter in the definition symbol (or assignment symbol) ":: =".

3. Types in ASN.1

Type is a non-empty set of values ​​that can be encoded and transmitted. Compared with the complex data structures in high-level languages, the types in ASN.1 are mainly for data transmission.

The types in ASN.1 are divided into basic types (built-in data types) and combined types. The combined types consist of one or more basic types.

1. Basic types

Types of meaning
BIT STRING Bit string
BOOLEAN Boolean
INTEGER Integer
NULL Null value
OBJECT IDENTIFIER Object identifier
OCTET STRING Byte string
PrintableString Printable string
UTCTime "Coordinated Universal Time"
GeneralizedTime Universal time

2. Construction type

  • Complex things can be viewed as simple collections or sequences of things.
  • Collections are order-independent, while sequences are order-dependent.
  • Construction types are used to describe complex things, including several fields (simple types or other construction types).
  • ASN.1 defines four construction methods, describing various situations of order and disorder.

2.1SEQUENCE

  • Represents an ordered sequence of one or more fields, for example:

     ReportEntry ::= SEQUENCE { 
       author OCTET STRING, 
       title OCTET STRING, 
       body OCTET STRING, 
       biblioBook Bibliography 
       } 
    
  • User-defined type names and identifier capitalization rules
    Type names are capitalized in camel case, such as "ReportEntry"
    identifiers are capitalized in camel case, such as "biblioBook"

2.2SEQUENCE OF

  • Represents an ordered sequence of 0 or more fields of a specific type, for example:

     Report ::= SEQUENCE SIZE (100) OF ReportEntry
     Report ::= SEQUENCE SIZE (MAX) OF ReportEntry
    

2.3SET

  • Represents an unordered set of one or more fields, for example:

     Menu ::=SET{
     	sandwich Food,
     	coke Beverage
     }
    

2.4SET OF

  • Represents an unordered set of 0 or more fields of a specific type, for example:

     Class ::= SET SIZE (50) OF Student
    

2.5 Use ASN.1 to write a data structure

  • Based on various construction methods, the basic data types are hierarchically nested to finally construct a data structure that can describe any abstract thing.

  • E.g:

       Bibliography ::= SEQUENCE { 
       	author OCTET STRING 
       	title OCTET STRING 
       	publisher OCTET STRING 
       	year OCTET STRING 
       } 
    

3. Other keywords

  • CHOICE: Choose one of several types
  • ANY: A field in the constructed type depends on the values ​​of other fields (ANY DIFINED BY)
  • OPTIONAL: a field in the construction type is optional
  • DEFAULT: Specify the default value of a field in the construction type

Guess you like

Origin www.cnblogs.com/Brass/p/12711196.html