ASNP

39
ASN.1 Tomado de: http://www.obj- sys.com/asn1tutorial/asn1only.html

Transcript of ASNP

ASN.1

Tomado de: http://www.obj-sys.com/asn1tutorial/asn1only.html

Purpose of ASN.1

ASN.1 is a fundamental tool for use by applications. It provides the ability to describe the information that will be exchanged independent of the way that information is represented on each of the communicating systems

Modules

The fundamental unit of ASN.1 is the module.

The sole purpose of a module is to name a collection of type definitions and/or value definitions (assignments) that constitute a data specification.

A type definition is used to define and name a new type by means of a type assignment and a value definition is used to define and name a specific value, when it is necessary, by means of a value assignment.

ModulesModule reference optional object identifierInventoryList {1 2 0 0 6 1} DEFINITIONS ::= BEGIN{ ItemId ::= SEQUENCE { partnumber IA5String,

quantity INTEGER, wholesaleprice REAL, saleprice REAL } StoreLocation ::= ENUMERATED {

Baltimore (0), Philadelphia (1),

Washington (2) }} END

Type Assignment

InventoryList {1 2 0 0 6 1} DEFINITIONS ::=BEGIN {

ItemId ::= SEQUENCE {partnumber IA5String,quantity INTEGER, wholesaleprice REAL,

saleprice REAL } StoreLocation ::= ENUMERATED {

Baltimore (0), Philadelphia (1),Washington (2)

} } END Type reference (name of the type)Component value

Value Assignment

A value assignment consists of a value reference(the name of the value), the type of the value, ::= (``is assigned the value''), and a valid value notation.

gadget ItemId ::= {

partnumber "7685B2", quantity 73,

wholesaleprice 13.50,

saleprice 24.95 )

defines ``gadget" as a value of type ``ItemId".

Built-in Types

ASN.1 has built-in types that are simple and structured. Structured types are composed of component types, each of which is a simple or structured type. A user-defined type is composed of simple and structured types.

ASN.1 also has another category of types called useful, which provide standard definitions for a small number of commonly used types.

Simple Types

ASN.1 has built-in types that are simple and structured. Structured types are composed of component types, each of which is a simple or structured type. A user-defined type is c

ASN.1 also has another category of types called useful, which provide standard definitions for a small number of commonly used types. omposed of simple and structured types.

Simple Types

Type BOOLEAN takes values TRUE and FALSE. Usually, the type reference for BOOLEAN describes the true state.

For example:

Female ::= BOOLEAN

is preferable to

Gender ::= BOOLEAN.

Simple TypesType INTEGER takes any of the infinite set of integer values. It has an additional notation that names some of the possible values of the integer. For example,

ColorType ::= INTEGER {

red (0)

white (1)

blue (2) }

indicates that the ``ColorType" is an INTEGER and its values 0, 1, and 2 are named ``red", ``white", and ``blue", respectively. The ColorType could also have any of the other valid integer values, such as 4 or -62.

Simple TypesType BIT STRING takes values that are an ordered sequence of zero or more bits. The bit sequence is either a binary or hexadecimal string delimited by single quotes followed by B or H, respectively.Occupation ::= BIT STRING{

clerk (0) editor (1) artist (2) publisher (3) }

names the first bit ``clerk", the second bit ``editor", and so on.(editor, artist) and '0110'B are two representations for the same value of ``Occupation".

Simple Types• Type OCTET STRING takes values that are an

ordered sequence of zero or more eight-bit octets.

• The sequence is written in the same form as a BIT STRING sequence.

• Thus, `1101000100011010'B and `82DA'H are valid values of OCTET STRING.

Simple Types• Type OBJECT IDENTIFIER names information

objects (for example, abstract syntaxes or ASN.1 modules).

• A list of positive numbers, enclosed in braces and ordered by level starting from the root, uniquely identifies an information object at a node of the tree. This ordered list of positive numbers delimited by braces is the value notation for type OBJECT IDENTIFIER.

Simple Types

