Method for judging ASN.1 structural body difference and computer readable storage medium
By analyzing and comparing different versions of ASN.1 data structures, generating and correcting member differences analysis results, the problem of difficult to intuitively compare the differences in ASN.1 structure versions is solved, and development efficiency and system compatibility are improved.
Patent Information
- Application Number
- CN202411519767.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-02-18
AI Technical Summary
It is difficult for the prior art to intuitively compare the differences in different versions of ASN.1 structures, which makes it difficult to guarantee system compatibility and correctness.
By obtaining the ASN.1 data structures of different iterative versions, analyzing and generating the corresponding programming language classes, performing analogies to determine the code structure differences, generating the initial member difference analysis results, and correcting the difference results through serialization and comparison, and finally determining the Difference points in ASN.1 data structure.
This realizes an intuitive comparison of the differences in ASN.1 structure versions, significantly improves development efficiency and maintainability of code, and ensures compatibility and correctness during system upgrades.
Smart Images

Figure CN119473385A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network security technology, and in particular to a method for distinguishing ASN.1 structure differences and a computer-readable storage medium. Background Art
[0002] In the fields of computer, telecommunication and network security, ASN.1 is a data structure definition language that is often used to serialize complex data structures and transfer data between different systems. ASN.1 can be used to describe complex data types and can represent and exchange data independently of any specific computer hardware, operating system or programming language.
[0003] In actual applications, the communicating parties usually use ASN.1 to define some specific structures according to the application requirements. These structures are used to describe the format and content of the data to be exchanged between the two parties. The data structure defined by ASN.1 can represent various complex data types, such as simple integers, strings, Boolean values, or more complex nested structures, such as sequences, sets, options, etc. These ASN.1 structure definitions are part of the protocol and are usually iterated and updated with changes in requirements and technological developments, such as adding new fields and modifying constraints on existing fields.
[0004] For developers in these fields, understanding changes in interfaces is an important step to ensure system compatibility and correctness when performing version iterations, and analyzing version updates from the perspective of changes in ASN.1 structures is a very effective approach. Developers can quickly identify specific changes in data structures by comparing the old and new versions of the ASN.1 structure, identify potential incompatibilities in advance, and adjust code and configuration in a timely manner, thereby reducing the risk of system upgrades.
[0005] When comparing and analyzing different versions of ASN.1 structure definitions, it may not be intuitive to start directly from the original ASN.1 expression, especially during the development process. This is because the description method of ASN.1 tends to be a standardized definition of data structure, which is not convenient for direct comparison and operation at the code level. Summary of the invention
[0006] The main technical problem solved by the present invention is to provide a method for distinguishing ASN.1 structure differences which can intuitively compare different versions of ASN.1.
[0007] According to the first aspect, an embodiment provides a method for determining ASN.1 structure version differences, including:
[0008] Get the data structure of different iteration versions of ASN.1;
[0009] Parse the data structure of each version of ASN.1 to generate corresponding classes of the set programming language;
[0010] Compare the various categories to determine the differences in code structure within each category to generate initial member difference analysis results;
[0011] Obtaining classes with different code structures under different iteration versions, and creating instances of the classes with different code structures;
[0012] Assign values to each instance, and serialize the assigned instances to generate binary data accordingly;
[0013] Compare the sites of each binary data one by one, modify the initial member difference analysis result according to the site comparison result of each binary data, and generate a final member difference analysis result;
[0014] The difference points of the data structures of different iterative versions of ASN.1 are determined according to the final member difference analysis result to provide modification prompts for program development.
[0015] In one embodiment, the parsing of the data structures of each version of ASN.1 to generate a class of a set programming language includes:
[0016] Use jasn1 to parse the data structures of various versions of ASN.1 to generate corresponding Java classes.
[0017] In one embodiment, comparing the various categories to determine the code structure differences in the various categories to generate initial member difference analysis results includes:
[0018] Use the reflection feature of Java to compare the various categories to determine the differences in the code structure of each category.
[0019] In one embodiment, the code structure differences include at least one of package differences indicating changes in the package path where the class is located, class member variable differences indicating changes in attributes in the class, class member function differences indicating changes in functions in the class, and internal class differences indicating changes in internal classes defined in the class.
[0020] In one embodiment, the package difference includes at least one of a package path difference indicating a change in the directory to which the class belongs, a class increase / decrease difference within the package indicating a change in the number of classes, and a class name difference indicating a change in the name of the class.
[0021] In one embodiment, the class member variable differences include at least one of member variable increase or decrease differences indicating a change in the number of member variables in the class, member variable name differences indicating a change in the names of the member variables in the class, access modifier differences indicating a change in the member variable access rights of the member variables in the class, and member variable type differences indicating a change in the data type of the member variables in the class.
[0022] In one embodiment, the class member function differences include at least one of the following: function increase and decrease differences in which new methods are added or old methods are deleted in the class, function name differences in which the names of functions in the class are changed, function input parameter differences in which the types and quantities of parameters in the class are changed, function return value differences in which the return value types of functions in the class are changed, and function access modifier differences in which the access rights of functions in the class are changed.
[0023] In one embodiment, the inner class differences include at least one of the following: inner class increase / decrease differences in which new inner classes are added or old inner classes are deleted in the class, inner class name differences in which the names of inner classes in the class are changed, inner class access modifier differences in which the access rights of inner classes in the class are changed, inner class member variable differences in which the number of inner class member variables in the class or the names of inner class member variables are changed, and inner class member function differences in which the number of functions in the class in the class is changed or the names of inner class functions are changed.
[0024] In one embodiment, the assigning of values to each instance and serializing the assigned instances to generate corresponding binary data; comparing the sites of each binary data one by one, correcting the initial member difference analysis results according to the site comparison results of each binary data, and generating the final difference analysis results include:
[0025] Each instance is assigned a value according to the code structure difference in each category, and the site comparison result of each binary data is detected to see whether it is consistent with the code structure difference in the initial member difference analysis result. If it is consistent, the code structure difference in the initial member difference analysis result is retained to complete the correction of the initial member difference analysis result.
[0026] According to the second aspect, an embodiment provides a computer-readable storage medium, on which a program is stored, and the program can be executed by a processor to implement the method described in any one of the above embodiments.
[0027] According to a method and computer-readable storage medium for distinguishing ASN.1 structure differences in the above-mentioned embodiment, the data structure of ASN.1 of different iteration versions is obtained in the method, and the data structure is converted into a class of a set programming language. Under the set programming language, the classes of the set programming language corresponding to different iteration versions are compared, so as to determine the code structure differences of each class under different iteration versions, so as to generate the initial member difference analysis results. After determining the class with code structure differences, an instance of the class is created, and a value is assigned in the instance, and the strength of the completed assignment is serialized to generate corresponding binary data, and each site in the binary data is compared one by one. The initial generated difference analysis result is corrected according to the site comparison result of the binary data, so as to generate the final member difference analysis result. The final member difference analysis result is used to prompt the developer when developing the program, thereby significantly improving the development efficiency and the maintainability of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 is a flow chart of a method for determining ASN.1 structure differences in an embodiment;
[0029] Figure 2 A schematic diagram of a method for distinguishing ASN.1 structure differences in an embodiment;
[0030] Figure 3 A schematic diagram of code structure differences in an embodiment;
[0031] Figure 4 A schematic diagram of package differences in an embodiment;
[0032] Figure 5 A schematic diagram of class member variable differences in an embodiment;
[0033] Figure 6 A schematic diagram of the difference in class member functions in one embodiment;
[0034] Figure 7 Schematic diagram of internal class differences in one embodiment. DETAILED DESCRIPTION
[0035] The present invention is further described in detail below by specific embodiments in conjunction with the accompanying drawings. Wherein similar elements in different embodiments adopt associated similar element numbers. In the following embodiments, many detailed descriptions are for making the present application better understood. However, those skilled in the art can easily recognize that some features can be omitted in different situations, or can be replaced by other elements, materials, methods. In some cases, some operations related to the present application are not shown or described in the specification, this is to avoid the core part of the present application being overwhelmed by too much description, and for those skilled in the art, it is not necessary to describe these related operations in detail, and they can fully understand the related operations according to the description in the specification and the general technical knowledge in the art.
[0036] In addition, the features, operations or characteristics described in the specification can be combined in any appropriate manner to form various implementations. At the same time, the steps or actions in the method description can also be interchanged or adjusted in a manner that is obvious to those skilled in the art. Therefore, the various sequences in the specification and the drawings are only for the purpose of clearly describing a certain embodiment and are not meant to be a required sequence, unless otherwise specified that a certain sequence must be followed.
[0037] The serial numbers of the components in this document, such as "first", "second", etc., are only used to distinguish the objects described and do not have any order or technical meaning. The "connection" and "coupling" mentioned in this application, unless otherwise specified, include direct and indirect connections (couplings).
[0038] Please refer to Figure 1 and Figure 2 In one embodiment, a method for determining ASN.1 structure version differences is provided, and the method includes the following steps.
[0039] Step S110: Acquire data structures of ASN.1 of different iteration versions.
[0040] In one embodiment, ASN.1 (Abstract Syntax Notation One) is a standardized language for describing data structures, commonly used in telecommunications and computer network fields. An ASN.1 file contains a set of data structures that define how to represent data and how to serialize and deserialize it when transmitting between different systems.
[0041] Step S120: Parse the data structure of each version of ASN.1 to generate a corresponding class of a set programming language.
[0042] In one embodiment, the data structures of various versions of ASN.1 are parsed to generate corresponding Java source codes, and the classes of these Java source codes retain the structure and type information in the ASN.1 file for subsequent analysis. In programming, class is one of the core concepts of object-oriented programming, representing an abstract data type. Class is used to define a data structure, which encapsulates data (called attributes or fields) and behaviors that operate on these data (called functions).
[0043] In one embodiment, jasn1 is used to parse the data structures of various versions of ASN.1 to generate corresponding Java classes. Using jasn1 (a Java library for processing ASN.1), the data types in the ASN.1 data structures can be converted to basic types in Java. ASN.1 defines a standardized syntax for describing data structures, which is widely used in network protocols and data transmission. jasn1 can parse the data structures described by ASN.1 and generate corresponding Java code, mapping these ASN.1 data types to basic types in Java.
[0044] Step S130: Compare the various categories to determine the code structure differences in the various categories to generate initial member difference analysis results.
[0045] In one embodiment, the reflection feature of Java is used to compare various classes to determine the differences in the code structure in each class. The Java reflection feature is a powerful mechanism in the Java language that allows a program to dynamically access and manipulate information such as classes, methods, and properties at runtime without having to know this information at compile time. Through reflection, a program can obtain metadata about an object and can dynamically create objects, call methods, and access fields. The basic differences between member variables and functions in different versions of source code generated using the Java reflection feature are integrated to generate an initial member difference analysis result.
[0046] Please refer to Figure 3 In one embodiment, the code structure differences of various classes determined by utilizing the reflection characteristics of Java include at least one of package differences, class member variable differences, class member function differences, and internal class differences.
[0047] In one embodiment, the package difference refers to whether the package path where the class is located has changed. The package path is a way to organize classes in Java, similar to the folder structure in the file system. The change of the package path may affect the reference location of the class in the system, especially during serialization and deserialization, the system may not be able to find the class under the specified package.
[0048] Please refer to Figure 4In one embodiment, the package differences include package path differences, intra-package class addition and reduction differences, and class name differences. Package path differences indicate that the directory to which the class belongs has changed. For example, the package path of the first iterative version is com.example.asn1.v1, and the package path of the second iterative version is com.example.asn1.v2. Intra-package class addition and reduction differences refer to changes in the number of classes in a certain package, such as whether new classes are added or old classes are deleted. Class name differences indicate that the name of the class has changed. For example, the PersonV1 class in the first iterative version is renamed to PersonV2 in the second iterative version.
[0049] Please refer to Figure 5 In one embodiment, class member variable differences refer to changes in attributes (fields) in a class. Class member variable differences include at least one of member variable increase / decrease differences, member variable name differences, member variable access modifier differences, member variable type differences, and serialization tag field differences. These differences will directly affect the data structure matching of the object during the serialization process, especially the increase / decrease or type change of member variables will cause the old version to be unable to correctly decode the data of the new version.
[0050] In one embodiment, the difference in member variable addition and reduction refers to the addition of new member variables or the deletion of old member variables. For example, the class Person has name and age in the first iteration version, and address is added in the second iteration version. The difference in member variable names refers to the change in the name of the member variable. For example, the name in the first iteration version may be changed to fullName in the second iteration version. The difference in member variable access modifiers refers to whether the access rights of the member variables have changed (such as private, public, protected, etc.), which affects whether external classes or systems can directly access these member variables. The difference in member variable types refers to the change in the data type of the member variables. For example, the data type changes from int in the first iteration version to String in the second iteration version, which may affect the storage and transmission of data during serialization and deserialization. The difference in serialization tag fields refers to whether there is an annotation (such as @ASN1Tag) or other tag to identify the tag of the field during serialization.
[0051] Please refer to Figure 6 In one embodiment, the class member function difference refers to the change of the function in the class, which mainly includes at least one of the difference in function addition and reduction, function name difference, function input parameter difference, function return value difference and function access modifier difference.
[0052] In one embodiment, the difference in function addition and deletion refers to the addition of new functions or the deletion of old functions. For example, getAddress() does not exist in the first iteration version, but is added in the second iteration version. The difference in function name refers to the change in the name of the function, for example, getName() in the first iteration version is changed to getFullName() in the second iteration version. The difference in function input parameters refers to the change in the type and number of function parameters. For example, setAge(int age) in the first iteration version is changed to setAge(String age) in the second iteration version. The difference in function return value refers to whether the return value type of the function changes. For example, getAge() returns int in the first iteration version and returns String in the second iteration version. The difference in function access modifiers refers to the change in the access rights of the function (such as public, private, protected), which affects the accessibility of the method to the external system.
[0053] Please refer to Figure 7 In one embodiment, the inner class difference refers to the change of the inner class defined in the class. The inner class is a class defined inside the class and is often used to encapsulate logic closely related to the class. The inner class difference includes the inner class increase and decrease difference, the inner class name difference, the inner class access modifier difference, the inner class member variable difference and the inner class member function difference.
[0054] In one embodiment, the difference in the increase or decrease of inner classes refers to the addition of new inner classes or the deletion of old inner classes. For example, in the Person class in the first iteration version, an Address inner class is added in the second iteration version. The difference in inner class names refers to the change in the name of the inner class. The difference in inner class access modifiers refers to whether the access modifier (such as public, private, protected) of the inner class has changed, which will affect whether the outer class or the class outside the package can access the inner class. The difference in inner class member variables refers to whether the member variables in the inner class have increased or decreased, or the name or type has changed. The difference in inner class member functions refers to whether the functions in the inner class have increased or decreased, or the name or parameters have changed.
[0055] Step S140: creating instances of classes with code structure differences, assigning values to each instance to generate corresponding binary data, and generating final member difference analysis results based on the site comparison results of each binary data.
[0056] In one embodiment, in the class that has been determined to have code structure differences in the initial member difference analysis results, reflection is used to create an instance of the class, and each instance is assigned a value according to the code structure differences in each class, that is, the Java reflection feature is used to fill the data structure defined by the Java source code in the class. Then, ASN.1 serialization is performed on the instance that has completed the assignment to generate corresponding binary data (that is, an instance of two versions of the class that have been determined to have code structure differences is created, and member variables in the class with code structure differences are assigned in the instances corresponding to each version, and ASN.1 serialization is performed after each version has completed the assignment to generate binary data corresponding to different versions). Serialization refers to the process of converting an object or data structure into a byte stream for cross-platform transmission.
[0057] It should be noted that in programming, an instance refers to a specific object of a class. When a class is created, we can generate specific objects through its defined properties (member variables) and methods (functions). These objects are instances of the class. An instance is the actual application of a class, a "copy" or "concretization" of the class, and can contain specific values or states.
[0058] In one embodiment, the sites of each binary data are compared one by one to detect whether the site comparison results of each binary data are consistent with the code structure differences in the initial member difference analysis results. If they are consistent, the code structure differences in the initial member difference analysis results are retained to complete the correction of the initial member difference analysis results. That is, the differences in binary data of different versions are compared, and the sites corresponding to the binary formats are analyzed one by one according to the known differences, and the results of the member difference analysis are corrected according to whether there are actual differences. The difference points of the data structure of different iterative versions of ASN.1 are determined according to the final member difference analysis results to provide change prompts for program development. That is, according to the above analysis process, the difference points between different iterative versions are summarized, and the user is prompted that each difference point corresponds to the position that may need to be changed in the actual encoding, as well as the recommended change plan.
[0059] In one embodiment, the specific process of comparing the sites of each binary data one by one and detecting whether the site comparison results of each binary data are consistent with the code structure differences in the initial member difference analysis results includes: assigning values to newly added member variables, checking whether there is new content at the sites corresponding to the binary data, and whether the new content is consistent; assigning values to deleted member variables, checking whether serialization can be successful, and whether the content is deleted at the sites corresponding to the binary data; assigning values to member variables with changed names, and checking whether the data at the sites corresponding to the binary data remains consistent; assigning values to member variables with changed types, and checking whether the data at the sites corresponding to the binary data is updated synchronously.
[0060] In one embodiment, when assigning values to newly added member variables, checking whether there is new content at the corresponding position of the binary data and whether the new content is consistent is to confirm whether the newly added member variables are correctly reflected in the serialized binary data. Specifically: in the second iterative version of the class, assign values to the newly added member variables (i.e., variables that do not exist in the class in the first iterative version), and then perform ASN.1 serialization to convert the object into binary format. Check whether the corresponding position has been added to the binary data (i.e., the value of the member variable has been added to a certain position in the binary data). Whether the newly added content is consistent with the assigned data, that is, whether the format of the serialized data meets expectations.
[0061] In one embodiment, assigning values to deleted member variables, checking whether serialization can be successful, and checking whether the content is deleted at the corresponding position of the binary data is to confirm whether the deleted member variables are correctly removed in the binary format of the new version. Specifically: in the first iterative version of the class, assign values to the deleted member variables and perform serialization, and then try the same operation in the new version. In the second iterative version of the class, check whether serialization can proceed normally (although the member variable has been deleted in the second iterative version). Check whether the content corresponding to the member has been deleted in the binary data, that is, whether the binary data part that existed in the first iterative version no longer appears in the new version of the data.
[0062] In one embodiment, assigning values to member variables whose names have been changed and checking whether the corresponding sites of the binary data remain consistent is to confirm whether the change in the member variable name is limited to the name itself and does not affect the data consistency of the serialized format. Specifically: in the second iterative version of the class, some member variables may only be renamed (the variable name has changed but the logic is still the same). At this time, assign values to the variables and perform serialization. Check the corresponding sites of the variables in the binary data before and after the rename to confirm whether the binary data is consistent.
[0063] In one embodiment, assigning values to member variables of changed types and checking whether the corresponding sites of binary data are updated synchronously is to ensure that the data after the variable type is changed can be correctly updated to the binary format of the second iterative version and compared with the binary data generated by the first iterative version. Specifically: assigning values to variables whose types have changed (for example, the variable changes from int to String) and serializing them. Checking whether the site of the variable has changed in the serialized binary data, and whether the new type is correctly serialized into the corresponding ASN.1 binary format. Whether the binary data can correctly reflect the change of type (for example, the encoding method of integer values is different from the encoding method of character strings).
[0064] This application uses the reflection characteristics of the Java language to analyze the definition differences of Java classes corresponding to different versions of ASN.1 structures. It can intuitively map and manage these data structures defined using ASN.1, derive version differences, and output analysis reports, thereby significantly improving development efficiency and code maintainability.
[0065] Those skilled in the art will appreciate that all or part of the functions of the various methods in the above-mentioned embodiments can be implemented by hardware or by computer programs. When all or part of the functions in the above-mentioned embodiments are implemented by computer programs, the program can be stored in a computer-readable storage medium, and the storage medium can include: read-only memory, random access memory, disk, optical disk, hard disk, etc., and the program is executed by a computer to implement the above-mentioned functions. For example, the program is stored in the memory of the device, and when the program in the memory is executed by the processor, all or part of the above-mentioned functions can be implemented. In addition, when all or part of the functions in the above-mentioned embodiments are implemented by computer programs, the program can also be stored in a storage medium such as a server, another computer, disk, optical disk, flash disk or mobile hard disk, and can be downloaded or copied and saved in the memory of the local device, or the system of the local device is updated, and when the program in the memory is executed by the processor, all or part of the functions in the above-mentioned embodiments can be implemented.
[0066] The above specific examples are used to illustrate the present invention, which is only used to help understand the present invention and is not intended to limit the present invention. For those skilled in the art, according to the concept of the present invention, some simple deductions, modifications or substitutions can be made.
Claims
1. A method for determining ASN.1 structure version differences, characterized in that: include: Get the data structure of different iteration versions of ASN.1; Parse the data structure of each version of ASN.1 to generate corresponding classes of the set programming language; Compare the various categories to determine the differences in code structure within each category to generate initial member difference analysis results; Obtaining classes with different code structures under different iteration versions, and creating instances of the classes with different code structures; Assign values to each instance, and serialize the assigned instances to generate binary data accordingly; Compare the sites of each binary data one by one, modify the initial member difference analysis result according to the site comparison result of each binary data, and generate a final member difference analysis result; The difference points of the data structures of different iterative versions of ASN.1 are determined according to the final member difference analysis result to provide modification prompts for program development.
2. The method for determining ASN.1 structure version differences according to claim 1, characterized in that: The data structure of each version of ASN.1 is parsed to generate a class of a set programming language, including: Use jasn1 to parse the data structures of various versions of ASN.1 to generate corresponding Java classes.
3. The method for determining ASN.1 structure version differences according to claim 2, characterized in that: The comparing of the various categories to determine the code structure differences in the various categories to generate initial member difference analysis results includes: Use the reflection feature of Java to compare the various categories to determine the differences in the code structure of each category.
4. The method for determining ASN.1 structure version differences according to claim 3, characterized in that: The code structure differences include at least one of package differences indicating changes in the package path where the class is located, class member variable differences indicating changes in attributes in the class, class member function differences indicating changes in functions in the class, and internal class differences indicating changes in internal classes defined in the class.
5. The method for determining ASN.1 structure version differences according to claim 4, characterized in that: The package difference includes at least one of a package path difference indicating a change in the directory to which the class belongs, a class increase / decrease difference within the package indicating a change in the number of classes, and a class name difference indicating a change in the name of the class.
6. The method for determining ASN.1 structure version differences according to claim 4, characterized in that: The class member variable differences include at least one of member variable increase or decrease differences indicating changes in the number of member variables in the class, member variable name differences indicating changes in the names of member variables in the class, member variable access modifier differences indicating changes in access rights of member variables in the class, and member variable type differences indicating changes in the data types of member variables in the class.
7. The method for determining ASN.1 structure version differences according to claim 4, characterized in that: The class member function differences include at least one of the following: function increase or decrease differences where new functions are added or old functions are deleted in the class, function name differences where the names of functions in the class are changed, function input parameter differences where the parameter types and quantities of functions in the class are changed, function return value differences where the return value types of functions in the class are changed, and function access modifier differences where the access rights of functions in the class are changed.
8. The method for determining ASN.1 structure version differences according to claim 4, characterized in that: The inner class differences include at least one of the following differences: inner class increase / decrease differences in which new inner classes are added or old inner classes are deleted, inner class name differences in which the names of inner classes in the class are changed, inner class access modifier differences in which the access rights of inner classes in the class are changed, inner class member variable differences in which the number of inner class member variables in the class or the names of inner class member variables are changed, and inner class member function differences in which the number of functions in the class in the class is changed or the names of inner class functions are changed.
9. The method for determining ASN.1 structure version differences according to claim 1, characterized in that: The step of assigning a value to each instance and serializing the instance after the value assignment is completed to generate binary data accordingly; comparing the sites of each binary data one by one, correcting the initial member difference analysis result according to the site comparison result of each binary data, and generating a final difference analysis result, including: Each instance is assigned a value according to the code structure difference in each category, and the site comparison result of each binary data is detected to see whether it is consistent with the code structure difference in the initial member difference analysis result. If it is consistent, the code structure difference in the initial member difference analysis result is retained to complete the correction of the initial member difference analysis result.
10. A computer-readable storage medium, characterized in that: The medium stores a program, which can be executed by a processor to implement the method according to any one of claims 1 to 9.