ASN.1
support three kinds of data types.
a. Simple types like
INTEGER, BOOLEAN
b. Composite types like
SEQUENCE, SET
c. User-defined types
Below
table summarizes the data types supported by ASN.1.
Data Type
|
Description
|
Example
|
Boolean
is used to represent TRUE, FALSE states. It is similar to boolean type in
programming languages.
|
isPassedInExam
BOOLEAN
canIReadTheFile
BOOLEAN
|
|
It
is used to represent integer values. It do not have any upper and lower
limits, it can be of any magnitude.
|
id
INTEGER
age
INTEGER (15..60)
In
the second example, age is of type integer and the valid values are from 15
to 60.
|
|
Used
to represent bit arrays. Specific bits can be identified by parenthesized
integers and assigned names. It is used to model the binary data of arbitrary
length.
Values
can be represented in 3 possible forms:
binary
- '01'B,
hex
- '9'H, and
named
- {windowOpen, engineOn}
|
Ex
Occupation
::= BIT STRING {
clerk (0),
watchman (1),
engineer (2),
manager (3)
}
Hobbies
::= BIT STRING {
chess (0),
cricket (1),
hockey (2),
football (3),
others (4)
}
|
|
This
is used to represent binary data that is multiple of 8 bits. Octet string can
be of any length.
It
can be represented in two forms.
a.
Binary – '1000100'B
b.
Hexa - '44'H
|
Ex
id
OCTET STRING
|
|
Used
to represent date. It should be of the form "YYYY-MM-DD".
|
dateOfBirth
DATE
|
|
Used
to represent time of the day. It is of the form "HH:MM:SS"
|
startTime
TIME-OF-DAY,
endTime
TIME-OF-DAY
|
|
It
is used to represent date and time together. "YYYY-MM-DDTHH:MM:SS"
|
startTime
"2018-02-06T06:30:23"
|
|
Represent
decimal point numbers.
You
can represent real numbers in 2 ways.
a.
Decimal format like 546789.239
b.
Sequence format like {mantissa 546789239, base 10,
exponent -3}
|
salary
REAL
|
|
ENUMERATED
is used to model constants. If you have list of items, you can model them
using ENUMERATED type.
|
FavoriteColors
::= ENUMERATED {black, green, red, yellow, white}
|
|
It
is used to uniquely identify an entity like algorithm, certificate, (or)
organization. It is a sequence of integer components, and components usually
have non-negative value.
|
organizationCode
OBJECT IDENTIFIER
|
|
Used
to define collection of items.
|
Employee
::= SEQUENCE {
name VisibleString,
id VisibleString,
salary REAL
}
|
|
Used
to define collection of items of same type. It is similar to arrays in
programming languages.
|
favoriteColors
SEQUENCE OF VisibleString
|
|
Used
to select one item from collection of items
|
Motorcar
::= SEQUENCE {
carRegNumber VisibleString
}
Bicycle
::= SEQUENCE {
bicycleColor VisibleString,
bicycleModel VisibleString
}
Boat
::= SEQUENCE {
boatRegNumber VisibleString
}
PreferredVehicle
::= CHOICE { car Motorcar, bike Bicycle, boat Boat }
|
|
It
is an arbitrary string of IA5 (ASCII) characters. IA5 stands for
International Alphabet 5.
|
email
IA5String
|
|
Use
this type, when you want to use ASCII characters but not control characters
|
name
VisibleString
|
|
Use
this when you want a string with only numeric characters.
|
salary
NumericString
|
|
Use
this to create string with uni code characters.
|
name
UTF8String
|
|
NULL
|
Use
this to represent a variable with no value. It indicates the absence of an
element.
|
|
It
is similar to SEQUENCE except the type of each identifier must be different
from other identifier in the set and order of the elements doesn’t matter
here.
|
Person
::= SET {
name VisibleString,
id INTEGER,
salary REAL
}
|
|
It
is similar to SEQUENCE OF type, only difference, order of the items may not
be same at the receiver end. Suppose you sent the items like 1, 2, 3, but at
the receiver end you may receive like 2, 1, 3.
|
Person
::= SEQUENCE {
name VisibleString,
favoriteColors SET OF VisibleString
}
|
|
By
using ANY, you can supply any valid ASN.1 type while defining identifiers.
|
Every
type in ASN.1 has given a universal tag number to identify them uniquely.
Universal Tag
number
|
Type
|
0
|
reserved
for BER
|
1
|
BOOLEAN
|
2
|
INTEGER
|
3
|
BIT
STRING
|
4
|
OCTET
STRING
|
5
|
NULL
|
6
|
OBJECT
IDENTIFIER
|
7
|
ObjectDescriptor
|
8
|
INSTANCE
OF, EXTERNAL
|
9
|
REAL
|
10
|
ENUMERATED
|
11
|
EMBEDDED
PDV
|
12
|
UTF8String
|
13
|
RELATIVE-OID
|
14
|
Reserved
for future use
|
15
|
Reserved
for future use
|
16
|
SEQUENCE,
SEQUENCE OF
|
17
|
SET,
SET OF
|
18
|
NumericString
|
19
|
PrintableString
|
20
|
TeletexString,
T61String
|
21
|
VideotexString
|
22
|
IA5String
|
23
|
UTCTime
|
24
|
GeneralizedTime
|
25
|
GraphicString
|
26
|
VisibleString,
ISO646String
|
27
|
GeneralString
|
28
|
UniversalString
|
29
|
CHARACTER
STRING
|
30
|
BMPString
|
31
|
Reserved
for future use
|
No comments:
Post a Comment