Simple TypesType REAL takes values that are the machine representation of a real number, namely the triplet (m, b, e), where m is the mantissa (a signed number), b the base (2 or 10), and e the exponent (a signed number).

For example, the representation of the value 3.14 for the variable Pi, declared as

Pi ::= REAL,

can be

(314, 10, -2).

Simple Types

Type ENUMERATED is similar to the INTEGER type, but names specific values only.

ColorType ::= ENUMERATED {

red (0)

white (1)

blue (2) }

ColorType can take only the values specifically in the list;

Simple Types

Type CHARACTER STRING takes values that are strings of characters from some defined (ISO- or CCITT-registered) character set.

if Address is of type PrintableString, then ``Villanova, PA 19085'' is an Address value.

Structured TypesType SEQUENCE is an ordered list of zero or more component types. The type notation requires braces around the list and permits a local identifier preceding the list to act as the name of the sequence type.

There are two ways to specify that a component type is optional in the ordered list: using OPTIONAL after the component type and using DEFAULT followed by a value after the component type. When DEFAULT is used, the specified value is assumed whenever the type is absent from the list. Any of the component types can be an embedded sequence, in which case COMPOSED OF precedes the embedded sequence.

Structured TypesThe value notation for each sequence type is the list of component values within braces.{ airline "American",

flight "1106",seats { 320, 107, 213 }, airport { origin "BWI", destination "LAX" }, crewsize 10 }

or { "American", "1106", { 320, 107, 213 }, { "BWI", "LAX" }, 10 }represent the same instance of the sequence type

Structured TypesThe value notation for each sequence type is the list of component values within braces.{ airline "American",

flight "1106",seats { 320, 107, 213 }, airport { origin "BWI", destination "LAX" }, crewsize 10 }

or { "American", "1106", { 320, 107, 213 }, { "BWI", "LAX" }, 10 }represent the same instance of the sequence type

Structured TypesAirlineFlight ::= SEQUENCE {

airline IA5String, flight NumericString, seats SEQUENCE {

maximum INTEGER,occupied INTEGER, vacant INTEGER },

airport SEQUENCE {origin IA5String, stop1 [0] IA5String OPTIONAL,stop2 [1] IA5String OPTIONAL,

destination IA5String }, crewsize ENUMERATED { six (6), eight (8), ten (10) },

cancel BOOLEAN DEFAULT FALSE }.

Structured TypesTwo components, Stop1 and Stop2 of the sequence type airport are tagged with the context-specific tags [0] and [1] to avoid ambiguity due to consecutive optional components not having distinct types. Without the tags, the definition of airport would be invalid in ASN.1.

Structured TypesType SEQUENCE OF is similar to SEQUENCE, except that all values in the ordered list must be of the same type.

Structured TypesType SET takes values that are unordered lists of component types. The type and value notations for SET are similar to SEQUENCE, except that the type of each component must be distinct from all others and the values can be in any order

{"Maggie", 4, TRUE} {TRUE, "Maggie", 4} {4, TRUE,"Maggie"} are three representations of the same instance of Person ::= SET {

name IA5String,age INTEGER,female BOOLEAN }.

Structured TypesType SET OF takes values that are unordered lists of a single type.

Structured TypesType CHOICE takes one value from a specified list of distinct types.. The value notation is that for the type chosen. For example, each of the three values,

(1) nothing TRUE, (2) car "Lincoln", (3) cash 25000

is a valid instance of

Prize ::= CHOICE {

car IA5String,

cash INTEGER,

nothing BOOLEAN }.

Structured TypesType SELECTION enables the user to choose a component type from a specified CHOICE type. The less than symbol ``<" must precede the name of the CHOICE type.

Winner ::= SEQUENCE {

lastName VisibleString,

ssn VisibleString,

cash < Prize }

with value notation

