Resources
Whether you're an experienced user or just starting, it may be hard to pick the right schema technology out of many popular alternatives such as ASN.1, JSON schema, and Google Protocol Buffers. There are two important factors that may help you with your decision - schema expressivity and schema authority. Both will allow your solution to grow without compromising its integrity and to avoid punitive costs.
Writing a schema requires a good balance between being under- and over-expressive. For example, writing a JSON schema can easily include both extremes. On one hand, it allows defining only parts of the entire message, and on the other hand, it enables complex (algorithmic) expressions (such as if/then, not, anyOf/allOf, etc.), which can be difficult to follow.
An under-expressive schema is almost like having no schema at all, as it lacks the structural integrity of the data it's supposed to validate.
An over-expressive schema can be difficult to interpret and is prone to human errors, e.g. its semantics can be easily "lost in translation".
An ASN.1 schema offers a middle ground. It requires a complete definition of every field in the message and it is easily read by a human/designer.
A schema for a basic empty object:
JSON Schema | ASN.1 Schema |
---|---|
{ "additionalProperties": false, "definitions": {}, "description": "Empty Object", "properties": {}, "type": [ "object", "null" ] } |
-- Empty Object
EmptyObject ::= SEQUENCE {}
|
Schema evolution is a boon. However, technologies that are too permissive, offering extensive backward and forward compatibility, are prone to spill the data validation throughout the entire application code base. In the end, whether you want it or not, when you choose to communicate with Protobuf or JSON Schema, you have to use more developers and spend more time to ensure the sanity of your data.
An ASN.1 schema allows extensibility (an evolution) as well, but it does this in a predictable way, at compile-time (as in strongly-typed data), ensuring schema authority and a well-defined boundary for the validation logic. ASN.1 technology offers a "right time, right place" solution for scaling larger applications without compromising data integrity.
ASN.1 is primarily used in telecommunications and computer networking, yet its applications can go beyond these conventional uses:
PER is a compact binary encoding that significantly reduces the data size, which is especially useful in bandwidth-constrained environments.
A ::= INTEGER (1234567..1234570) a A ::= 1234568 -- encoded in 2 bits
ASN.1's flexibility allows for complex data structures to be easily shared and understood across various systems.
ASN.1's clear and structured format makes it easy to generate and validate test data.
Structured documents and messages stored in a format defined by ASN.1 can be read and interpreted in the future, regardless of changes in technology.
In software development, applications often require a reliable method to handle command-line arguments and configuration parameters. These inputs can range from simple options to complex configurations. Ensuring correct syntax and validation is crucial for application stability and security. Traditional methods using custom parsing and validation can be error-prone and difficult to maintain.
The ASN.1 schema can also be considered as the application synopsis. It's easy to follow, eliminates interpretation ambiguity, and is both rigorous and extensible:
AppParameters ::= SEQUENCE { inputFile UTF8String, outputFile UTF8String, loggingOptions LoggingOptions OPTIONAL } LoggingOptions ::= SEQUENCE { logLevel ENUMERATED {debug, info, warn, error} DEFAULT error, logFile UTF8String OPTIONAL -- no file means console }
From this schema, an ASN.1 compiler can generate bindings (structures that can be populated with command-line arguments and configuration file parameters) and validation code for the programming language of your choice.
Using ASN.1 provides a standardized, robust, and extensible solution. By leveraging ASN.1's capabilities, developers can ensure their applications handle inputs correctly, enhancing stability and security while reducing the maintenance burden associated with custom validation logic.