Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • onion/asn1c
  • oai/asn1c
  • ptizoom/asn1c
  • havar_mind/asn1c
  • gao/asn1c
  • samlty/asn1c
  • tomrom/asn1c
  • tjamc80/asn1c
  • james862/asn1c
  • gaoridong2009/asn1c
  • zhourenquan/asn1c
11 results
Show changes
Commits on Source (1354)
*.o
*.la
*.lo
*.libs
*.deps
*.core
# /
/autom4te.cache
/config.h
/config.log
/config.cache
/config.status
/configure.lineno
/local-configure.sh
/libtool
/stamp-h*
/asn1c-*.tar.gz
/asn1c.spec
/Makefile
# /asn1c/
/asn1c/Makefile
/asn1c/asn1c
/asn1c/unber
/asn1c/enber
# /asn1c/tests/
/asn1c/tests/Makefile
/asn1c/tests/test-*
# /doc/
/doc/Makefile
# /doc/docsrc
/doc/docsrc/Makefile
doc/docsrc/*.aux
doc/docsrc/*.dvi
doc/docsrc/*.log
doc/docsrc/*.out
doc/docsrc/*.toc
doc/docsrc/*.xdv
# /examples/
/examples/Makefile
/examples/*.asn1
# /examples/*/
/examples/*/*.c
/examples/*/*.h
/examples/*/*dump
/examples/*/.tmp.*
# /libasn1compiler/
/libasn1compiler/Makefile
/libasn1compiler/check_compiler
# /libasn1fix/
/libasn1fix/Makefile
/libasn1fix/check_fixer
# /libasn1parser/
/libasn1parser/Makefile
/libasn1parser/check_parser
# /libasn1print/
/libasn1print/Makefile
# /skeletons/
/skeletons/Makefile
# /skeletons/standard-modules/
/skeletons/standard-modules/Makefile
# /skeletons/tests/
/skeletons/tests/Makefile
/skeletons/tests/check-*
# /tests/
/tests/Makefile
......@@ -5,27 +5,28 @@ known. Not a huge problem for run-once programs like a compiler.
NOTE: This statement does not apply to the target code _produced_
by the compiler.
1. REAL type is not supported yet.
2. For purposes of compilation, INTEGER type is modelled using a large
1. For purposes of compilation, INTEGER type is modelled using a large
static type (asn_integer_t), but defined as any positive or negative value
by ASN.1. Not a problem as most specifications use very small values anyway.
NOTE: This statement does not apply to the target code _produced_
by the compiler.
3. ASN Macros are prohibited by the current ASN.1 standard,
and are not supported.
2. A MACRO facility is part of obsolete ASN.1 standard, and is not supported.
4. Multiple tags applied at the same level are not supported:
3. Multiple tags applied at the same level are not supported:
BadTags ::= [0] EXPLICIT [2] IMPLICIT OtherType
The same thing could be achieved by using the indirection:
GoodTags ::= [0] EXPLICIT OtherTypePtr
OtherTypePtr ::= [2] IMPLICIT OtherType
5. Mixed definite/indefinite length in a _single_ BER tags sequence is not
4. Mixed definite/indefinite length in a _single_ BER tags sequence is not
supported. Should not be a problem in the real world. Please note that it
is still possible, for example, to encode a wrapper structure using definite
length, and encode its substructure member using indefinite length. The BER
decoder is perfectly capable of decoding such sequences.
5. Encoding or decoding of structures with combined length greater than 16MB
is not tested.
6. XER codec does not support integer (INTEGER, ENUMERATED) values
outside the signed long range.
/*-
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>
* Copyright (c) 2003, 2004, 2005, 2006, 2007 Lev Walkin <vlm@lionet.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......
0.9: 2004-Aug-19
???:
* Updated asn1c-usage.pdf.
* Made -fskeletons-copy a default option; removed cmdline option.
* Made -fnative-types a default option; removed cmdline option.
Added -fwide-types for backwards compatibility.
* Add -fline-refs to avoid being unfriendly to version control systems.
0.9.24: 2013-Mar-16
* GeneralizedTime fix for working with time offsets which are not
representable in whole hours. (Severity: low; Security impact: low)
Thanks to IP Fabrics, Inc.
* Added -fincludes-quoted to asn1c to generate #includes in "double"
instead of <angle> quotes.
* PER encoding correctness fix. (Severity: high; Security impact: low)
Reported by Grzegorz Aksamit.
* ENUMERATED extension values check relaxed. Reported by Gabriel Burca.
* Fixed decimal decoding of REAL values in -fnative-types mode
(Severity: medium; Security impact: medium)
* Removed webcgi subproject (introduced in 2004) as useless.
0.9.22: 2008-Nov-19
* Added -pdu=all and -pdu=<type> switches to asn1c.
* Added PER support for most known-multiplier string types:
IA5String, VisibleString, PrintableString, BMPString, UniversalString;
useful types: GeneralizedTime, UTCTime, ObjectDescriptor;
as well as REAL and OBJECT IDENTIFIER.
TODO: SET type.
* Added PER support for extensions in SEQUENCE.
* Multiple enhancements by Daniele Varrazzo <daniele.varrazzo@gmail.com>
* Fixed explicit tagging of an in-lined constructed type.
(Severity: low; Security impact: none).
* Memory leak fixed in SET OF / SEQUENCE OF when wrong encoding
is encountered. (Severity: medium; Security impact: low)
* Fixed extensibility handling of second SEQUENCE production.
(Severity: low; Security impact: none)
* Added DEFAULT handling for known multiplier string.
* Added a sample OMA ULP decoder (./examples/sample.source.ULP).
* Added full-width 32-bit integer encoding support in PER.
* Fixed 1-byte OOB write issue with non-standard and Windows
memory allocators (Severity: low; Security impact: medium).
Reported by Sheng Yu.
0.9.21: 2006-Sep-17
* skeletons/standard-modules directory is now used for standard types.
* Fixed class field access problem (Test case 98)
(Severity: medium; Security impact: none)
* Refactored Information Object Classes parsing.
* Refactored Parameterization support.
* [typedef enum foo {}] foo_e; is now e_foo, see #1287989
* Refactored ValueSetTypeAssignment parsing.
* asn-decoder-template.c renamed into converter-sample.c
* MEGACO (Media Gateway Control Protocol) decoder sample added.
* First release of PER encoder (does not encode SETs yet).
* Added a sample LDAP decoder (./examples/sample.source.LDAP3).
* Added a sample 3GPP RRC decoder (./examples/sample.source.RRC).
* Added a sample MEGACO (H.248.1) decoder (sample.source.MEGACO).
0.9.20: 2006-Mar-06
* SET OF CHOICE, SEQUENCE OF CHOICE and a certain named S/O types
are represented differently in XER. THIS IS AN INCOMPATIBLE CHANGE.
(Test case 70) (Severity: low; Security impact: low)
* asn1c: Removed -ftypes88 command line option.
* Started PER implementation. Somewhat experimental!
0.9.19: 2005-Oct-06
* A proper solution to circular references. No kludge flags
should be necessary anymore to produce reference-free code:
recursive dependencies are resolved automatically.
* Test cases 73 & 92 keep track of various circular references.
* Introduced compiler directives to allow finer control over the
generated code ("--<ASN1C...>--" in comments), (Test case 93).
* New feature for unber(1): -s <skip> bytes.
* Mandatory elements map for SET was not getting generated properly.
(Test case 94) (Severity: high; Security impact: low)
* asn1c: new command line option: -fskeletons-copy.
0.9.18: 2005-Aug-14
* The obsolete X.208 syntax is handled gracefully now (compound types'
member names are invented on the fly). (Test case 87).
* Generating enumeration tables for INTEGER types (Test case 88).
* Generating enumeration tables for BIT STRING types (Test case 89).
* Conditional INTEGER/ENUMERATED representation: long vs. INTEGER_t
type is chosen based on PER visible constraints (Test cases 90, 91).
* Union structures for CHOICE type are not anonymous anymore.
* Made unber(1) program more verbose: effective structure length is
now displayed as L="<n>" at the closing tag. (Test check-xxber.sh).
* Fixed unber(1)'s -1 switch for indefinite encoding length.
* New command line option for unber(1): -m to enable minimalistic mode.
0.9.17: 2005-Aug-07
* Tagging mode is implicitly IMPLICIT if AUTOMATIC TAGS is used, #30.6.
(Test cases 55, 86).
* Started to use extern "C" {} in skeleton headers.
* Introduced -finline-choice command line option to fix
yet another class of circular references.
0.9.16: 2005-July-04
* GeneralizedTime API now supports fractions of seconds.
Thanks to Bent Nicolaisen <BN@JAI.com> for support.
* ASN.1 parser has been tweaked to allow parsing something like
"SEQUENCE----comment----", which is ambiguous for many reasons.
* XER decoder better handles not-yet-defined future extensions.
0.9.15: 2005-July-02
* Compiler now checks 64-bit overflows in constraints range handling
code. No effect on the code produced by the compiler.
* Compiler support for tagged and marked parametrized members.
* Empty tags to element map avoided.
* Compiled code GCC 4.x compatibility.
0.9.14: 2005-Apr-29
* Fixed check-70.-fnative-integers.c test (it was failing
when no test directory was found).
0.9.13: 2005-Apr-24
* Added extra const qualifiers into the support code.
* More RFC variations supported in crfc2asn1.pl.
* Refined string values compatibility. (Test cases 77, 78).
* Support for ContainedSubtype constraints. (Test case 16).
* Parsing support for CONSTRAINED BY. (Test case 79).
* Support for CharsDefn (Quadruple and Tuple, most used in
ASN1-CHARACTER-MODULE) (Test case 80).
* Pretty-printing support for WITH COMPONENT[S]. (Test case 82).
* Streamed OCTET STRING decoding of large values: fixed allocation
problem introduced in 0.9.9. (Severity: high; Security impact: medium)
Reported by Yann Grossel <olrick@users.sourceforge.net>.
* Fixed BASIC-XER encoding of REAL numbers.
0.9.12: 2005-Mar-10
* Fixed a name clash in produced constraint checking code.
* #includes are now in single quotes (to solve a name
clash with system's <time.h> on a Win32 system).
* Small refinement of XML DTD generation (`asn1c -X`).
* Relaxed XER processing rules to skip extra whitespace
in some more places. It also skips XML comments (although
XML comments in XER are prohibited by X.693, #8.2.1).
(Test case 70) (Severity: medium; Security impact: none)
Reported by <Dominique.Nerriec@alcatel.fr>.
* Constraints on primitive types being defined are now supported.
(Test case 74) (Severity: low; Security impact: none)
* XMLValueList generation fixed for CHOICE type.
(Severity: medium; Security impact: none)
* Added the GSM TAP3 decoder into ./examples/sample.source.TAP3
0.9.11: 2005-Mar-04
* Released -fcompound-names to fix the name clashes in the code
produced by the asn1c.
* Released -fno-include-deps to avoid #including non-critical
external dependencies.
* Compiler is taught to produce compilable code for yet another class
of circular ASN.1 type references.
* X.693:8.3.4 prohibits anything but SignedNumber; fixed XER codec.
* Fixed ENUMERATED identifier to value conversion in XER.
Reported by <jacque.celaire@caramail.com>.
* If the compiled file contents are the same as in already existing
file (left from previous compilation), the old file is retained.
This prevents thrashing `make` dependencies if amount of changes in
the original ASN.1 module(s) is small.
0.9.10: 2005-Feb-25
* Completed the XER XMLValueList encoding and decoding.
* Native integer type is now using "long".
* Fixed #1150856. Reported by <vvvy@users.sourceforge.net>.
* Some WIN32 portability fixes.
0.9.9: 2005-Feb-22
* First release of XER (XML) decoding implementation (somewhat
experimental).
* ANY allocation routine fixed.
Reported by <mikko.ahonen@elma.net>.
* Fixed tag parsing (tags like "[ 0 ]" were not supported).
* Compiler now checks for duplicate ASN.1 types across modules.
0.9.8: 2005-Jan-17
* [NEW PLATFORM] Compiled and tested on Linux @ alpha64 (LP64).
Some code needed to be fixed regarding int-long conversions
(mostly inside the test suite), and floating point handling
code needed to be restructured to handle signalling NAN and
other floating point exceptions quietly. Smooth transition!
* [NEW PLATFORM] Compiled and tested on Sun Solaris 9 @ sparc.
Improved includes/defines of/for system headers.
* -X command line option added to asn1c to generate XML DTD.
* Empty SEQUENCE and SET clauses are now allowed.
* Removed confusion between &xNN; and &#xNN; in enber and unber.
* Removed order dependency in DEFAULT references to ENUMERATED
identifiers (./tests/68-*-OK.asn1).
* ber_dec_rval_t renamed into asn_dec_rval_t: more generality.
* Extensions in CHOICE types are properly marked as non-pointers
(Test case 59) (Severity: medium; Security impact: medium)
Reported by <roman.pfender@sdm.de>.
* Tagged CHOICE type is now supported again.
(Test case 59) (Severity: low; Security impact: low)
Reported by <orlinkata@dir.bg>.
* Implemented der_encode_to_buffer() procedure.
0.9.7.1: 2004-Oct-12
* Fixed automatic tagging for extensions of compound types.
* Fixed ParametrizedReference parsing: {} are now recognized.
0.9.7: 2004-Oct-11
* Finished CXER implementation by adding SET and SET OF canonical
ordering support.
* Fixed unber(1) limits controlling logic.
* Removed C99'izm from the x509dump, now understood by older compilers.
* Enhanced UTF8String constraint validation, now it checks
for the minimal encoding length; API of UTF8String_length() changed.
* Fixed SEQUENCE dealing with premature termination of the
optionals-laden indefinite length structure. The code was previously
refusing to parse such structures.
* Fixed explicitly tagged ANY type encoding and decoding
(Severity: medium; Security impact: low).
* Fixed CHOICE code spin when indefinite length structures appear
in the extensions (Severity: medium; Security impact: medium).
Reported by <siden@ul-gsm.ru>.
* BIT STRING now stores the number of unused octets in a separate field.
0.9.6: 2004-Sep-29
* Added several security firewalls: decoder's stack usage control
and the stricter checking of the TLV length.
* Implemented BASIC-XER encoding support (X.693).
* Implemented unber(1) and enber(1) for BER<->XML translation.
* Implemented CGI for online ASN.1 compilation (asn1c/webcgi).
* Implemented the sample X.509 decoder (./examples/sample.source.PKIX1).
* NamedType is now supported for SET OF/SEQUENCE OF type.
* Added -fno-constraints option to asn1c, which disabled generation of
ASN.1 subtype constraints checking code.
* Added ASN1C_ENVIRONMENT_VERSION and get_asn1c_environment_version().
* Fixed ANY type decoding (Severity: high; Security impact: low).
* Fixed BER decoder restartability problem with certain primitive
types (BOOLEAN, INTEGER, and REAL). The problem occured when the
encoding of such type is split between several bytes.
(Severity: high; Security impact: low)
* Support for cross-referencing type definitions (updated ./tests/43-*).
* Fixed pretty-printing of the REAL type. Added lots of test cases.
* Renamed asn1_* into asn_* in function and type names.
* Updated documentation.
0.9.5: 2004-Sep-17
* Fixed CER (common BER) decoder code. See check-25.c/VisibleString
case for details. X.690 specifies that inner structures in BER
encoding must be tagged by stripping off the outer tag for each
subsequent containment level. See also X.690: 8.21.5.4 and
the "Spouse" case in A.3.
(Severity: medium; Security impact: low)
* Added converters between any generic type and the ANY type.
* Parser fixed: Information Object Class fields may be taged.
* Parser fixed: tagged types inside SEQUENCE OF/SET OF support.
* Improved DEFAULT Value parsing and pretty-printing.
* Condition on distinct tags checker was incorrectly dealing with
tagged CHOICE types. Fixed. Modified tests/37-indirect-choice-OK.asn1
* Improved type name generation code ("struct foo" vs "foo_t").
* Fixed constraint checking code incorrectly dealing with imported
types with constraint values defined in other modules.
* Real REAL support! (Haven't tested denormals support yet!)
See skeletons/tests/check-REAL.c
0.9.4: 2004-Sep-10
* More support for recursive type definitions.
* Explicit support for ANY type decoding.
* Refactored tags processing code.
* Fixed constraints checking code: non-exploitable buffer overflow.
(Severity: medium; Security impact: low)
0.9.3: 2004-Sep-07
* Extended constraints support in parametrized types.
* Better support for parametrization and constraints handling.
* Better handling of recursive type definitions.
* Added support for ANY type.
0.9.2: 2004-Aug-24
* More flexible subtype constraints handling, with relaxed
PER visibility rules for actual constraints checking code generator.
* Indirect references in constraints resolver code fixed.
* Avoided compilation warning on gcc 3.3.3 systems.
* Better ValueSet printing.
0.9.1: 2004-Aug-23
* Documentation updated: doc/asn1c-usage.pdf
* Fixed OBJECT IDENTIFIER human-readable printing.
Reported by <siden@ul-gsm.ru>.
0.9: 2004-Aug-23
* Reworked subtype constraints handling, aiming at PER-applicability.
* BOOLEAN and NULL are now implemented in terms of native int type.
* Compiler now links in only necessary skeleton files.
* -t option added to asn1c to ease BER manual decoding.
* -t option added to asn1c to ease manual BER/CER/DER decoding.
* Added support COMPONENTS OF construct.
* Numerous parser fixes and enhancements.
* Better constraint failure reporting.
0.8.19: 2004-Aug-18
* Fixed BER encoder (problem encoding large tag values)
(Severity: medium, Security impact: low)
(Severity: medium; Security impact: low)
0.8.18: 2004-Aug-12
......@@ -25,16 +333,16 @@
0.8.16: 2004-Jul-22
* Fixed application-level problem in SET OF/SEQUENCE OF array cleanup.
(Severity: medium, Security impact: low)
(Severity: medium; Security impact: low)
* Improved asn_GT2time() and added asn_time2{GT,UT}() functions.
* BIT STRING pretty-printing.
0.8.15: 2004-Jul-20
* Fixed parser: memory leak in free_struct code for SET OF/SEQUENCE OF.
(Severity: high, Security impact: medium)
(Severity: high; Security impact: medium)
* Fixed parser: invalid memory reference in code constructing tags.
(Test case 48) (Severity: high, Security impact: medium)
(Test case 48) (Severity: high; Security impact: medium)
When encoding data for certain ASN.1 specifications containing
explicit tags, the tag is always written incorrectly due to
incorrect memory reference. The encoding will almost always produce
......@@ -51,13 +359,13 @@
* Fixed compiler: extensibility of CHOICE and SET type has not been
taken into account during table construction.
(Test case 47) (Severity: high, Security impact: low)
(Test case 47) (Severity: high; Security impact: low)
0.8.13: 2004-Jun-29
* Fixed compiler: the skip values for IMPLICIT tagging were broken
in some complex cases where one type is defined using another.
(Test case 46) (Severity: medium, Security impact: low).
(Test case 46) (Severity: medium; Security impact: low).
* Added -fknown-extern-type command line parameter to asn1c.
* Removed -N command line flag and underlying functionality
to honor KISS principle.
......@@ -69,7 +377,7 @@
size of an integer must be provided explicitly.
See {OBJECT_IDENTIFIER|RELATIVE_OID}_{get|set}_arcs().
* SEQUENCE BER decoder fixed again for complex CHOICE case
(Test case 44) (Severity: medium, Security impact: low).
(Test case 44) (Severity: medium; Security impact: low).
0.8.11: 2004-Jun-05
......@@ -94,18 +402,18 @@
* Fixed compiler. If the last member of the SEQUENCE is OPTIONAL
and absent in the encoding, and the type is extensible (...) or
EXTENSIBILITY IMPLIED flag is set, then the structure could not
be correctly decoded. (Severity: high, Security impact: low).
be correctly decoded. (Severity: high; Security impact: low).
* Compiler: fixed recursive ASN.1 types inclusion (Severity: low,
Security impact: none).
* Parser: IMPORTS/FROM fixes, now allowing multiple sections.
* Code compiled and checked on PowerPC (@MacOS X). No major portability
issues experienced.
* NEW PLATFORM: Compiled and tested on MacOS X (@ PowerPC).
No major portability issues experienced.
0.8.7: 2004-Apr-11 T-version-0-8-7
* Fixed SEQUENCE BER decoder: if the last member of the SEQUENCE is
OPTIONAL and absent in the encoding, RC_FAIL was returned instead
of RC_OK (Severity: high, Security impact: low).
of RC_OK (Severity: high; Security impact: low).
* Added test case to check the above problem.
* Added test case to check -fnative-integers mode.
......@@ -115,7 +423,7 @@
0.8.5: 2004-Mar-28 T-version-0-8-5
* Fixed ber_tlv_length() computation problem (Severity: blocker,
* Fixed ber_tlv_length() computation problem (Severity: high,
Security impact: none).
Reported by <vss@high.net.ru>
......@@ -127,9 +435,9 @@
0.8.3: 2004-Mar-14 T-version-0-8-3
* Fixed SET::BER decoder: restart after reaching a buffer boundary
weas broken (Severity: blocker, Security impact: low).
weas broken (Severity: high; Security impact: low).
* Fixed OCTET STRING::BER decoder: restart after reaching a buffer
boundary was broken (Severity: blocker, Security impact: low).
boundary was broken (Severity: high; Security impact: low).
Reported by <vss@high.net.ru>
* Added test cases to check decoders restartability.
* Slightly more general INTEGER2long decoder.
......@@ -206,3 +514,30 @@
0.1: 2003-Nov-28
* Programming started.
=== Bug importance disclosure terms ===
SEVERITY.
This term applies to the frequence the particular construct is used
in the real world. The higher the frequency, the more chances of triggering
this bug.
low: The ASN.1 specifications which could trigger
this kind of bug are not widespread.
medium: The particular ASN.1 construct is used quite often,
so the chance of triggering an error is considerable.
high: This fix is considered urgent, or the particular ASN.1
construct triggering this bug is in wide use.
SECURITY IMPACT.
This term applies to the amount of potential damage a bug exploitation
could cause.
none: No malicious exploitation is possible.
low: The local exploitation is unlikely; the remote exploitation
is impossible.
medium: The remote exploitation is possible when a particular ASN.1
construct is being used. If possible, only hard failure, spin
or memory leak are the possible outcome: no shellcode
injection could possibly be carried by the attack.
high: The remote shellcode injection is possible, or the bug is
otherwise remotely exploitable for most specifications.
1.Q: Is it possible to build the asn1c compiler on Win32?
1.A:
At this point, the asn1c source code is tied to GCC-specific
extensions in several key places. The CYGWIN environment with
gcc compiler may be what are you looking for.
Please also consider using the Online ASN.1 compiler at
http://lionet.info/asn1c
which generates platform-independent code.
2.Q: How to build a simplest BER (XER) encoder or decoder?
2.A:
Please check the "Quick Start Guide" on ./doc/asn1c-quick.pdf
Please check the "Examples" section of ./doc/asn1c-usage.pdf
Also, try the following to build the X.509v3 parser:
cd ./examples/sample.source.PKIX1
make
./x509dump -h
3.Q: Your compiler supplies a der_encode() procedure. How do I encode BER?
3.A:
The DER (and CER) are stricter subsets of a more generic BER encoding
method. If you encode data with DER or CER, all BER-conformant decoders
will easily understand that. Hence, to encode data in the BER format,
simply use the DER encoder, der_encode().
See also: ISO/IEC 8825-1 / X.690:
"ASN.1 encoding rules: Specification of
Basic Encoding Rules (BER),
Canonical Encoding Rules (CER) and
Distinguished Encoding Rules (DER)"
--
Lev Walkin
vlm@lionet.info
......@@ -2,13 +2,28 @@ QUICK START INSTALLATION
========================
./configure # Configure the build infrastructure for your platform
make # Build the libraries and the compiler
make check # Ensure that the code is still behaving well
# after compiling on your platform
# PLEASE CONTACT ME IF THIS FAILS ON YOUR PLATFORM!
make install # Install the compiler into standard location
man asn1c # Display the asn1c manual page
QUICK USAGE GUIDE
=================
For usage guide and more information please refer to README file.
For usage guide and more information please refer to the README file.
In case of any difficulties with installing the compiler, consider using
the Online ASN.1 Compiler at
http://lionet.info/asn1c
--
Lev Walkin
vlm@lionet.info
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = \
libasn1parser libasn1fix \
libasn1print libasn1compiler \
skeletons examples tests \
doc asn1c
EXTRA_DIST = BUGS MANIFEST
docsdir = $(datadir)/doc/asn1c
docs_DATA = README FAQ COPYING ChangeLog BUGS TODO
EXTRA_DIST = asn1c.spec.in FAQ BUGS MANIFEST
CLEANFILES = asn1c.spec
This diff is collapsed.
WHAT TO READ?
=============
For quick installation tips read INSTALL.
If you haven't installed the asn1c yet, read the INSTALL file for
a short installation guide.
For the list of asn1c command line options, see `asn1c -h` or `man asn1c`.
For more complete documentation on this compiler and on using the
results of compilation please look into ./doc directory.
results of compilation phase, please look into asn1c-quick.pdf and
asn1c-usage.{pdf,html}.
If you are building the compiler from the sources, these documents reside
in the ./doc directory, otherwise they lie nearby the README file you're
reading right now.
Please also read the FAQ file.
An excellent book on ASN.1 is written by Olivier Dubuisson:
"ASN.1 Communication between heterogeneous systems", ISBN:0-12-6333361-0.
QUICK START
===========
QUICK START (also check out asn1c-quick.pdf)
============================================
After building [and installing] the compiler (see INSTALL), you may use
the asn1c command to compile the ASN.1 specification:
asn1c <spec.asn1>
asn1c <module.asn1> # Compile module
If several specifications contain interdependencies, all of them must be
specified:
asn1c <spec1.asn1> <spec2.asn1> ...
asn1c <module1.asn1> <module2.asn1> ... # Compile interdependent modules
The ./examples directory contains several ASN.1 modules and a script to
extract ASN.1 modules from RFC documents. To compile X.509 PKI module:
If you are building the asn1c from the sources, the ./examples directory
contains several ASN.1 modules and a script to extract the ASN.1 modules
from RFC documents. Refer to the README file in that directory.
To compile the X.509 PKI module:
./asn1c/asn1c -P ./examples/*PKIX*93*.asn1
./asn1c/asn1c -P ./examples/rfc3280-*.asn1 # Compile-n-print
In this example, -P option is used to instruct the compiler to print the
compiled text on the standard output instead of creating multiple .c
and .h files for every ASN.1 type found inside the specified files.
This is useful for debugging and tests automation.
and .h files for every ASN.1 type found inside the specified ASN.1 modules.
This is useful for debugging and test automation.
The compiler -E and -EF options are used for testing the parser and
the semantic fixer, respectively. These options will instruct the compiler
......@@ -40,7 +50,7 @@ to dump out the parsed (and fixed) ASN.1 specification as it was
whether a particular syntactic construction is properly supported
by the compiler.
asn1c -EF <spec-to-test.asn1>
asn1c -EF <module-to-test.asn1> # Check semantic validity
MODEL OF OPERATION
......@@ -49,10 +59,10 @@ MODEL OF OPERATION
The asn1c compiler works by processing the ASN.1 module specification
in several stages:
1. In the first stage, the ASN.1 file is parsed.
(Parsing produces an ASN.1 syntax tree for the subsequent levels.)
(Parsing produces an ASN.1 syntax tree for the subsequent levels)
2. In the second stage, the syntax tree is "fixed".
(Fixing is done by checking the tree for semantic errors
and by transforming the tree into the canonical representation.)
(Fixing is a process of checking the tree for semantic errors,
accompanied by the tree transformation into the canonical form)
3. In the third stage, the syntax tree is compiled into the target language.
There are several command-line options reserved for printing the results
......
MAJOR:
1. MAJOR:
1. Support for PER encoding. Requires advanced subtype constraints support (#1)
1.1 Support for Information Object Classes.
Status: Support for parsing IOCs is mostly present.
Support for slicing the IOCs to produce "views"
is not yet designed.
2. Support for Information Object Classes.
Status: support for parsing IOCs is mostly present. Support for slicing
the IOCs to produce "views" is not yet designed.
3. Support for XER encoding.
2. MEDIUM:
2.1 Support for EXTERNAL, EMBEDDED-PDV and CHARACTER STRING types.
Requires something from 1.2 (Information Object Classes).
This diff is collapsed.
#
# $Id$
#
Name: @PACKAGE@
Version: @VERSION@
Release: 2
Copyright: Lev Walkin <vlm@lionet.info>
Source: %{name}-%{version}.tar.gz
Url: http://asn1c.sourceforge.net/
BuildRoot: /var/tmp/%{name}-root
Group: Development/Languages
Summary: The ASN.1 to C compiler
%description
The asn1c compiler turns ASN.1 specifications into C language
source files containing the BER/CER/DER/PER/XER encoders and decoders
for the given abstract notation.
%prep
%setup -q
%build
./configure
%{_make} DESTDIR=$RPM_BUILD_ROOT
%install
rm -rf $RPM_BUILD_ROOT
%{__make} install-exec DESTDIR=$RPM_BUILD_ROOT
(cd skeletons && %{__make} install-data DESTDIR=$RPM_BUILD_ROOT)
(cd asn1c && %{__make} install-man DESTDIR=$RPM_BUILD_ROOT)
%clean
rm -rf $RPM_BUILD_ROOT
%files
%doc README FAQ COPYING ChangeLog BUGS TODO
%doc doc/asn1c-usage.pdf doc/asn1c-usage.html
%attr(755,root,root) %{_bindir}
%attr(644,root,root) %{_datadir}/asn1c
%{_mandir}/man1
%changelog
* Sun Sep 18 2006 Lev Walkin <vlm@lionet.info>
- Added PER support into description
* Sun Sep 26 2004 Lev Walkin <vlm@lionet.info>
- All manuals are now getting installed, including new ones: unber.1 and enber.1
* Tue Sep 18 2004 Lev Walkin <vlm@lionet.info>
- First version of asn1c.spec
......@@ -10,20 +10,18 @@ AM_CPPFLAGS = \
-I${top_srcdir}/skeletons \
-DDATADIR=\"$(pkgdatadir)\"
LDADD = \
asn1c_LDADD = \
$(top_builddir)/libasn1parser/libasn1parser.la \
$(top_builddir)/libasn1print/libasn1print.la \
$(top_builddir)/libasn1fix/libasn1fix.la \
$(top_builddir)/libasn1compiler/libasn1compiler.la
asn1c_SOURCES = asn1c.c \
tlv_decoder.c tlv_decoder.h
bin_PROGRAMS = asn1c unber enber
bin_PROGRAMS = asn1c
noinst_HEADERS = sys-common.h
dist_man1_MANS = asn1c.1
dist_man1_MANS = asn1c.1 unber.1 enber.1
check_SCRIPTS = check-parsing.sh
TESTS = check-parsing.sh
EXTRA_DIST = check-parsing.sh
CLEANFILES = .check-parsing.*.tmp
dist_check_SCRIPTS = check-xxber.sh check-parsing.sh
TESTS = $(dist_check_SCRIPTS)
CLEANFILES = .check-xxber.*.tmp .check-parsing.*.tmp
This diff is collapsed.
The ASN.1 Compiler
asn1c - The ASN.1 Compiler
unber - The ASN.1 BER Decoder
enber - Reverse unber(1) output back into BER
.de Id
..
.Id $Id"
.TH ASN1C 1 "\*(Dt" "ASN.1 Compiler" "ASN.1 Compiler"
.SH NAME
asn1c \- ASN.1 Compiler
.ND ASN.1 compiler
.SH SYNOPSIS
.B asn1c
.RI "[ " option " | " filename " ].\|.\|."
asn1c [\fB\-E\fR [\fB-F\fR] | \fB\-P\fR | \fB\-R\fR]
[\fB\-S\fR\fIdir\fR] [\fB-X\fR]
[\fB\-W\fR\fIdebug-\fR...] [\fB\-f\fR\fIoption\fR] [\fB\-gen-\fR\fIoption\fR] [\fB\-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}\fR]
[\fB\-print-\fR\fIoption\fR]
\fIinfile\fR...
.SH DESCRIPTION
asn1c is a tool to compile the ASN.1 specifications into C language structures
and accompanying routines to perform data encoding and decoding.
asn1c compiles ASN.1 specifications into a set of
target language (C/C++) encoders and decoders for BER, DER, PER, XER
and other encoding rules.
.SH OPTIONS
.TP
.B Overall Options
\-E
\-F
\-L
\-P
\-R
.RI "\-S " directory
.RI "\-t " data-string
\fIOverall Options\fR
\fB\-E \-F \-P \-R\fR
.BI "\-S " directory
\fB\-X
.TP
.B Language Options
\fIWarning Options\fR
.br
\-ftypes88
\-fnative-integers
\-fno-c99
\-funnamed-unions
\fB\-Werror \-Wdebug-lexer \-Wdebug-fixer \-Wdebug-compiler\fR
.TP
.B Output Options
\fILanguage Options\fR
.br
\-print-constraints
\fB\-fbless-SIZE \-fcompound-names \-findirect-choice
.BI "\-fknown-extern-type="<name>
\fB\-fno-constraints \-fno-include-deps \-funnamed-unions \-fwide-types
.TP
.B Warning Options
\fICodecs Generation Options\fR
.br
\-Werror
\-Wdebug-lexer
\-Wdebug-fixer
\-Wdebug-compiler
.B \-gen-PER \-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}
.TP
\fIOutput Options\fR
.br
.B \-print-constraints \-print-lines
.SH OVERALL OPTIONS
.TP
.B \-E
Stop after the parsing stage. The output is a reconstructed ASN.1
specification code, which is sent to the standard output.
Stop after the parsing stage and print the reconstructed ASN.1
specification code to the standard output.
.TP
.B \-F
Used together with \c
......@@ -52,11 +48,6 @@ Used together with \c
tree fixing stage and dump the reconstructed ASN.1 specification
to the standard output.
.TP
.B \-L
Generate "-- #line" comments in
.B -E
output.
.TP
.B \-P
Dump the compiled output to the standard output instead of creating the
target language files on disk.
......@@ -65,31 +56,11 @@ target language files on disk.
Restrict the compiler to generate only the ASN.1 tables,
omitting the usual support code.
.TP
.B \-S directory
\fB\-S\fR \fIdirectory\fR
Use the specified directory with ASN.1 skeleton files.
.TP
.B \-t data-string
Interpret the data-string as a sequence of hexadecimal values representing
the start of BER TLV encoding. Print the human readable explanation.
.SH LANGUAGE OPTIONS
.TP
.B \-ftypes88
Use only ASN.1:1988 embedded types.
.TP
.B \-fnative-integers
Use native machine's integer types whenever possible,
instead of the complex ASN.1 INTEGER and ENUMERATED types.
.TP
.B \-fno-c99
Disable use of certain C99 extensions, like designated initializers.
.TP
.B \-funnamed-unions
Enable unnamed unions in structures definitions.
.SH OUTPUT OPTIONS
.TP
.B \-print-constraints
When -EF are also specified, this option forces the compiler to explain
its internal understanding of subtype constraints.
.B \-X
Generate an XML DTD schema for the specified ASN.1 files.
.SH WARNING OPTIONS
.TP
.B \-Werror
......@@ -103,5 +74,65 @@ Enable ASN.1 syntax tree fixer debugging during the fixing stage.
.TP
.B \-Wdebug-compiler
Enable debugging during the actual compile time.
.SH LANGUAGE OPTIONS
.TP
.B \-fbless-SIZE
Allow SIZE() constraint for INTEGER, ENUMERATED, and other types for which this
constraint is normally prohibited by the standard. This is a violation of
ASN.1 standard, and the compiler may fail to produce a meaningful code.
.TP
.B \-fcompound-names
Using this option prevents name collisions in the target source code
by using complex names for target language structures. (Name collisions
may occur if the ASN.1 module reuses the same identifiers in multiple
contexts).
.TP
.B \-findirect-choice
When generating code for a CHOICE type, compile the CHOICE members as indirect
pointers instead of declaring them inline. Consider using this option
together with
.B \-fno-include-deps
to prevent circular references.
.TP
.BI "\-fknown-extern-type="<name>
Pretend the specified type is known. The compiler will assume the target
language source files for the given type have been provided manually.
.TP
.B \-fno-constraints
Do not generate ASN.1 subtype constraint checking code. This may make a shorter executable.
.TP
.B \-fno-include-deps
Do not generate courtesy #include lines for non-critical type dependencies.
Helps prevent namespace collisions.
.TP
.B \-funnamed-unions
Enable unnamed unions in the definitions of target language's structures.
.TP
.B \-fwide-types
Use the unbounded size data types (INTEGER_t, ENUMERATED_t, REAL_t) by default,
instead of the native machine's data types (long, double).
.SH CODECS GENERATION OPTIONS
.TP
.B \-gen-PER
Generate Packed Encoding Rules (PER) support code.
.TP
.B \-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}
Create a PDU table for specified types, or discover Protocol Data Units
automatically. In case of -pdu=\fBall\fR, all ASN.1 types defined in
all modules will form a PDU table. In case of -pdu=\fBauto\fR, all types
not referenced by any other type will form a PDU table.
If \fIType\fR is an ASN.1 type identifier, it is added to a PDU table.
The last form may be specified multiple times to add any number of PDUs.
.SH OUTPUT OPTIONS
.TP
.B \-print-constraints
When -EF are also specified, this option forces the compiler to explain
its internal understanding of subtype constraints.
.TP
.B \-print-lines
Generate "-- #line" comments in \fB-E\fR output.
.SH SEE ALSO
.TP
\&\fIunber\fR\|(1), \&\fIenber\fR\|(1)
.SH AUTHORS
Lev Walkin <vlm@lionet.info>
/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2013
* Lev Walkin <vlm@lionet.info>. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
/*
* This is the program that connects the libasn1* libraries together.
* It uses them in turn to parse, fix and then compile or print the ASN.1 tree.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h> /* for stat(2) */
#include <unistd.h>
#include <sysexits.h> /* for EX_USAGE */
#include <assert.h>
#include <errno.h>
#include "sys-common.h"
#undef COPYRIGHT
#define COPYRIGHT \
"Copyright (c) 2003, 2004, 2005, 2006 Lev Walkin <vlm@lionet.info>\n"
#include <asn1parser.h> /* Parse the ASN.1 file and build a tree */
#include <asn1fix.h> /* Fix the ASN.1 tree */
......@@ -19,15 +42,21 @@
#include <asn1c_compat.h> /* Portable basename(3) and dirname(3) */
#include "tlv_decoder.h" /* -t: decode TL[V?] string */
#ifdef _WIN32
#include <io.h>
#include <direct.h>
#else
#include <dirent.h>
#endif
static void usage(char *av0); /* Print the Usage screen and exit(EX_USAGE) */
static void usage(const char *av0); /* Print the Usage screen and exit */
static int importStandardModules(asn1p_t *asn, const char *skeletons_dir);
int
main(int ac, char **av) {
enum asn1p_flags asn1_parser_flags = A1P_NOFLAGS;
enum asn1f_flags asn1_fixer_flags = A1F_NOFLAGS;
enum asn1c_flags asn1_compiler_flags= A1C_NOFLAGS;
enum asn1c_flags asn1_compiler_flags= A1C_NO_C99;
enum asn1print_flags asn1_printer_flags = APF_NOFLAGS;
int print_arg__print_out = 0; /* Don't compile, just print parsed */
int print_arg__fix_n_print = 0; /* Fix and print */
......@@ -41,7 +70,7 @@ main(int ac, char **av) {
/*
* Process command-line options.
*/
while((ch = getopt(ac, av, "EFf:LPp:RS:t:W:")) != -1)
while((ch = getopt(ac, av, "EFf:g:hLPp:RS:vW:X")) != -1)
switch(ch) {
case 'E':
print_arg__print_out = 1;
......@@ -50,34 +79,81 @@ main(int ac, char **av) {
print_arg__fix_n_print = 1;
break;
case 'f':
if(strcmp(optarg, "types88") == 0) {
asn1_parser_flags |= A1P_TYPES_RESTRICT_TO_1988;
} else if(strcmp(optarg, "constr90") == 0) {
asn1_parser_flags |= A1P_CONSTRUCTS_RESTRICT_TO_1990;
} else if(strcmp(optarg, "native-integers") == 0) {
asn1_compiler_flags |= A1C_USE_NATIVE_INTEGERS;
} else if(strcmp(optarg, "no-c99") == 0) {
asn1_compiler_flags |= A1C_NO_C99;
} else if(strcmp(optarg, "unnamed-unions") == 0) {
asn1_compiler_flags |= A1C_UNNAMED_UNIONS;
if(strcmp(optarg, "all-defs-global") == 0) {
asn1_compiler_flags |= A1C_ALL_DEFS_GLOBAL;
} else if(strcmp(optarg, "bless-SIZE") == 0) {
asn1_fixer_flags |= A1F_EXTENDED_SizeConstraint;
} else if(strcmp(optarg, "compound-names") == 0) {
asn1_compiler_flags |= A1C_COMPOUND_NAMES;
} else if(strcmp(optarg, "indirect-choice") == 0) {
asn1_compiler_flags |= A1C_INDIRECT_CHOICE;
} else if(strncmp(optarg, "known-extern-type=", 18) == 0) {
char *known_type = optarg + 18;
ret = asn1f_make_known_external_type(known_type);
assert(ret == 0 || errno == EEXIST);
} else if(strcmp(optarg, "native-types") == 0) {
fprintf(stderr, "-f%s: Deprecated option\n", optarg);
asn1_compiler_flags &= ~A1C_USE_WIDE_TYPES;
} else if(strcmp(optarg, "wide-types") == 0) {
asn1_compiler_flags |= A1C_USE_WIDE_TYPES;
} else if(strcmp(optarg, "line-refs") == 0) {
asn1_compiler_flags |= A1C_LINE_REFS;
} else if(strcmp(optarg, "no-constraints") == 0) {
asn1_compiler_flags |= A1C_NO_CONSTRAINTS;
} else if(strcmp(optarg, "no-include-deps") == 0) {
asn1_compiler_flags |= A1C_NO_INCLUDE_DEPS;
} else if(strcmp(optarg, "includes-quoted") == 0) {
asn1_compiler_flags |= A1C_INCLUDES_QUOTED;
} else if(strcmp(optarg, "unnamed-unions") == 0) {
asn1_compiler_flags |= A1C_UNNAMED_UNIONS;
} else if(strcmp(optarg, "skeletons-copy") == 0) {
fprintf(stderr, "-f%s: Deprecated option\n", optarg);
asn1_compiler_flags &= ~A1C_LINK_SKELETONS;
} else if(strcmp(optarg, "link-skeletons") == 0) {
asn1_compiler_flags |= A1C_LINK_SKELETONS;
} else if(strcmp(optarg, "have_native64") == 0) {
asn1_compiler_flags |= A1C_HAVE_NATIVE_64;
} else {
fprintf(stderr, "-f%s: Invalid argument\n", optarg);
exit(EX_USAGE);
}
break;
case 'L':
asn1_printer_flags |= APF_LINE_COMMENTS;
case 'g':
if(strcmp(optarg, "en-PER") == 0) {
asn1_compiler_flags |= A1C_GEN_PER;
} else {
fprintf(stderr, "-g%s: Invalid argument\n", optarg);
exit(EX_USAGE);
}
break;
case 'h':
usage(av[0]);
case 'P':
asn1_compiler_flags |= A1C_PRINT_COMPILED;
asn1_compiler_flags &= ~A1C_NO_C99;
break;
case 'p':
if(strcmp(optarg, "rint-constraints") == 0) {
asn1_printer_flags |= APF_DEBUG_CONSTRAINTS;
if(strncmp(optarg, "du=", 3) == 0) {
char *pduname = optarg + 3;
if(strcmp(pduname, "all") == 0) {
asn1_compiler_flags |= A1C_PDU_ALL;
} else if(strcmp(pduname, "auto") == 0) {
asn1_compiler_flags |= A1C_PDU_AUTO;
} else if(pduname[0] >= 'A' && pduname[0] <= 'Z') {
asn1c__add_pdu_type(pduname);
asn1_compiler_flags |= A1C_PDU_TYPE;
} else {
fprintf(stderr, "-pdu=%s"
": expected -pdu={all|auto|Type}\n",
pduname);
exit(EX_USAGE);
}
} else if(strcmp(optarg, "rint-class-matrix") == 0) {
asn1_printer_flags |= APF_PRINT_CLASS_MATRIX;
} else if(strcmp(optarg, "rint-constraints") == 0) {
asn1_printer_flags |= APF_PRINT_CONSTRAINTS;
} else if(strcmp(optarg, "rint-lines") == 0) {
asn1_printer_flags |= APF_LINE_COMMENTS;
} else {
fprintf(stderr, "-p%s: Invalid argument\n", optarg);
exit(EX_USAGE);
......@@ -89,10 +165,10 @@ main(int ac, char **av) {
case 'S':
skeletons_dir = optarg;
break;
case 't':
if(decode_tlv_from_string(optarg))
exit(EX_DATAERR);
case 'v':
fprintf(stderr, "ASN.1 Compiler, v" VERSION "\n" COPYRIGHT);
exit(0);
break;
case 'W':
if(strcmp(optarg, "error") == 0) {
warnings_as_errors = 1;
......@@ -111,6 +187,11 @@ main(int ac, char **av) {
exit(EX_USAGE);
}
break;
case 'X':
print_arg__print_out = 1; /* Implicit -E */
print_arg__fix_n_print = 1; /* Implicit -F */
asn1_printer_flags |= APF_PRINT_XML_DTD;
break;
default:
usage(av[0]);
}
......@@ -125,8 +206,7 @@ main(int ac, char **av) {
}
if(asn1_printer_flags) {
fprintf(stderr, "Error: "
"-L and -print-constraints "
"require -E\n");
"-print-... arguments require -E\n");
exit(EX_USAGE);
}
}
......@@ -138,11 +218,46 @@ main(int ac, char **av) {
ac -= optind;
av += optind;
} else {
fprintf(stderr, "%s: No input files specified\n",
a1c_basename(av[0]));
char *bin_name = a1c_basename(av[0]);
fprintf(stderr, "%s: No input files specified. "
"Try '%s -h' for more information\n",
bin_name, bin_name);
exit(1);
}
/*
* Make sure the skeleton directory is out there.
*/
if(skeletons_dir == NULL) {
struct stat sb;
skeletons_dir = DATADIR;
if((av[-optind][0] == '.' || av[-optind][1] == '/')
&& stat(skeletons_dir, &sb)) {
/*
* The default skeletons directory does not exist,
* compute it from my file name:
* ./asn1c/asn1c -> ./skeletons
*/
char *p;
size_t len;
p = a1c_dirname(av[-optind]);
len = strlen(p) + sizeof("/../skeletons");
skeletons_dir = malloc(len);
assert(skeletons_dir);
snprintf(skeletons_dir, len, "%s/../skeletons", p);
if(stat(skeletons_dir, &sb)) {
fprintf(stderr,
"WARNING: skeletons are neither in "
"\"%s\" nor in \"%s\"!\n",
DATADIR, skeletons_dir);
if(warnings_as_errors)
exit(EX_OSFILE);
}
}
}
/*
* Iterate over input files and parse each.
* All syntax trees from all files will be bundled together.
......@@ -163,13 +278,16 @@ main(int ac, char **av) {
asn1p_module_t *mod;
while((mod = TQ_REMOVE(&(new_asn->modules), mod_next)))
TQ_ADD(&(asn->modules), mod, mod_next);
asn1p_free(new_asn);
asn1p_delete(new_asn);
} else {
asn = new_asn;
}
}
/* These are mostly notes for the human readers */
assert(asn);
assert(skeletons_dir);
/*
* Dump the parsed ASN.1 tree if -E specified and -F is NOT given.
*/
......@@ -179,6 +297,13 @@ main(int ac, char **av) {
return 0;
}
/*
* Read in the files from skeletons/standard-modules
*/
if(importStandardModules(asn, skeletons_dir)) {
if(warnings_as_errors)
exit(EX_DATAERR);
}
/*
* Process the ASN.1 specification: perform semantic checks,
......@@ -207,84 +332,158 @@ main(int ac, char **av) {
}
/*
* Make sure the skeleton directory is out there.
* Compile the ASN.1 tree into a set of source files
* of another language.
*/
if(skeletons_dir == NULL) {
struct stat sb;
skeletons_dir = DATADIR;
if((av[-optind][0] == '.' || av[-optind][1] == '/')
&& stat(skeletons_dir, &sb)) {
/*
* The default skeletons directory does not exist,
* compute it from my file name:
* ./asn1c/asn1c -> ./skeletons
*/
char *p;
int len;
if(asn1_compile(asn, skeletons_dir, asn1_compiler_flags,
ac + optind, optind - 1, av - optind)) {
exit(EX_SOFTWARE);
}
p = a1c_dirname(av[-optind]);
return 0;
}
len = strlen(p) + sizeof("/../skeletons");
skeletons_dir = alloca(len);
snprintf(skeletons_dir, len, "%s/../skeletons", p);
if(stat(skeletons_dir, &sb)) {
fprintf(stderr,
"WARNING: skeletons are neither in "
"\"%s\" nor in \"%s\"!\n",
DATADIR, skeletons_dir);
if(warnings_as_errors)
exit(EX_SOFTWARE);
}
}
}
/*
* Parse and import *.asn1 from skeletons/standard-modules
*/
static int
importStandardModules(asn1p_t *asn, const char *skeletons_dir) {
asn1p_t *new_asn;
asn1p_module_t *mod;
const char *filename;
char *fullname;
char *target_dir;
int target_dir_len;
int len;
#ifdef _WIN32
intptr_t dir;
struct _finddata_t c_file;
char *pattern;
#else
struct dirent *dp;
DIR *dir;
#endif
int ret = 0;
/* Notes for the human reader */
assert(asn);
assert(skeletons_dir);
/*
* Compile the ASN.1 tree into a set of source files
* of another language.
* Figure out the standard-modules directory.
*/
if(asn1_compile(asn, skeletons_dir, asn1_compiler_flags)) {
exit(EX_SOFTWARE);
target_dir_len = strlen(skeletons_dir)
+ sizeof("/standard-modules") - 1;
target_dir = malloc(target_dir_len + 1);
assert(target_dir);
snprintf(target_dir, target_dir_len + 1, "%s/standard-modules",
skeletons_dir);
#ifdef _WIN32
len = target_dir_len + sizeof("/*.asn1");
pattern = malloc(len);
assert(pattern);
snprintf(pattern, len, "%s/*.asn1", target_dir);
dir = _findfirst(pattern, &c_file);
if(dir == -1L) {
#else
dir = opendir(target_dir);
if(!dir) {
#endif
fprintf(stderr,
"WARNING: Cannot find standard modules in %s\n",
target_dir);
return -1;
}
return 0;
#ifdef _WIN32
do {
filename = c_file.name;
#else
while((dp = readdir(dir))) {
filename = dp->d_name;
#endif
len = strlen(filename);
if(len <= 5 || strcmp(filename + len - 5, ".asn1"))
continue;
len = target_dir_len + 1 + len + 1;
fullname = malloc(len);
if(!fullname) continue; /* Just skip it, no big deal */
snprintf(fullname, len, "%s/%s", target_dir, filename);
filename = fullname;
new_asn = asn1p_parse_file(filename, A1P_NOFLAGS);
if(new_asn == NULL) {
fprintf(stderr, "WARNING: Cannot parse standard module \"%s\"\n", filename);
ret = -1;
continue;
}
/* Import these modules and mark them as "standard" */
while((mod = TQ_REMOVE(&(new_asn->modules), mod_next))) {
mod->_tags |= MT_STANDARD_MODULE;
TQ_ADD(&(asn->modules), mod, mod_next);
}
asn1p_delete(new_asn);
#ifdef _WIN32
} while(_findnext(dir, &c_file) == 0);
_findclose(dir);
#else
free(fullname);
} /* while(readdir()) */
closedir(dir);
#endif
return ret;
}
/*
* Print the usage screen and exit(EX_USAGE).
*/
static void
usage(char *av0) {
usage(const char *av0) {
fprintf(stderr,
"ASN.1 Compiler, v" VERSION "\n"
"Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>\n"
"Usage: %s [options] ...\n"
"Where [options] are:\n"
"\t-E\tRun only the ASN.1 parser and print out the tree\n"
"\t-F\tDuring -E operation, also perform tree fixing\n"
"\t-L\tGenerate \"-- #line\" comments in -E output\n"
"\n"
"\t-P \tConcatenate and print the compiled text\n"
"\t-R \tRestrict output (tables only, no support code)\n"
"\t-S <dir>\tDirectory with support (skeleton?) files\n"
"\t \t(Default is \"%s\")\n"
"\n"
"\t-t <data>\tDecode the given tag[/length] sequence\n"
"\n"
"\t-ftypes88\tUse only ASN.1:1988 embedded types\n"
/*
"\t-fconstr90\tUse only ASN.1:1990 constructs (not available)\n"
*/
"\t-fknown-extern-type=<name>\tPretend this type is known\n"
"\t-fnative-integers\tUse int instead of INTEGER_t whenever possible\n"
"\t-fno-c99\tDisable C99 extensions\n"
"\t-funnamed-unions\tEnable unnamed unions in structures\n"
"\n"
"\t-print-constraints\tExplain subtype constraints (debug)\n"
"\n"
"\t-Werror \tTreat warnings as errors; abort if any warning\n"
"\t-Wdebug-lexer\tEnable verbose debugging output from lexer\n"
"\t-Wdebug-fixer\tDebug ASN.1 semantics processor\n"
"\t-Wdebug-compiler\tDebug ASN.1 compiler\n"
"ASN.1 Compiler, v" VERSION "\n" COPYRIGHT
"Usage: %s [options] file ...\n"
"Options:\n"
" -E Run only the ASN.1 parser and print out the tree\n"
" -F During -E operation, also perform tree fixing\n"
"\n"
" -P Concatenate and print the compiled text\n"
" -R Restrict output (tables only, no support code)\n"
" -S <dir> Directory with support (skeleton?) files\n"
" (Default is \"%s\")\n"
" -X Generate and print the XML DTD\n"
"\n"
" -Werror Treat warnings as errors; abort if any warning\n"
" -Wdebug-lexer Enable verbose debugging output from lexer\n"
" -Wdebug-fixer --//-- semantics processor\n"
" -Wdebug-compiler --//-- compiler\n"
"\n"
" -fbless-SIZE Allow SIZE() constraint for INTEGER etc (non-std.)\n"
" -fcompound-names Disambiguate C's struct NAME's inside top-level types\n"
" -findirect-choice Compile members of CHOICE as indirect pointers\n"
" -fincludes-quoted Generate #includes in \"double\" instead of <angle> quotes\n"
" -fknown-extern-type=<name> Pretend the specified type is known\n"
" -fline-refs Include ASN.1 module's line numbers in comments\n"
" -fno-constraints Do not generate constraint checking code\n"
" -fno-include-deps Do not generate courtesy #includes for dependencies\n"
" -funnamed-unions Enable unnamed unions in structures\n"
" -fwide-types Use INTEGER_t instead of \"long\" by default, etc.\n"
" -fhave_native64 Use int64_t/uint64_t for target platform\n"
"\n"
" -gen-PER Generate PER support code\n"
" -pdu={all|auto|Type} Generate PDU table (discover PDUs automatically)\n"
"\n"
" -print-class-matrix Print out the collected object class matrix (debug)\n"
" -print-constraints Explain subtype constraints (debug)\n"
" -print-lines Generate \"-- #line\" comments in -E output\n"
,
a1c_basename(av0), DATADIR
);
......
......@@ -2,17 +2,25 @@
tmpfile=".check-parsing.$$.tmp"
# Test diff(1) capabilities
diff -a . . 2>/dev/null && diffArgs="-a" # Assume text files
diff -u . . 2>/dev/null && diffArgs="$diffArgs -u" # Unified diff output
ec=0
for ref in ../tests/*.asn1.-*; do
src=`echo "$ref" | sed -e 's/\.-[-a-zA-Z0-9=]*$//'`
flags=`echo "$ref" | sed -e 's/.*\.-//'`
echo "Checking $src against $ref"
./asn1c "-$flags" "$src" > "$tmpfile" || ec=$?
./asn1c -S../skeletons "-$flags" "$src" > "$tmpfile" || ec=$?
if [ $? = 0 ]; then
diff -a -u "$ref" "$tmpfile" || ec=$?
diff $diffArgs "$ref" "$tmpfile" || ec=$?
fi
if [ "$1" != "regenerate" ]; then
rm -f "$tmpfile"
else
mv "$tmpfile" "$ref"
fi
rm -f "$tmpfile"
done
exit $ec
#!/bin/sh
ORIG="./.check-xxber.orig.$$.tmp"
TEST="./.check-xxber.test.$$.tmp"
# Test diff(1) capabilities
diff -a . . 2>/dev/null && diffArgs="-a" # Assume text files
diff -u . . 2>/dev/null && diffArgs="$diffArgs -u" # Unified diff output
cat<<EOM > $ORIG
<I O="0" T="[UNIVERSAL 16]" TL="2" V="Indefinite" A="SEQUENCE">
<P O="2" T="[UNIVERSAL 19]" TL="2" V="2" A="PrintableString">&#x55;&#x53;</P>
<C O="6" T="[UNIVERSAL 16]" TL="2" V="22" A="SEQUENCE">
<P O="8" T="[UNIVERSAL 2]" TL="2" V="4" A="INTEGER">&#x31;&#xa6;&#x20;&#x47;</P>
<C O="14" T="[UNIVERSAL 16]" TL="2" V="6" A="SEQUENCE">
<P O="16" T="[UNIVERSAL 2]" TL="2" V="4" A="INTEGER">&#x31;&#xa6;&#x20;&#x47;</P>
</C O="22" T="[UNIVERSAL 16]" A="SEQUENCE" L="8">
<C O="22" T="[UNIVERSAL 16]" TL="2" V="6" A="SEQUENCE">
<P O="24" T="[UNIVERSAL 2]" TL="2" V="4" A="INTEGER">&#x31;&#xa6;&#x20;&#x47;</P>
</C O="30" T="[UNIVERSAL 16]" A="SEQUENCE" L="8">
</C O="30" T="[UNIVERSAL 16]" A="SEQUENCE" L="24">
<I O="30" T="[UNIVERSAL 16]" TL="2" V="Indefinite" A="SEQUENCE">
</I O="32" T="[UNIVERSAL 0]" TL="2" L="4">
EOM
./enber $ORIG | ./unber -p -i 0 - > $TEST 2>&1
diff $diffArgs $ORIG $TEST >/dev/null 2>&1
diffExitCode=$?
if [ "$diffExitCode" = "0" ]; then
echo "FAILED: $0: expected failure, got success"
exit 42;
fi
# Append necessary terminator
echo '</I O="34" T="[UNIVERSAL 0]" TL="2" L="36">' >> $ORIG
# Try trancoding again
./enber $ORIG | ./unber -p -i 0 - > $TEST 2>&1
diff $diffArgs $ORIG $TEST
diffExitCode=$?
rm -f $ORIG $TEST
exit $diffExitCode