Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4972329
  • 博文数量: 1696
  • 博客积分: 10870
  • 博客等级: 上将
  • 技术积分: 18357
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-30 15:16
文章分类
文章存档

2017年(1)

2016年(1)

2015年(1)

2013年(1)

2012年(43)

2011年(17)

2010年(828)

2009年(568)

2008年(185)

2007年(51)

分类: 系统运维

2009-04-21 23:54:03

Abstract Syntax Notation One
From Wikipedia, the free encyclopedia
In telecommunications and computer networking, Abstract Syntax Notation One (ASN.1) is a standard and flexible notation that describes data structures for representing, encoding, transmitting, and decoding data. It provides a set of formal rules for describing the structure of objects that are independent of machine-specific encoding techniques and is a precise, formal notation that removes ambiguities.

ASN.1 is a joint ISO/IEC and ITU-T standard, originally defined in 1984 as part of CCITT X.409:1984. ASN.1 moved to its own standard, X.208, in 1988 due to wide applicability. The substantially revised 1995 version is covered by the X.680 series. The latest available version is dated 2002, and is backward compatible with the 1995 version.

 


Contents
[hide]
1 Example
1.1 Example encoded in DER
1.2 Example encoded in XER
1.3 Example encoded in PER (unaligned)
2 ASN.1 versus other data structure definition schemes
3 Encoding Control Notation (ECN)
4 ASN.1 Information Object Class
5 Using ASN.1 in practice
6 Standards
7 See also
8 Notes
9 References
10 External links
 


[edit] Example
Data structures of FooProtocol defined using the ASN.1 notation:

FooProtocol DEFINITIONS ::= BEGIN

    FooQuestion ::= SEQUENCE {
        trackingNumber INTEGER,
        question       IA5String
    }

    FooAnswer ::= SEQUENCE {
        questionNumber INTEGER,
        answer         BOOLEAN
    }

END

This could be a specification published by creators of Foo protocol. ASN.1 does not define conversation flows. This is up to the textual description of the protocol.

Assuming a message, which complies with Foo protocol and which will be sent to the receiving party. This particular message (PDU) is:

myQuestion FooQuestion ::= {
    trackingNumber     5,
    question           "Anybody there?"
}

To send the above message through the network one needs to encode it to a string of bits. ASN.1 defines various algorithms to accomplish that task, called Encoding rules. There are plenty of them; one of the simplest is Distinguished Encoding Rules (DER).

The Foo protocol specification should explicitly name one set of encoding rules to use, so that users of the Foo protocol know they should use DER.


[edit] Example encoded in DER
Below is the data structure shown above encoded in the DER format (all numbers are in hexadecimal):

30 -- tag indicating SEQUENCE
13 -- length in octets

02 -- tag indicating INTEGER
01 -- length in octets
05 -- value

16 -- tag indicating IA5String
0e -- length in octets
41 6e 79 62 6f 64 79 20 74 68 65 72 65 3f -- value ("Anybody there?" in ASCII)

(Note DER uses a pattern of tag-length-value triplets)

So what one actually gets is the string of 21 octets:

30 13 02 01 05 16 0e 41  6e 79 62 6f 64 79 20 74  68 65 72 65 3f

The scope of ASN.1 and DER ends here. It is possible to transmit the encoded message to the party by any means (utilizing TCP or any other protocol). The party should be able to decode the octets back using DER.


[edit] Example encoded in XER
Alternatively, it is possible to encode the same ASN.1 data structure with XER (XML Encoding Rules) to achieve greater human readability "over the wire". It would then appear like the following 108 octets:


    5
    Anybody there?


[edit] Example encoded in PER (unaligned)
Alternatively, if Packed Encoding Rules are employed, the following 122 bits (less than 16 octets) will be produced:

01 05 0e 83 bb ce 2d f9  3c a0 e9 a3 2f 2c af c0


[edit] ASN.1 versus other data structure definition schemes
As commonly used for defining messages for communication protocols, ASN.1, with its associated encoding rules, results in a binary encoding.

Other communication protocols, such as Internet protocols HTTP and SMTP, define messages using text tags and values, sometimes based on the Augmented Backus-Naur form (ABNF) notation. The definition also defines the encoding, which is in text.

There has been much debate over the two approaches, and both have their merits; the ASN.1 approach is believed to be more efficient, and with Packed Encoding Rules, certainly provides a more compact encoding. The textual approach is claimed to be easier to implement (through creation and parsing of text strings) and easier to debug, as one can simply read an encoded message. In the case of the Megaco protocol, consensus between the two points of view was not reached and so two encodings, one based on ASN.1 and one on ABNF, were defined.

The ASN.1 XML Encoding Rules (XER) attempts to bridge the gap by providing a textual encoding of data structures defined using ASN.1 notation. Generic String Encoding Rules were also defined for the sole purpose of presenting and inputting data to/from a user.


[edit] Encoding Control Notation (ECN)
The Encoding Control Notation (ECN) is a notation to specify specific encodings of ASN.1 types. ECN is useful to describe legacy protocols in ASN.1. It is possible to specify only the encoding of some types and then complete with a standard encoding rules (usually unaligned PER).


[edit] ASN.1 Information Object Class
Main article: Information Object Class (ASN.1)
Information Object Classes is a concept used in ASN.1 to address specification needs similar to the ones addressed by CORBA/IDL specifications.


[edit] Using ASN.1 in practice
One may use an ASN compiler which takes as input an ASN.1 specification and generates computer code (for example in the C programming language) for an equivalent representation of the data structures. This computer code, together with supplied run-time libraries, can then convert encoded data structures to and from the computer language representation. Alternatively, one can manually write encoding and decoding routines.


[edit] Standards
Standards describing the ASN.1 notation:

ITU-T Rec. X.680 | ISO/IEC 8824-1
ITU-T Rec. X.681 | ISO/IEC 8824-2
ITU-T Rec. X.682 | ISO/IEC 8824-3
ITU-T Rec. X.683 | ISO/IEC 8824-4
Standards describing the ASN.1 encoding rules:

ITU-T Rec. X.690 | ISO/IEC 8825-1 (BER, CER and DER)
ITU-T Rec. X.691 | ISO/IEC 8825-2 (PER)
ITU-T Rec. X.693 | ISO/IEC 8825-4 (XER)
ITU-T Rec. X.694 | ISO/IEC 8825-5 (XSD mapping)
RFC 3641 (GSER)

[edit] See also
TTCN
TTCN-3
EBML

[edit] Notes

[edit] References
A free book about ASN.1 from Olivier Dubuisson
A free book about ASN.1 from John Larmouth
This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.


[edit] External links
ASN.1C, free, open source ASN.1 to C compiler
openASN.1 An Open Source ASN.1 toolkit for Java
asn1forj An Open Source ASN.1 toolkit for Java
BinaryNotes: The Open Source ASN.1 Framework for Java and .NET
pyasn1: ASN.1 types and codecs implemented in Python
Standards describing the ASN.1 notation
Standards describing the ASN.1 encoding rules
The ASN.1 Consortium
The Object Identifier (OID) repository
ASN.1 Compiler
OSS ASN.1 Tools page
ASN.1 Tutorial Tutorial on basic ASN.1 concepts
A Layman's Guide to a Subset of ASN.1, BER, and DER A very good introduction for beginners
Asn2wrs, an ASN.1 to Wireshark dissector compiler
ASN.1 DER encoding and decoding example in C
K2C software ASN.1 Comercial Software
Retrieved from ""

阅读(2462) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~