TLV(tag length value)編碼

來源:互聯網
上載者:User
2007-08-18 21:18
標籤(Tag)欄位是關於標籤和編碼格式的資訊;
長度 (Length)欄位定義數值的長度;
內容(Value)欄位表示實際的數值。
因此,一個編碼值又稱TLV(Tag,Length,Value)三元組。編碼可以是基本型或結構型,如果它表示一個簡單類型的、完整的顯式值,那麼編碼就是基本型 (primitive);如果它表示的值具有嵌套結構,那麼編碼就是結構型 (constructed)。

TLV編碼就是指先對Tag編碼,再對Length編碼,最後對Value編碼。BER編碼的長度確定的編碼方式就是這樣的。
BER編碼有兩種方式:
一種是長度確定的編碼方式。這由3部分組成Identifier octets、Length octets和Contents octets(可以和TLV對應)。另一種是長度不確定的編碼方式。這由4部分組成Identifier octets、Length octets、Contents octets、End-of-contents octets。其中Length octets為0x80,End-of-contents octets為0x00 00。每種類型都能夠編碼成長度確定的編碼方式,但是有的類型不能夠編碼成長度不確定的編碼方式。DER編碼只能使用長度確定的編碼方式。
Identifier octets由3部分組成Class、P/C和Tag number。Identifier octets的第一個位元組的高2位為Class,接下來一位為P/C,其他位表示Tag number。Class有4中類型Universal(00)、Application(01)、Context-specific(10)和Private(11)。P/C位如果為1則表示是Constructed的,為0表示是Primitive。如果0<=Tag number<=30,則整個Identifier octets只有一個位元組,否則第一個位元組的後5位前為1,接下來找第一個最高位為0的位元組,該位元組就是Identifier octets的最後一個位元組。從第二個位元組到最後一個位元組去掉最高位的值拼起來就是Tag number的值。
長度確定的編碼方式的Length octets有兩種方法編碼長度,一種是只用一個位元組表示長度,其最高位為0,後7位表示長度值,顯然這樣只能表示0-127。另一種是第一個位元組的最高位為1,其他位表示後面還有多少個位元組屬於Length octets。後面的那些位元組組成的就是長度值。長度值表示的是Contents octets所佔的位元組數。DER要求如果長度為0-127則要使用第一種方式,如果大於127則使用後一種方式。
The tag field (T) consists of one or more consecutive bytes. It indicates a class,
a type, and a number. The tag field of the data objects
described in this specification is coded on one or two bytes.

* The length field (L) consists of one or more consecutive bytes. It indicates the
length of the following field. The length field of the data objects described in
this specification is coded on one or two bytes.

* The value field (V) indicates the value of the data object. If L = '00', the value
field is not present.

A BER-TLV data object belongs to one of the following two categories:

* A primitive data object where the value field contains a data element for
financial transaction interchange.

* A constructed data object where the value field contains one or more primitive
or constructed data objects. The value field of a constructed data object is
called a template.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.