aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_check.erl
AgeCommit message (Collapse)Author
2015-01-12Clean up and correct table constraint handlingBjörn Gustavsson
2015-01-12Correct another bug with instantiated typesBjörn Gustavsson
a1260b2ffa60581ce3af0728320b593cca3fd7b0 fixed a problem with expansion of parameterized types, but it didn't go all the way. The compiler would still crash if we attempted to define a value using the instantiated type.
2015-01-12Clean up matching of parametersBjörn Gustavsson
Introduce match_parameter/2 for matching a single parameter and match_parameters/2 for matching all of them.
2015-01-12Clean up handling of 'simpletable' and 'componentrelation'Björn Gustavsson
The constraint_member/2 function is used for looking up 'simpletable' and 'componentrelation' constraints. Both parts of its name are misleading. The "constraint" part makes you think that it is a general function for constraints, but it is not - it can only search for 'simpletable' and 'componentrelation'. The "member" part makes you think that it would return a boolean, but it returns either {true,Tuple} or false, making it more similar to lists:keysearch/3. Use lists:keyfind/3 (or lists:keymember/3) instead of constraint_member/2. Also use lists:keyfind/3 in one place where there was a direct matching of a 'simpletable' constraint.
2015-01-12Fix instantiation of an inlined type in a value definitionBjörn Gustavsson
2015-01-12Simplify and correct tag handlingBjörn Gustavsson
There is no reason to handle tags differently depending on the back-end. The PER back-end will simply ignore tags. There is also a bug in tags the ABSTRACT-SYNTAX and TYPE-IDENTIFIER pre-defined classes. So far it has not caused problems, but it could do in a future commit, such as the next commit...
2015-01-12Clean up constraint checkingBjörn Gustavsson
2015-01-12Use recursive get_referenced_type to get classdef directlyDan Gudmundsson
To be sure that indirect references to classes are solved.
2015-01-12Fix recursive get_referenced_typeDan Gudmundsson
2015-01-12Remove special case in parserBjörn Gustavsson
The parser handled the builtin ABSTRACT-SYNTAX and TYPE-IDENTIFIER classes specially, which caused problems. It turns out that there is no longer any need to handle those classes specially.
2015-01-12Improve handling of BIT STRING valuesBjörn Gustavsson
2015-01-12Check more errors in the simplified syntaxBjörn Gustavsson
An optional group must not contain mandatory class fields. All mandatory fields must be included in the simplified syntax.
2015-01-12Handle CLASS.&field when checking valuesBjörn Gustavsson
2015-01-12Clean up and correct validation of OBJECT IDENTIFIER/RELATIVE-OIDDan Gudmundsson
Besides simplifying the code and doing better error checking and error reporting, fix the following bugs: Support retrieving an OBJECT IDENTIFIER/RELATIVE-OID from an object. Example: oid OBJECT IDENTIFIER ::= some-object.&some-field Allow an integer constant first in an OBJECT IDENTIFIER: integer INTEGER ::= 0 oid OBJECT IDENTIFIER ::= {integer 1}
2015-01-12Fix object set duplication testBjörn Gustavsson
Wrong fields in the record where checked when sorting, which caused duplicate objects to exist in constructed object sets and later caused an error.
2015-01-12Correct recursion in OCTET STRING value definitionsBjörn Gustavsson
2015-01-12Clean up get_fieldname_element/3Björn Gustavsson
Also add proper error handling.
2015-01-12Provide more reliable location of errorsBjörn Gustavsson
File names and line number information was not reliable available when producing error messages. Some items have embedded line number information, and sometimes the S#state.type and/or S#state.value could be used to retrieve the line number information. To make sure that we can always retrieve at least an approximate error location, store the top-level construct being checked in S#state.error_context. Example of top-level constructs: Seq ::= SEQUENCE {...} i INTEGER ::= 42 This is a short-term solution. In the long term, we would want the parser to include line number information in all items.
2015-01-12Rewrite matching of object definitions using the simplified syntaxBjörn Gustavsson
Rewrite the confusing and buggy matching of an object definition against the simplified syntax. While we are at it, we will also add proper error handling.
2015-01-12Simplify handling of an empty object definitionBjörn Gustavsson
When the parser sees: something SOMETHING ::= {} it has no way of knowing whether 'something' is an value or an object. It depends on how SOMETHING is defined. For example: SOMETHING ::= SEQUENCE {} or SOMETHING ::= CLASS { &id OPTIONAL } Because of that ambiguity, there is no way to avoid a special case when we check an object definition. However, there is no need to invent an entire new checking function for this special case. It is much easier to just pretend that the parser gave us {object,defaultsyntax,[]} and let check_objectdefn/3 check it in the usual way.
2015-01-12Use object_to_check/1 in two forgotten placesBjörn Gustavsson
An #'Externavaluereference'{} may either be a value or an object. In places where objects are expected, we will need to call object_to_check/1 to convert an #'Externavaluereference'{} to an object. It was forgotten in two places.
2015-01-12Refactor code involving calls to get_fieldname_element/3Björn Gustavsson
Refactor and clean up code. While at it, add error handling and test cases. (Also add test cases for the existing values in ValueTest.asn while we are it.) Add support for defining INTEGER constants by extracting fields from objects. Example: int-from-object INTEGER ::= object.&id When extracting values from objects in constraints, only one level of extraction would work. That is, the following would work: SomeName ::= INTEGER (object.&int) but not: SomeName ::= INTEGER (object.&obj.&int)
2015-01-12Check INTEGER values betterBjörn Gustavsson
There is duplicated effort in that validate_integer() checks whether the integer value is valid, and then normalize_integer() does mostly the same work in order to convert the value to an integer. Eliminate the validate_integer() function and incorporate its checks into normalize_integer(). Also produce proper error messages.
2015-01-12Check CLASS names for validityBjörn Gustavsson
Class names must start with an uppercase letter and only contain uppercase letters, digits, or hyphens. The parser will not allow class names that don't start with an uppercase letter, so we don't have to check that.
2015-01-12Use the #objectclass{} record instead of a tupleBjörn Gustavsson
Don't build a record using the tuple syntax. It is bad in case we would want to change the record definition later.
2015-01-12Correct typo in an error messageBjörn Gustavsson
2014-11-27Merge branch 'dgud/asn1/fix-seqtag/OTP-12326' into maintDan Gudmundsson
* dgud/asn1/fix-seqtag/OTP-12326: asn1: Fix EXTERNAL (1994 variant) type conversion
2014-11-26asn1: Fix EXTERNAL (1994 variant) type conversionDan Gudmundsson
Missed to add seqtag handling for EXTERNAL type conversion, bug introduced in c266196c016fc1156c7a18cfeec4920ee4075519
2014-11-24Fix IMPLICIT tagging when TagDefault is AUTOMATICSimon Cornish
This patch fixes a bug with compliance to X.680 (200811) s31.2.7 Basically, when TagDefault is AUTOMATIC then tags are IMPLICIT unless EXPLICIT is given.
2014-09-01Workaround for combining two object sets separated by extensionBjörn Gustavsson
The following type of code would crash the compiler: OSET SOME-CLASS ::= {OSET1, ..., OSET2}
2014-09-01Clean up and correct handling of parameters for parameterized typesBjörn Gustavsson
The previous code looked at the actual parameters supplied when instantiating the type to determine the type of the argument; the correct way is to determine the type by looking at the governor and case of the formal parameter.
2014-09-01Check the formal parameter for parameterized type definitionsBjörn Gustavsson
Check the formal parameters for a parameterized type definition. If the governor for a formal parameter is absent, the formal parameter must be in upper case.
2014-09-01Report errors also for unused parameterized typesBjörn Gustavsson
Definitions for parameterized types are verified once very early, and one more time when they are instantiated. Errors found during the first check were ignored, so errors for unused parameterized types were not reported.
2014-09-01Remove unused code for ABSTRACT-SYNTAX and TYPE-IDENTIFIERBjörn Gustavsson
Before classes were fully implemented, there was support for ABSTRACT-SYNTAX and TYPE-IDENTIFIER. Some of that code is still there and is no longer used. Get rid of it and correct comments.
2014-09-01Correct expansion of parameterized typesBjörn Gustavsson
Attempting to compile: SomeType{SOME-CLASS-NAME, SOME-CLASS-NAME:SomeSet} ::= ... SEQUENCE { something SOME-CLASS-NAME.&id({SomeSet}) } would crash the compiler, because the actual parameter for SOME-CLASS-NAME was not substituted into the governor for the SomeSet parameter. While we are at it, combine the functionality of is_class/2 and get_class_def/2 (eliminating is_class/2). Most callers call both function.
2014-09-01Add the module name to the #classdef{} recordBjörn Gustavsson
If we want construct an #'Externaltypereference'{} from a #classdef{} record, we will need the module name.
2014-09-01Eliminate the use of #identifier{} outside the tokeniser and parserBjörn Gustavsson
The only remaining use of #identifier{} in asn1ct_check was in a temporary packaging of a value that would be ultimately be put into #valuedef{}. Therefore we can eliminate that last usage but putting the value directly into a #valuedef{} and we can move the record definition into asn1ct_parser2.
2014-09-01Fix problem with object identifiers in external modulesBjörn Gustavsson
When parsing ASN.1, certain constructs can only be understood in the full context of the entire ASN.1 module. For instance, the value following ID in this simplified excerpt from MTSAbstractService88: administration-88 PORT ::= { ID {id-pt-administration 88} } the value following "ID" can be interpreted either as value for: SEQUENCE { id-pt-administration INTEGER } or as an OBJECT IDENTIFIER. Our ASN.1 parser assumes that a SEQUENCE is meant, and if that later turns out to be wrong, the SEQUENCE value is rewritten to an OBJECT IDENTIFIER. The problem is that at the time of the rewrite, we no longer know in which ASN.1 module id-pt-administration was defined in, and we have to use the module name in the state{} record. Unfortunately, the module name in the state{} record may not always be correct. While there are attempts in the code to keep the module name up-to-date when checking imported types, it is not done consistently, and it seems to be a difficult and error-prone task to attempt to make it consistent. A safer and less error-prone approach is to make sure that we don't lose the module name while parsing. To make it clear what we are doing, we will introduce a new #seqtag{} record that are used for tags in SEQUENCE values. The name is based on its primary use. The record also contains the module in case it happens to be an OBJECT IDENTIFIER.
2014-09-01Rewrite get_referenced_type/2Björn Gustavsson
Make sure that we continue to follow external references until we find a real type.
2014-09-01Teach the ASN.1 compiler to handle objects in field namesBjörn Gustavsson
2014-02-28Clean up reporting of errors in IMPORTSBjörn Gustavsson
2014-02-28asn1ct_check: Clean up error checking for INSTANCE OFBjörn Gustavsson
This will also eliminate a dialyzer warning for unmatched returns, and increase the coverage.
2014-02-28asn1ct_check: Rewrite error checking for INTEGER and BIT STRINGBjörn Gustavsson
The error checking code for INTEGER and BIT STRING was broken, since it built an error tuple that was never returned. Rewrite the error checking code, sharing most of the code between INTEGER and BIT STRING. Make sure that we test for both duplicated names and number, as well as for negative bit numbers for BIT STRING. This rewrite will eliminate two dialyzer warnings for unmatched returns.
2014-02-28asn1ct_check: Remove unreachable clauses handling {identifier,_,_}Björn Gustavsson
A named number list as used for ENUMERATED and INTEGER can never have an {identifier,...} tuple in its third position like this: {'NamedNumber',Id,{identifier,_,_}} because asn1ct_parser2:parse_NamedNumber/1 will always replace an identifier tuple with an #Externaluereference{} record.
2014-02-28asn1ct_check: Let asn1_error/3 throw its resultBjörn Gustavsson
Since most calls to asn1_error/3 throw its result, it makes more sense to let asn1_error/3 itself throw the error tuple. Add the return_asn1_error/3 to return the error tuple to use when we don't want to throw it.
2014-02-20Merge branch 'bjorn/asn1/cleanup/OTP-11727'Björn Gustavsson
* bjorn/asn1/cleanup/OTP-11727: asn1ct_check: Use a return value to silence a dialyzer warning asn1ct_check: Remove useless call to check_integer/3 asn1ct_check: Correct error handling for illegal OCTET STRING values asn1ct: Silence dialyzer warnings for unmatched returns asn1ct_table: Remove unused flexibility in table creation asn1ct_table: Silence a dialyzer warning for unmatched return asn1ct_gen: Silence dialyzer warnings for unmatched returns asn1ct_value: Silence a dialyzer warning for unmatched return asn1ct_tok: Check return value from file:close/1
2014-02-13Correct subtyping of extensible ENUMERATEDBjörn Gustavsson
Attempting to subtype an extensible ENUMERATED like this: BaseType ::= { foo, bar, ... } SubType ::= BaseType ( foo ) would fail to compile with a message that 'foo' was undefined. Reported-by: Morten Nygaard Åsnes
2014-01-31asn1ct_check: Use a return value to silence a dialyzer warningBjörn Gustavsson
Unfortunately the code in question is not covered by our test suites, but it should be correct to do the same thing as in the clause above.
2014-01-31asn1ct_check: Remove useless call to check_integer/3Björn Gustavsson
check_integer/3 can check nothing for an INTEGER without any named values. Remove the useless call to silence a dialyzer warning for unmatched return.
2014-01-31asn1ct_check: Correct error handling for illegal OCTET STRING valuesBjörn Gustavsson
The value for an OCTET STRING must be specified as either a bstring or an hstring. Everything else (including character strings) is illegal. This correction also removes the offending code that caused an unmatched return warning from dialyzer.