关闭

ASN1 研究1

标签: stringtypesintegerobjectnullnumbers
2891人阅读 评论(0) 收藏 举报
分类:

一、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对象组成

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:126538次
    • 积分:1781
    • 等级:
    • 排名:千里之外
    • 原创:42篇
    • 转载:28篇
    • 译文:7篇
    • 评论:14条
    最新评论