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 (722)
*.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
/*-
* Copyright (c) 2003, 2004, 2005 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
......
???:
* 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.
......@@ -8,12 +147,13 @@
* 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)
(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)
(Test case 74) (Severity: low; Security impact: none)
* XMLValueList generation fixed for CHOICE type.
(Severity: medium, Security impact: none)
(Severity: medium; Security impact: none)
* Added the GSM TAP3 decoder into ./examples/sample.source.TAP3
0.9.11: 2005-Mar-04
......@@ -63,10 +203,10 @@
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)
(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)
(Test case 59) (Severity: low; Security impact: low)
Reported by <orlinkata@dir.bg>.
* Implemented der_encode_to_buffer() procedure.
......@@ -87,9 +227,9 @@
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).
(Severity: medium; Security impact: low).
* Fixed CHOICE code spin when indefinite length structures appear
in the extensions (Severity: medium, Security impact: medium).
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.
......@@ -105,11 +245,11 @@
* 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 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)
(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.
......@@ -122,7 +262,7 @@
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)
(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.
......@@ -141,7 +281,7 @@
* Explicit support for ANY type decoding.
* Refactored tags processing code.
* Fixed constraints checking code: non-exploitable buffer overflow.
(Severity: medium, Security impact: low)
(Severity: medium; Security impact: low)
0.9.3: 2004-Sep-07
......@@ -177,7 +317,7 @@
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
......@@ -193,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
......@@ -219,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.
......@@ -237,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
......@@ -262,7 +402,7 @@
* 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.
......@@ -273,7 +413,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.
......@@ -283,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>
......@@ -295,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.
......@@ -391,6 +531,7 @@ SEVERITY.
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
......
Q: How to build a simplest BER (XER) encoder or decoder?
A:
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 see "Examples" section of ./doc/asn1c-usage.pdf
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:
......@@ -11,8 +22,8 @@ A:
./x509dump -h
Q: Your compiler supplies a der_encode() procedure. How do I encode BER?
A:
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,
......
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = \
libasn1parser libasn1fix \
libasn1print libasn1compiler \
......
This diff is collapsed.
......@@ -7,7 +7,8 @@ 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 phase, please look into asn1c-usage.{pdf,html}.
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.
......@@ -17,8 +18,8 @@ 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:
......
1. MAJOR:
1.1 Support for PER encoding. Requires advanced subtype constraints support,
which is already completed. Also see #3.2.
1.2 Support for Information Object Classes.
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. MEDIUM:
2.1 Support for DEFAULT encoding and decoding, at least in INTEGER/ENUMERATED types.
2.2 Support for EXTERNAL, EMBEDDED-PDV and CHARACTER STRING types.
3. MINOR:
3.1 Parsing of CONSTRAINED BY clauses
3.2 Support for ContainedSubtype constraint.
2.1 Support for EXTERNAL, EMBEDDED-PDV and CHARACTER STRING types.
Requires something from 1.2 (Information Object Classes).
This diff is collapsed.
......@@ -4,7 +4,7 @@
Name: @PACKAGE@
Version: @VERSION@
Release: 1
Release: 2
Copyright: Lev Walkin <vlm@lionet.info>
Source: %{name}-%{version}.tar.gz
Url: http://asn1c.sourceforge.net/
......@@ -16,7 +16,7 @@ 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/XER encoders and decoders
source files containing the BER/CER/DER/PER/XER encoders and decoders
for the given abstract notation.
%prep
......@@ -45,6 +45,9 @@ rm -rf $RPM_BUILD_ROOT
%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
......
SUBDIRS = . webcgi tests
SUBDIRS = . tests
AM_CFLAGS = @ADD_CFLAGS@
AM_CPPFLAGS = \
......@@ -22,7 +22,6 @@ noinst_HEADERS = sys-common.h
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.
......@@ -4,12 +4,13 @@ asn1c \- ASN.1 Compiler
.SH SYNOPSIS
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\-p\fR\fIrint-\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 compiles the ASN.1 specifications into the set of
target language (C/C++) encoders and decoders for BER, DER, XER,
and other encoding standards.
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
\fIOverall Options\fR
......@@ -23,7 +24,13 @@ and other encoding standards.
.TP
\fILanguage Options\fR
.br
\fB\-fall-defs-global \-fbless-SIZE \-fnative-types \-fno-constraints \-funnamed-unions \-ftypes88\fR
\fB\-fbless-SIZE \-fcompound-names \-findirect-choice
.BI "\-fknown-extern-type="<name>
\fB\-fno-constraints \-fno-include-deps \-funnamed-unions \-fwide-types
.TP
\fICodecs Generation Options\fR
.br
.B \-gen-PER \-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}
.TP
\fIOutput Options\fR
.br
......@@ -53,7 +60,7 @@ omitting the usual support code.
Use the specified directory with ASN.1 skeleton files.
.TP
.B \-X
Generate the XML DTD schema for the specified ASN.1 files.
Generate an XML DTD schema for the specified ASN.1 files.
.SH WARNING OPTIONS
.TP
.B \-Werror
......@@ -69,33 +76,53 @@ Enable ASN.1 syntax tree fixer debugging during the fixing stage.
Enable debugging during the actual compile time.
.SH LANGUAGE OPTIONS
.TP
.B \-fall-defs-global
Normally the compiler hides the definitions (asn1_DEF_xxx) of the inner
structure elements (members of SEQUENCE, SET and other types). This option
makes all such definitions global.
Enabling this option may pollute the namespace by making lots of asn1_DEF_xxx
structures globally visible, but will allow you to manipulate
(encode and decode) the individual members of any complex ASN.1 structure.
.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
an ASN.1 standard and compiler may fail to produce the meaningful code.
ASN.1 standard, and the compiler may fail to produce a meaningful code.
.TP
.B \-fnative-types
Use the native machine's data types (int, double) whenever possible,
instead of the compound INTEGER_t, ENUMERATED_t and REAL_t types.
.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 \-ftypes88
Pretend to support only ASN.1:1988 embedded types. Certain reserved words,
such as UniversalString and BMPString, become ordinary type references
and may be redefined by the specification.
.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
......
/*-
* Copyright (c) 2003, 2004, 2005
* 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
......@@ -31,6 +31,10 @@
*/
#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 */
#include <asn1print.h> /* Print the ASN.1 tree */
......@@ -38,11 +42,15 @@
#include <asn1c_compat.h> /* Portable basename(3) and dirname(3) */
#undef COPYRIGHT
#define COPYRIGHT \
"Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>\n"
#ifdef _WIN32
#include <io.h>
#include <direct.h>
#else
#include <dirent.h>
#endif
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) {
......@@ -62,7 +70,7 @@ main(int ac, char **av) {
/*
* Process command-line options.
*/
while((ch = getopt(ac, av, "EFf:hLPp:RS:vW:X")) != -1)
while((ch = getopt(ac, av, "EFf:g:hLPp:RS:vW:X")) != -1)
switch(ch) {
case 'E':
print_arg__print_out = 1;
......@@ -77,27 +85,47 @@ main(int ac, char **av) {
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-integers") == 0 /* Legacy */
|| strcmp(optarg, "native-types") == 0) {
asn1_compiler_flags |= A1C_USE_NATIVE_TYPES;
} 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, "types88") == 0) {
asn1_parser_flags |= A1P_TYPES_RESTRICT_TO_1988;
} 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 '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':
......@@ -105,8 +133,25 @@ main(int ac, char **av) {
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 {
......@@ -173,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.
......@@ -198,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.
*/
......@@ -214,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,
......@@ -241,50 +331,113 @@ main(int ac, char **av) {
return 0;
}
/*
* 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 = 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);
}
}
}
/*
* Compile the ASN.1 tree into a set of source files
* of another language.
*/
if(asn1_compile(asn, skeletons_dir, asn1_compiler_flags,
ac + optind, av - optind)) {
ac + optind, optind - 1, av - optind)) {
exit(EX_SOFTWARE);
}
return 0;
}
/*
* 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);
/*
* Figure out the standard-modules directory.
*/
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;
}
#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).
*/
......@@ -310,17 +463,24 @@ usage(const char *av0) {
" -Wdebug-compiler --//-- compiler\n"
"\n"
" -fall-defs-global Don't make the asn1_DEF_'s of structure members \"static\"\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"
" -fknown-extern-type=<name> Pretend this type is known\n"
" -fnative-types Use \"long\" instead of INTEGER_t whenever possible, etc.\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"
" -ftypes88 Pretend to support only ASN.1:1988 embedded types\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"
......
......@@ -2,7 +2,9 @@
tmpfile=".check-parsing.$$.tmp"
diff -a . . 2>/dev/null && diffArgs="-a"
# 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
......@@ -10,9 +12,9 @@ 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 $diffArgs -u "$ref" "$tmpfile" || ec=$?
diff $diffArgs "$ref" "$tmpfile" || ec=$?
fi
if [ "$1" != "regenerate" ]; then
rm -f "$tmpfile"
......
#!/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
......@@ -12,37 +12,35 @@
.SH NAME
enber \- Convert the unber XML output back into BER
.SH SYNOPSIS
enber [\fB-n\fR] [\fB-\fR] \fIinfile\fR...
enber [\fB-n\fR] [\fB-\fR] [\fIinfile\fR...]
.SH DESCRIPTION
enber takes the XML-formatted files produced by \fIunber\fR\|(1) and converts
them back into the BER format.
A single dash represents the standard input.
enber convers the XML-formatted files produced by \fIunber\fR\|(1) back into the BER format.
A single dash denotes the standard input.
.SH OPTIONS
.TP
\fB\-n\fR
Disable input validation. By default, enber performs some basic validity checks
against the XML input. This option disables such checks.
against XML input.
.SH EXAMPLES
Decode the BER sequence and immediately encode it back
Decode a BER sequence and immediately encode it back
.Vb
\& unber \fB-p\fR \fIfilename.ber\fR | enber \fB-\fR > \fIreconstructed.ber\fR
.Ve
.SH FOOTNOTES
This program does not attempt to perform full-fledged XML parsing. It is merely
compatible with \fIunber\fR\|(1)'s output.
In particular, the XML comments are not supported.
The following characters after the initial white space indicate
the start of a comment: "\fB#\fR" (a hash) and "\fB--\fR" (two dashes).
The whole comment line is ignored completely. Empty lines are ignored as well.
In particular, XML style comments are not supported.
A hash "\fB#\fR" or two dashes "\fB--\fR" following a whitespace is treated as a beginning of a comment line, which is ignored completely.
Empty lines are ignored as well.
.P
The following example demostrates the use of comments:
.Vb
\& <C T="[1]" TL="2" V="2">
\& <I T="[1]" TL="2" V="Indefinite">
\& -- </I>
\& # Do not terminate:
\& # the absence of end-of-content octets is intentional!
\& </C>
\& <C O="0" T="[1]" TL="2" V="2">
\& <I O="2" T="[1]" TL="2" V="Indefinite">
\& \fB--\fR </I O="4" T="[UNIVERSAL 0]" L="4">
\& \fB#\fR Do not terminate:
\& \fB#\fR the absence of end-of-content octets is intentional!
\& </C O="6" T="[1]" L="6">
.Ve
.SH SEE ALSO
.TP
......
/*-
* Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Copyright (c) 2004, 2005 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
......@@ -35,7 +35,7 @@
#undef COPYRIGHT
#define COPYRIGHT \
"Copyright (c) 2004 Lev Walkin <vlm@lionet.info>\n"
"Copyright (c) 2004, 2005 Lev Walkin <vlm@lionet.info>\n"
static void usage(const char *av0, int);/* Print the Usage screen and exit */
static int process(const char *fname); /* Perform the BER decoding */
......@@ -58,9 +58,6 @@ main(int ac, char **av) {
break;
case 'v':
usage(av[0], 1);
fprintf(stderr, "Convert unber(1)'s output back into BER, "
"v" VERSION "\n" COPYRIGHT);
exit(0);
break;
case 'h':
default:
......@@ -139,7 +136,7 @@ process(const char *fname) {
if((collector_size - collector_offset) <= len
|| !collector) {
collector_size <<= 1;
collector = realloc(collector, collector_size);
collector = REALLOC(collector, collector_size);
if(!collector) {
perror("realloc()");
exit(EX_OSERR);
......@@ -170,20 +167,22 @@ process_line(const char *fname, char *line, int lineno) {
char buf[32];
char *op; /* '<' */
char *cl; /* '>' */
char *tcl_pos; /* tag class position */
char *tl_pos;
char *v_pos;
char *tcl_pos; /* tag class (T=") position */
char *tl_pos; /* tag length (TL=") position */
char *v_pos; /* value length (V=") position */
int constr;
ber_tlv_tag_t tag_value;
ber_tlv_tag_t tag_class;
ber_tlv_tag_t tlv_tag;
ber_tlv_len_t tlv_len;
ber_tlv_len_t tl_len;
ber_tlv_len_t opt_tl_len; /* optional TL length */
ssize_t ret;
(void)fname;
/* Find a tag opening angle bracket */
/* Skip the whitespace */
for(; *line == ' ' || *line == '\t'; line++);
/* Find a tag opening angle bracket */
op = line;
switch(*op) {
case '<': /* That's what we want! A tag opening */
......@@ -195,7 +194,9 @@ process_line(const char *fname, char *line, int lineno) {
case '#': /* This is a comment */
return 0;
default:
fprintf(stderr, "%s: Missing '<' after whitespace at line %d\n", fname, lineno);
fprintf(stderr,
"%s: Missing '<' after whitespace at line %d\n",
fname, lineno);
exit(EX_DATAERR);
}
......@@ -209,14 +210,16 @@ process_line(const char *fname, char *line, int lineno) {
}
cl = line;
if(*cl != '>') {
fprintf(stderr, "%s: Missing '>'\n", fname);
fprintf(stderr, "%s: Missing '>' at line %d\n", fname, lineno);
exit(EX_DATAERR);
}
/* Ignore closing tags */
if(op[1] == '/') {
if(strchr(cl, '<')) { /* We are not very robust */
fprintf(stderr, "%s: Multiple tags per line\n", fname);
fprintf(stderr,
"%s: Multiple tags per line at line %d\n",
fname, lineno);
exit(EX_DATAERR);
}
/* End-of-content octets */
......@@ -228,40 +231,43 @@ process_line(const char *fname, char *line, int lineno) {
}
switch(op[1]) {
case '!': return 0; /* A comment */
case '?': return 0; /* An XML preamble */
case 'C': constr = 1; break;
case 'P': constr = 0; break;
case 'I': constr = 2; break;
default:
fprintf(stderr,
"%s: Expected \"C\"/\"P\"/\"I\" as the XML tag name (%c)\n",
fname, op[1]);
"%s: Expected \"C\"/\"P\"/\"I\" as the XML tag name (%c) at line %d\n",
fname, op[1], lineno);
exit(EX_DATAERR);
}
*cl = '\0';
if(cl[-1] == 'F') {
fprintf(stderr, "%s: Uses pretty-printing of values. "
"Use -p option to unber\n", fname);
fprintf(stderr,
"%s: Detected pretty-printing of primitive types at line %d. "
"Re-run `unber` with -p option to disable pretty-printing.\n", fname, lineno);
exit(EX_DATAERR);
}
tcl_pos = strstr(op, "T=\"[");
tl_pos = strstr(op, "TL=\"");
v_pos = strstr(op, "V=\"");
if(!tcl_pos || !tl_pos || (!v_pos && constr != 2)) {
if(!tcl_pos || (!v_pos && constr != 2)) {
fprintf(stderr,
"%s: Mandatory attribute %s is not found at line %d\n",
fname, (!tcl_pos)?"T":((!v_pos)?"V":"TL"), lineno);
fname, (!tcl_pos)?"T":"V", lineno);
exit(EX_DATAERR);
}
errno = 0;
tl_len = strtoul(tl_pos + 4, 0, 10);
opt_tl_len = tl_pos ? strtoul(tl_pos + 4, 0, 10) : 0;
if(constr == 2) {
tlv_len = 0;
} else {
tlv_len = strtoul(v_pos + 3, 0, 10);
}
if(errno || tl_len < 2 || tlv_len < 0) {
if(errno || (opt_tl_len && opt_tl_len < 2) || tlv_len < 0) {
fprintf(stderr, "%s: Invalid TL or V value at line %d\n",
fname, lineno);
exit(EX_DATAERR);
......@@ -314,14 +320,14 @@ process_line(const char *fname, char *line, int lineno) {
buf + ret, sizeof(buf) - ret);
assert(ret >= 2 && (size_t)ret < sizeof(buf));
}
if(ret != tl_len) {
if(opt_tl_len && ret != opt_tl_len) {
fprintf(stderr, "%s: Cannot encode TL at line %d "
"in the given number of bytes (%ld!=%ld)\n",
fname, lineno, (long)ret, (long)tl_len);
fname, lineno, (long)ret, (long)opt_tl_len);
exit(EX_DATAERR);
}
if(constr) *buf |= 0x20; /* Enable "constructed" bit */
fwrite(buf, 1, tl_len, stdout);
fwrite(buf, 1, ret, stdout);
if(!constr) {
ber_tlv_len_t len;
......@@ -375,9 +381,9 @@ process_line(const char *fname, char *line, int lineno) {
if(len != tlv_len) {
if(no_validation) fprintf(stderr, "Warning: ");
fprintf(stderr,
"%s: Could not encode value of %d chars "
"at line %d in %d bytes\n",
fname, len, lineno, tlv_len);
"%s: Could not encode value of %ld chars "
"at line %d in %ld bytes\n",
fname, (long)len, lineno, (long)tlv_len);
if(!no_validation) exit(EX_DATAERR);
}
}
......
......@@ -46,9 +46,9 @@
#include <sys/stat.h> /* for stat(2) */
#endif
#ifndef WIN32
#ifndef _WIN32
#include <sysexits.h> /* for EX_USAGE & others */
#else /* WIN32 */
#else /* _WIN32 */
#ifndef EX_USAGE
#define EX_USAGE 64
#endif
......@@ -61,7 +61,10 @@
#ifndef EX_OSERR
#define EX_OSERR 71
#endif
#ifndef EX_OSFILE
#define EX_OSFILE 72
#endif
#define alloca _alloca
#define snprintf _snprintf
#endif /* WIN32 */
#endif /* _WIN32 */