{ lastName `AUSTING', ssn `222334444', cash 5000 }

Structured TypesType ANY, without further specification, is incomplete. It must be supplemented by any valid ASN.1 type . The value notation for the type notation ANY is the specified type followed by its value.

Structured Types{ author "Shakespeare", reference IA5String "ISBN0669123757" }

and

{ author "Shakespeare", reference INTEGER 1988 }

are two possible values of

TextBook ::= SEQUENCE {

author IA5String,

reference ANY }

Structured TypesType TAGGED is used to enable the receiving system to correctly decode values from several datatypes that a protocol determines may be transmitted at any given time. TAGGED has no value notation of its own. Its type notation consists of three elements: a user-defined tag, possibly followed by IMPLICIT or EXPLICIT, followed by the value notation of the type being tagged.

Structured Types

• The user-defined tag consists of a class and class number contained in braces.

• Class is UNIVERSAL, APPLICATION, PRIVATE, or CONTEXT-SPECIFIC.

• The UNIVERSAL class is restricted to the ASN.1 built-in types. It defines an application-independent data type that must be distinguishable from all other data types. The other three classes are user defined.

Structured Types• The user-defined tag consists of a class and

class number contained in braces.

• Class is UNIVERSAL, APPLICATION, PRIVATE, or CONTEXT-SPECIFIC.

• The UNIVERSAL class is restricted to the ASN.1 built-in types. It defines an application-independent data type that must be distinguishable from all other data types. The other three classes are user defined.

Structured TypesThe APPLICATION class distinguishes data types that have a wide, scattered use within a particular presentation context.

PRIVATE distinguishes data types within a particular organization or country.

CONTEXT-SPECIFIC distinguishes members of a sequence or set, the alternatives of a CHOICE, or universally tagged set members. Only the class number appears in braces for this data type; the term COONTEXT-SPECIFIC does not appear.

Structured Typesa) seats SET { maximum INTEGER, occupied

INTEGER, vacant INTEGER }

b) b) seats SET { maximum [APPLICATION 0] INTEGER, occupied [APPLICATION 1] INTEGER, vacant [APPLICATION 2] INTEGER }

c) c) seats SET { maximum [APPLICATION 0] IMPLICIT INTEGER, occupied [APPLICATION 1] IMPLICIT INTEGER, vacant [APPLICATION 2] IMPLICIT INTEGER }

d) d) seats SET { maximum [0] INTEGER, occupied [1] INTEGER, vacant [2] INTEGER }

Additional Featuresa) ASN.1 defines a subtype notation and value

sets, a method for handling recursion in data types, and a macro facility.

Value Sets• SingleValue:

Divisors-of-6 ::= INTEGER (1 | 2 | 3 | 6) • ContainedSubtype:

Divisors-of-18 ::= INTEGER (INCLUDES Divisors-of-6 | 9 | 18)

• ValueRange: TeenAgeYears ::= (13 .. 19)

• Permitted Alphabet: BooleanValue ::= IA5String (FROM ('T' | 'F'))

• SizeConstraint: BaseballTeamRoster ::= SET SIZE (1..25) OF

PlayerNames

Inner Type• InnerType constrains the value ranges of

structured types.

• In particular, it can change an OPTIONAL component of a structured type into one that is always PRESENT or always ABSENT.

• The type notation requires the keywords ``WITH COMPONENTS'' followed by the components of the structured type, each component with or without a constraint.

Inner TypeNonStopFlights ::= AirlineFlight (

WITH COMPONENTS {airline ("American" | "Delta"),

flight, nonstopseats ::= seats( WITH COMPONENTS

{ maximum (0..200), occupied (100..200), vacant (0..100) } ), nonstopairport ::= airport( WITH COMPONENTS { origin, stop1 [0]

ABSENT, stop2 [1] ABSENT, destination ("LAX") } ),crewsize,

cancel })

Structured TypesAirlineFlight ::= SEQUENCE {

airline IA5String, flight NumericString, seats SEQUENCE {

maximum INTEGER,occupied INTEGER, vacant INTEGER },

airport SEQUENCE {origin IA5String, stop1 [0] IA5String OPTIONAL,stop2 [1] IA5String OPTIONAL,

destination IA5String }, crewsize ENUMERATED { six (6), eight (8), ten (10) },

cancel BOOLEAN DEFAULT FALSE }.