当前位置:网站首页>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 NameRANGE 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 !
边栏推荐
- [principle] several ways of horizontal penetration
- The output comparison function of Tim is introduced in detail through PWM breathing lamp and PWM controlled DC motor
- Nacos registry
- 数据挖掘——关联分析例题代码实现(下)
- Getting started with caspin
- RHCE的at,crontab的基本操作,chrony服务和对称加密和非对称加密
- sql
- Why does the 20 bit address bus determine the storage space of 1MB
- 【C语言入门】ZZULIOJ 1031-1035
- Typescript from getting started to mastering (XXII) namespace namespace (I)
猜你喜欢

Meeting notice of OA project (Query & whether to attend the meeting & feedback details)

Raft protocol - process demonstration

UCOS任务切换过程

VScode连接ssh遇到的问题

EMD empirical mode decomposition

nacos注册中心

【深度学习CPU(番外篇)——虚拟内存】

华为天才少年稚晖君做了一把模块化机械键盘,引起极客圈地震,网友:这才是真正的客制化...

Ribbon principle analysis namedcontextfactory

EMD 经验模态分解
随机推荐
First ALV program 2
Getting started with caspin
数据挖掘——关联分析基础介绍(上)
代码 ~ 隐藏或禁用状态栏和虚拟按键
Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
Typescript from introduction to proficiency (XXIV) using import syntax
3. Solve pychart's error unresolved reference 'selenium' unresolved reference 'webdriver‘
Since 2019, you must have stopped using this marketing strategy
Data too long for column 'xxx' at row 1 solution
Microcomputer principle and interface technology
企业网的三层架构
Alibaba Font Icon Library Usage and update methods
座机的表单验证
Basic configuration of BGP - establish peers and route announcements
Lucifer 98 life record ing
Solve the problem of garbled code when opening the project code in idea
[原理] 横向渗透的几种方式
Cannot paste multiple pictures at once
【redis系列】字符串数据结构
面试必备!TCP协议经典十五连问!