Why ASN1?


ASN.1 is formal notation for describing data structures. An international standard, ASN.1 is used almost everywhere, but it works so well it's invisible.

It has proven to be the most interoperable means for describing information exchanged between systems. It is heavily used in telecommunications protocols (it's in your cellphone), Intelligent Transportation (cars talking to each other and with road infrastructure), IoT (sensors in smart homes/cities), Security/Fintech (encryption, financial data), RFID, Aviation/Satellite and other protocols that require robust communication.

Using ASN.1, you describe your data and an ASN.1 compiler will ensure that the generated code will encode and decode exactly in the same way without any effort from the user's side, in any programming language and on any platform.

Modern communication calls for more structure in the messages being exchanged, while maintaining enough flexibility to deal with an unpredictable, evolving environment.

ASN.1 takes care of the former by its very nature, i.e., it describes data in an abstract schema, independent of the bits-on-the-wire, and it validates messages for conformance with this schema. ASN.1 can easily handle the latter via support for JSON and tagged binary encodings, which are robust enough to withstand deviations from schema or even no schema at all.

Today there are many options for describing data structures that will be used by communication endpoints. Choices range from binary protocols such as Google Protocol Buffers or Apache Thrift, to text based protocols such as JSON (using JSON Schema).


So why ASN.1?


Broadly speaking, the ASN.1 schema, while offering the same validation semantics is more compact and easier to read and understand by a human. This is especially useful for large schemas. Try generating an ASN.1 schema for your JSON message here.

JSON Message

{
 "name": "Falcon",
 "message": "Hello World",
 "fuel": "liquid",
 "speed":
 {
   "mph":18000
 },
 "payload":
  [
   "Car",
   "GPS unit"
  ]
}
                    

ASN.1 Schema

World-Schema DEFINITIONS AUTOMATIC TAGS ::=  
BEGIN   Rocket ::=  SEQUENCE {
  name     UTF8String (SIZE (1..16)),
  message  UTF8String DEFAULT "Hello World",
  fuel     ENUMERATED {solid, liquid, gas, hybrid},
  speed    CHOICE {
        mph  INTEGER,
        kmph INTEGER
  } OPTIONAL,
  payload      SEQUENCE OF UTF8String
}
END
                    

JSON Schema

{
  "type" : "object",
  "title" : "Rocket",
  "required" : 
  [
    “name”,
    "fuel",
    "payload"
  ],
  "properties" : 
  {
    "name" : 
    {
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 16
    },
    "message" : 
    {
      "default" : "Hello World"
    },
    "fuel" : 
    {
      "type" : "string",
      "enum" : 
      [
        "solid",
        "liquid",
        "gas",
        "hybrid"
      ]
    },
    "speed" : 
    {
      "type":"object",
      "oneOf":
      [
        {
          "properties" : 
          {
            "mph":
            {
              "Type":"number"
            }
          }, 
         "additionalProperties":false
        },
        {
          "properties" :
          {
             "kmph":
             {
                "Type":"number"
             }
          }, 
          "additionalProperties":false
        }
      ]
     },
    "payload" : 
    {
      "type" : "array",
      "items" : 
      {
        "type" : "string"
      }
    }
  }
}