当前位置:网站首页>There is a special cryptology language called asn.1
There is a special cryptology language called asn.1
2022-07-29 04:01:00 【flydean】
brief introduction ASN.1 Is an interface description language for cross platform data serialization . Maybe a lot of people haven't heard of ASN.1, But I believe that students who have had cross platform programming experience may have heard protocol buffers and Apache Thrift, although ASN.1 Compared with the above two languages, it is not so famous , however ASN.1 They appeared much earlier than them , As early as 1984 year ASN.1 And that's what happened .
Compare with them ASN.1 There is no single open source implementation , But as a specification for third-party suppliers to implement .ASN.1 It is mainly used to define various basic protocols , For example, common LDAP,PKCS,GSM,X.500 etc. .
ASN.1 Is a and platform 、 Language independent description language , You can use many ASN.1 It's a good translation tool , take ASN.1 Translate into C, C++, Java Etc .
ASN.1 Example since ASN.1 Is a description language , So let's start with an intuitive example .ASN.1 The foundation is module, Let's see ASN.1 in module Example :
StudentCards DEFINITIONS AUTOMATIC TAGS ::= BEGIN
StudentCard ::= SEQUENCE { dateOfBirthday DATE, student StudentInfo }
StudentInfo ::= SEQUENCE { studentName VisibleString (SIZE (3..50)), homeAddress Address, contactPhone NumericString (SIZE (7..12)) }
Address::= SEQUENCE { street VisibleString (SIZE (5 .. 50)) OPTIONAL, city VisibleString (SIZE (2..30)), state VisibleString (SIZE(2) ^ FROM ("A".."Z")), zipCode NumericString (SIZE(5 | 9)) }
END In the example above , We use ASN.1 Defined a StudentCard, Outermost with BEGIN and END Surrounded by module.StudentCards yes module Name , Initial must be capitalized .
among ::= Is an assignment symbol .
module There can be more than one type, type Your name must also be capitalized , For example, above StudentCard,StudentInfo wait .
Every type Its components are defined in , The first letter of the component name must be lowercase , These components are also called identifiers.
above dateOfBirthday It's followed by DATE yes ASN.1 Built in type . and student hinder StudentInfo It's a custom type , And also included in module in .
StudentInfo Medium studentName It's a VisibleString, This String The restrictions are size stay 3 To 50 Between .
Above we define module At the time of module Add... To the back AUTOMATIC TAGS , What does that mean ?
stay ASN.1 in ,tags yes ASN.1 The internal identifier of each component in the message , With Address For example , We want to give Address Each attribute in specifies an internal identifier , As shown below :
Address::= SEQUENCE { street [0] VisibleString (SIZE (5 .. 50)) OPTIONAL, city [1] VisibleString (SIZE (2..30)), state [2] VisibleString (SIZE(2) ^ FROM ("A".."Z")), zipCode [3] NumericString (SIZE(5 | 9)) } Inside [0] [1] It's an identifier , Of course , We can define module You can specify these manually when tags, But if we use AUTOMATIC TAGS , These identifiers are automatically created , This avoids the problem of manually creating identifiers .
ASN.1 Built in types in Through the above explanation , We are right. ASN.1 With a basic concept . If you want to be right ASN.1 Do more in-depth research , So the first thing we need to know is ASN.1 Built in types in .
Generally speaking ASN.1 There are the following data types in :
BOOLEAN BOOLEAN It is consistent with Boolean values in programming languages , It has two possible values :TRUE and FALSE. The following is the specific usage :
removed BOOLEAN ::= TRUE INTEGER INTEGER Represents an integer , As shown below , It means that the annual range is 0 To 100, The final value is 18:
age INTEGER (0..100) ::= 18 BIT STRING Bit representation of bytes , You can give one byte Each of them bit Set the value :
Status ::= BIT STRING { married(0), handsome(1), kind(2) } myStatus Status ::= {handsome, kind} In the example above , We set it up Status, And use Status Assigned to a variable myStatus.
OCTET STRING 8 The string represented by the decimal :
octetExample ::= OCTET STRING DATE Indicates the date , The format is ”YYYY-MM-DD”:
birthday DATE ::= "1990-11-18" TIME-OF-DAY Represents the time in the date , The format is ”HH:MM:SS”:
startTime TIME-OF-DAY ::= "09:30:00" DATE-TIME Time plus date format , Its format ”YYYY-MM-DDTHH:MM:SS”, As shown below :
endTime DATE-TIME ::= "2022-01-10T18:30:23" REAL REAL Represents a floating point number , It can be expressed as follows :
Amount ::= REAL ENUMERATED ENUMERATED Represents an enumeration , It can be expressed as follows :
Colors ::= ENUMERATED {black, red, white} myColor Colors ::= white SEQUENCE SEQUENCE Represents a sequence set of items , As shown below :
StudentInfo ::= SEQUENCE { name VisibleString, phone NumericString } max StudentInfo ::= {name "J.Max", phone "18888888888"} SEQUENCE OF SEQUENCE OF It means a list:
breakTimes SEQUENCE OF TIME-OF-DAY ::= {"10:00:00", "12:00:00", "14:45:00"} CHOICE CHOICE From many item Choose one of them :
Identity ::= CHOICE { name VisibleString, phone VisibleString, idCard VisibleString } jack Identity ::= name: "jack" IA5String IA5String It means ASCII character , And contains control characters .
SampleString ::= IA5String VisibleString VisibleString It means ASCII character , It does not contain control characters .
SampleString ::= VisibleString NumericString NumericString It means numbers and spaces .
SomeNumber ::= NumericString UTF8String UTF8String It means Unicode character
UnicodeString ::= UTF8String NULL It's a null value , Used for occupying .
ASN.1 Restriction syntax in ASN.1 Many fields can be defined in , Some fields may have some limitations , For example, mobile phone numbers can only be numbers , Name has length limit, etc .
These restrictions are limited to ASN.1 called Constraints, Generally speaking, there are some limitations as follows :
FROM FROM Provides a read range of data values , as follows :
PermittedChars ::= IA5String (FROM("ABCDEFG1244")) PermittedChars Only from ”ABCDEFG1244″ choice .
PATTERN PATTERN Represents a regular expression , As shown below :
phoneNumber ::= IA5String (PATTERN "1[0-9]#10") Listed above is a simple regular expression for mobile phone numbers .
SIZE SIZE It can represent the length of a string or the length of an array :
Name ::= IA5String (SIZE (4..7)) NameList ::= SEQUENCE SIZE (1..25) OF Name
RANGE Use .. Can represent a range :
Age ::= INTEGER (0..100) Single value Select one from the list of values provided :
Colors ::= UTF8String ("Blue" | "White") summary That's all ASN.1 The basic introduction of data structure description language , With these foundations , We can easily read and use ASN.1 To describe the data structure of .
Please refer to http://www.flydean.com/46-asn-1/
The most popular interpretation , The deepest dry goods , The most concise tutorial , There are so many tricks you don't know about waiting for you to discover !
Welcome to my official account. :「 Program those things 」, Know technology , Know you better !
边栏推荐
- How do programmers use code to completely end those things in the system?
- Beijing post network research 2015 problem2
- "Strangers once met" Summer Street Shen Shuyan_ Xia Mo Shen Shuyan's latest chapter
- 1985-2020(8个版次)全球地表覆盖下载与介绍
- 力扣面试题17.04 消失的数字||260.只出现一次的数字(内含位运算知识点)
- Form verification of landline
- 安装ros的laser_scan_matche库所遇到的问题(一)
- 代码 ~ 隐藏或禁用状态栏和虚拟按键
- Wechat applet monitors sliding events on the screen
- nacos注册中心
猜你喜欢
HCIP BGP
Why BGP server is used in sunflower remote control? Automatic optimal route and high-speed transmission across operators
【BGP】小型实验
Why does the 20 bit address bus determine the storage space of 1MB
UCOS task switching process
What have I learned from 200 machine learning tools?
EMD empirical mode decomposition
Sunflower senior product director technology sharing: "how to apply national remote control" in AD domain environment
Cloudera manager platform fault repair record
Typescript from getting started to mastering (XX) function generics
随机推荐
lodash库常用方法
3. Solve pychart's error unresolved reference 'selenium' unresolved reference 'webdriver‘
Getting started with caspin
Casbin入门
Const read only variable constant
Typescript from getting started to mastering (XXII) namespace namespace (I)
MySQL第三篇
Batch production and upload sales NFT opensea eth polygon
路由 知识
Data too long for column 'xxx' at row 1 solution
[原理] 横向渗透的几种方式
MySQL Part 3
Zhihuijun, a genius of Huawei, made a modular mechanical keyboard, which caused an earthquake in the geek circle. Netizens: This is the real customization
Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
C language to achieve three chess game (detailed explanation)
Lucifer 98 life record ing
Who can elaborate on the semi consistent read under mysqlrc and how to reduce the deadlock probability?
Deconstruction assignment of new features of ES6
Typescript from getting started to mastering (XX) function generics
Shutter start white screen