aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src
AgeCommit message (Collapse)Author
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-12per/uper: Fix code generation for nested types in objectsBjörn Gustavsson
2015-01-12Clean up use of asn1ct_gen:gen_types()Björn Gustavsson
asn1ct_gen:gen_types/3 is called by gen_encode_constructed/4 and generates encode *and* decode functions for any nested types. To faciliate future rewriting, where we might want to tweak code generation for encode and decode separately, refactor the code so that gen_encode_constructed/4 will only encode functions for nested types, and gen_deccode_constructed/4 will generate decode functions for nested types.
2015-01-12Correct recursion in OCTET STRING value definitionsBjörn Gustavsson
2015-01-12Fix BER code generationDan Gudmundsson
PKIX1Explicit-2009 did not compile.
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-12asn1: Fix BER generation for non optional and extended object setsDan Gudmundsson
Object sets with extension mark and without optional fields was not generated properly. It needs the default [enc|dec]_xxx function clause for the open type but no other clauses.
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-09-01Teach the ASN.1 compiler to understand "EXPORTS ALL"Björn Gustavsson
EXPORTS ALL is the same as leaving out the EXPORTS statement.
2014-09-01Teach the ASN.1 compiler the parse optionBjörn Gustavsson
2014-06-05BER: Eliminate dialyzer warnings for specialized decode functionsBjörn Gustavsson
2014-06-05BER: Eliminate dialyzer warning for encoding of BIT STRINGsBjörn Gustavsson
2014-06-05BER: Optimize encoding of ENUMERATEDBjörn Gustavsson
This will also eliminate a dialyzer warning.
2014-06-05BER: Remove a redundant clause in encoding of open typesBjörn Gustavsson
The clause is just an optimization for a (extremly rare) special case. Removing it will eliminate a dialyzer warning.
2014-06-05(U)PER: Fix decoding of named INTEGERBjörn Gustavsson
2014-06-05(U)PER: Fix encoding of a semi-constrained, named INTEGERBjörn Gustavsson
The code generator would crash.
2014-06-05(U)PER: Optimize handling of named BIT STRING with a lower zero boundBjörn Gustavsson
If a named BIT STRING has a lower size bound of 0, treat it the same way as if there was no constraint for the purposes of trailing zero bits. That change will eliminate a dialyzer warning.
2014-06-05PER: Optimize encoding of character strings with simple rangesBjörn Gustavsson
The encoder for the following type would generate a dialyzer warning: Ns ::= NumericString (FROM ("0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9")) Optimize this case to make it slightly faster as well as eliminate the dialyzer warning.
2014-06-05PER: Remove unnecessary clause for handling DEFAULTBjörn Gustavsson
2014-06-05(U)PER: Suppress dialyzer warnings for complete/1Björn Gustavsson
2014-06-05Correct OCTET STRING default when legacy_erlang_types is activeBjörn Gustavsson
The default value for an OCTET STRING when legacy_erlang_types was active would be a binary instead of a list.
2014-06-05Remove old DEFAULT-checking code made obsolete in the previous commitBjörn Gustavsson
2014-06-05Rewrite the code for testing DEFAULT for DERBjörn Gustavsson
The old code for testing DEFAULT values is messy, inefficient, and causes dialyzer warnings.
2014-05-06BER: Optimize decoding of ENUMERATEDBjörn Gustavsson
2014-05-06BER: Suppress dialyzer warnings for encode_bit_string/4Björn Gustavsson
We don't want to touch the code used for encoding BIT STRINGs when 'legacy_erl_types' is active, since it will be removed within two or three major releases. But we do want to suppress the dialyzer warnings in the meantime. The easiest way is to call encode_bit_string/4 with unknown types from an exported function that is never actually called like this: -export(['dialyzer-suppressions'/0]). 'dialyzer-suppressions'(Arg) -> {A,B,C,D} = Arg, encode_bit_string(A, B, C, D), ok.
2014-04-29BER: Inline testing of constraints when decodingBjörn Gustavsson
Calling library routines for validation of constraints may cause dialyzer warnings if some type of constraints handled by the library routine are not used in a specific ASN.1 module. To avoid those warnings (and slightly speed up the decoding), inline the constraint checking.
2014-04-16Refactor gen_dec_prim/3 to facilitate future optimizationsBjörn Gustavsson