ASN1 研究1

原创 2012年04月08日 16:14:03

一、ASN1的类型

         分为:简单类型(simple types),字符类型(String types),structured types(结构类型).

      字符类型又分为两类:一类是处理原始二进制字节,另一类是代表特定字符的编码

    结构类型由SEQUENCE和SET组成。

 

    简单类型:BOOLEAN、ENUMERATEDINTEGER、NULL、OBJECT IDENTIFIER、UTCTime、GeneralizedTime

                      boolean用来编码true或者false

                     null代表的是空值,而不是空,不存在

                     UTCTIme只有两位数的年份,GeneralizedTime是四位数的年份。它们都把时间转换成ASCII编码字符,GeneralizedTime可以精确的秒,

      Bit String Type(位字符串类型):         BIT STRING、OCTET STRING

                   BIT STRING:可以存储任意长度的任意字节,一个bit String由两部分组成,一部分是包含实际字符和0到7个补位的字符,以保证该部分字符长度是8的倍数。另一部  分 是记录补位的个数。一个bit String 的长度可以为0.

           OCTET STRING:可以存储8位字节的字符,与java byte数组匹配

     

 

 

BOOLEAN encodes a true or false value.

ENUMERATED is a special case of INTEGER that can be used to represent signed integers of any magnitude. Note that I saidsignedINTEGER values are encoded as two's-complement numbers, high byte first in "big endian" format.

You can think of NULL in a similar way to the Java null, although there is a slight twist, as it is ASN.1's way of distinguishing a value set to nothing, rather than absent, which you will see later is also a possibility.

You have already learned what object identifiers are in the section on basic ASN.1 syntax. Not surprisingly,OBJECT IDENTIFIER is the type they are given.

UTCTime and GeneralizedTime are two that deserve some special attention; both are used to define a "Coordinated Universal Time," butUTCTime has only a two-digit year.GeneralizedTime has a four-digit year. Both objects represent time as strings of ASCII, with major differences being thatGeneralizedTime has a four-digit year and can represent seconds to an arbitrary precision, whereasUTCTime has a two-digit year and cannot go any lower than seconds in its resolution. Although it should be obvious how aGeneralizedTime is used, a question remains: How do you deal with the two-digit year inUTCTime?

One interpretation of UTCTime is that the two-digit year is interpreted as spanning the century starting from 1950 to 2049, but others are also used. AUTCTime can also be interpreted as going from 1900 to 1999, or as being on a sliding window, as in if it's 2005, the digits 55 to 99 are interpreted as indicating 1955 to 1999, and 0 to 55 is interpreted as meaning 2000 to 2055. How you work this one out depends on the standard you are working with, but you will be relieved to know that for the most part people have settled on the meaning that maps 50 to 99 as 1950 to 1999, and 00 to 49 as 2000 to 2049.

 

                  

二、类型标签

       在ASN.1中,一个类型就是一个值的集合。有些类型有有限个值,有些类型有无限个值。一个给定的的ASN。1类型的值是该类型集合里的一个元素。

      除了CHOICE和ANY类型外,每种ASN1类型都有一个标签,由一个类和一个非负的标签树组成。标签的值可以唯一区分ASN1类型。也就是说ASN1类型的名字并 

     不影响它的抽象含义,只有标签的值才有这个作用。

 

The most important of these modifiers for you is bit 6, which if set means the type is a constructed type

最重要的是第六位的编码,如果设置为1,那么表示为结构化类型,意味着后面的字节流由其它ans1对象组成,以便组装成对象解析。

Therefore, although the tag value for SEQUENCE is 0×10 and SET is 0×11, the encoded values you will encounter will be 0×30 to indicate aSEQUENCE follows and 0×31 to indicate a SET, because both these types are composed of one or more other ASN.1 objects.

因此,虽然SEQUENCE是0x10,SET是0x11,编码值将会是0x30或者0x31,因为这两种类型都由其他asn1对象组成

ASN.1中OID类型的DER编码

asn1对OID的编码有一些规定,形如a.b.c.d.e的OID被编码的时候,完全可以按照der的编码规则将整个oid的类型设定为object,然后将每一个点分数字的类型设定为integer,最终编码...
  • CaesarZou
  • CaesarZou
  • 2014年06月09日 15:24
  • 2393

利用开源ASN1C库实现asn.1的编解码

最近在研究MMS的时候接触到了抽象语义记法ASN.1(Abstract Syntax Notation One),于是对它做了一番了解,下面将这几天的学习到的做下记录,以供以后偷懒。   ASN.1...
  • u013387076
  • u013387076
  • 2014年01月05日 17:18
  • 2393

ASN.1笔记——语法规则与类型概述

一.简介 ASN.1(Abstract Syntax Notation dotone)抽象语法标记定义抽象数据类型形式的标准,是用于描述数据表示、传输和编码的记法。 ASN.1只包含信息结构,不处...
  • andryyu
  • andryyu
  • 2016年09月01日 11:41
  • 2585

ASN.1及 其PER编码在视频会议系统中的应用研究

  • 2010年11月09日 13:57
  • 310KB
  • 下载

ASN_1在RRC消息中的应用研究.pdf

  • 2012年11月26日 16:18
  • 253KB
  • 下载

ASN.1 berview 查看

  • 2015年02月01日 14:27
  • 134KB
  • 下载

asn1-6141-mibs.zip

  • 2013年04月23日 11:47
  • 225KB
  • 下载

ASN1_Complete

  • 2012年11月06日 22:04
  • 1.02MB
  • 下载

ASN.1解码模块设计方案

  • 2013年11月01日 21:00
  • 50KB
  • 下载

ASN1C guide.docx

  • 2013年08月25日 18:29
  • 236KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ASN1 研究1
举报原因:
原因补充:

(最多只允许输入30个字)