Friday 20 April 2018

ASN.1: Applying constraints on types

In ASN.1, you can specify constraints while defining types.

Restrict to specific values
rating VisibleString ("bad" | "average" | "good" | "excellent")

Restrict values to specific range
age INTEGER (1..100)

Restrict length of strings
name VisibleString (SIZE (3..50))

Example Schema
Employee ::= SEQUENCE {
    name VisibleString (SIZE (3..50)),
 age INTEGER (1..100),
 id VisibleString,
 rating VisibleString ("bad" | "average" | "good" | "excellent")
}

Sample data for above schema
employee Employee ::= {
    name "Rama Krishna",
    age 28
    id "I334213",
    rating "excellent"
}


XML Encoding of above data
<?xml version="1.0" encoding="UTF-8"?>
<Employee>
  <name>Rama Krishna</name>
  <age>28</age>
  <id>I334213</id>
  <rating>excellent</rating>
</Employee>




Previous                                                 Next                                                 Home

No comments:

Post a Comment