当前位置:网站首页>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 !
边栏推荐
- Cannot paste multiple pictures at once
- MySQL Part 4 (end)
- Raft protocol - process demonstration
- 路西法98-生活记录ing
- SSL==证书相关概念
- 【C语言入门】ZZULIOJ 1031-1035
- Getting started with caspin
- The function parameters of the new features of ES6 are assigned initial values and rest parameters
- 5年多工作经验,工资给15k,要是你,你会接受吗?
- Nacos registry
猜你喜欢

Alibaba Font Icon Library Usage and update methods

Note: restframe work records many to one tables, how to serialize in that table (reverse query)

大厂们终于无法忍受“加一秒”了,微软谷歌Meta等公司提议废除闰秒

C语言实现三子棋游戏(详解)

Cloudera manager platform fault repair record

Uni app internationalization

Typescript from getting started to mastering (XX) function generics

1985-2020(8个版次)全球地表覆盖下载与介绍

Ribbon principle analysis namedcontextfactory

Press the missing number of interview question 17.04 | | 260. the number that appears only once (including bit operation knowledge points)
随机推荐
Nacos registry
SQL窗口函数
Deep understanding of browser caching mechanism (HTTP)
Configmap配置与Secret加密
Configmap configuration and secret encryption
3.解决Pycharm报错Unresolved reference ‘selenium‘ Unresolved reference ‘webdriver‘
Routing knowledge
Ssl== certificate related concepts
通过PWM呼吸灯和PWM控制直流电机来详细介绍TIM的输出比较功能
Data mining -- code implementation of association analysis example (Part 2)
HCIP BGP
Cloudera manager platform fault repair record
tron OUT_ OF_ ENERGY
C language to achieve three chess game (detailed explanation)
UCOS task switching process
Shopify seller: EDM marketing should be combined with salesmartly to easily get the conversion rate
[untitled]
With more than 5 years of work experience and a salary of 15K, would you accept it if you were me?
当我从数据库获取到了winfrom特定的控件ID之后我需要通过这个ID找到对应的控件,并对控件的TEXT文本进行赋值这该怎么做
Li Kou daily question - day 44 -205. Isomorphic string