aboutsummaryrefslogtreecommitdiffstats
path: root/asn1c
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2004-06-03 03:38:44 +0000
committerLev Walkin <vlm@lionet.info>2004-06-03 03:38:44 +0000
commitf15320bf6b50a0c02636405561ac8323ae901abd (patch)
tree33461d45122896c6dde35f82f5c7d19b62004a6b /asn1c
parent746cb60bbccf47019563665f4aec4b6c462c4163 (diff)
Initial revision
Diffstat (limited to 'asn1c')
-rw-r--r--asn1c/Makefile.am25
-rw-r--r--asn1c/Makefile.in556
-rw-r--r--asn1c/README1
-rw-r--r--asn1c/asn1c.199
-rw-r--r--asn1c/asn1c.c267
-rwxr-xr-xasn1c/check-parsing.sh18
-rw-r--r--asn1c/tests/Makefile.am10
-rw-r--r--asn1c/tests/Makefile.in284
-rw-r--r--asn1c/tests/README6
-rw-r--r--asn1c/tests/check-22.c141
-rw-r--r--asn1c/tests/check-24.c94
-rw-r--r--asn1c/tests/check-25.c252
-rw-r--r--asn1c/tests/check-30.c116
-rw-r--r--asn1c/tests/check-31.c175
-rw-r--r--asn1c/tests/check-32.c21
-rw-r--r--asn1c/tests/check-33.c21
-rw-r--r--asn1c/tests/check-35.c277
-rw-r--r--asn1c/tests/check-41.c315
-rw-r--r--asn1c/tests/check-43.c24
-rwxr-xr-xasn1c/tests/check-assembly.sh56
20 files changed, 2758 insertions, 0 deletions
diff --git a/asn1c/Makefile.am b/asn1c/Makefile.am
new file mode 100644
index 00000000..2363c189
--- /dev/null
+++ b/asn1c/Makefile.am
@@ -0,0 +1,25 @@
+
+SUBDIRS = . tests
+
+AM_CFLAGS = @ADD_CFLAGS@
+AM_CPPFLAGS = \
+ -I${top_srcdir}/libasn1compiler \
+ -I${top_srcdir}/libasn1parser \
+ -I${top_srcdir}/libasn1print \
+ -I${top_srcdir}/libasn1fix \
+ -DDATADIR=\"${pkgdatadir}\"
+
+LDADD = \
+ ${top_builddir}/libasn1parser/libasn1parser.la \
+ ${top_builddir}/libasn1fix/libasn1fix.la \
+ ${top_builddir}/libasn1print/libasn1print.la \
+ ${top_builddir}/libasn1compiler/libasn1compiler.la
+
+bin_PROGRAMS = asn1c
+
+dist_man1_MANS = asn1c.1
+
+check_SCRIPTS = check-parsing.sh
+TESTS = check-parsing.sh
+EXTRA_DIST = check-parsing.sh
+CLEANFILES = .check-parsing.*.tmp
diff --git a/asn1c/Makefile.in b/asn1c/Makefile.in
new file mode 100644
index 00000000..6b7805bc
--- /dev/null
+++ b/asn1c/Makefile.in
@@ -0,0 +1,556 @@
+# Makefile.in generated automatically by automake 1.5 from Makefile.am.
+
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+# Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = @program_transform_name@
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_alias = @build_alias@
+build_triplet = @build@
+host_alias = @host_alias@
+host_triplet = @host@
+target_alias = @target_alias@
+target_triplet = @target@
+ADD_CFLAGS = @ADD_CFLAGS@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AWK = @AWK@
+CC = @CC@
+CONFIGURE_DEPENDS = @CONFIGURE_DEPENDS@
+CPP = @CPP@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+EXEEXT = @EXEEXT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LEX = @LEX@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+MAINT = @MAINT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PATH = @PATH@
+RANLIB = @RANLIB@
+VERSION = @VERSION@
+YACC = @YACC@
+am__include = @am__include@
+am__quote = @am__quote@
+install_sh = @install_sh@
+
+SUBDIRS = . tests
+
+AM_CFLAGS = @ADD_CFLAGS@
+AM_CPPFLAGS = \
+ -I${top_srcdir}/libasn1compiler \
+ -I${top_srcdir}/libasn1parser \
+ -I${top_srcdir}/libasn1print \
+ -I${top_srcdir}/libasn1fix \
+ -DDATADIR=\"${pkgdatadir}\"
+
+
+LDADD = \
+ ${top_builddir}/libasn1parser/libasn1parser.la \
+ ${top_builddir}/libasn1fix/libasn1fix.la \
+ ${top_builddir}/libasn1print/libasn1print.la \
+ ${top_builddir}/libasn1compiler/libasn1compiler.la
+
+
+bin_PROGRAMS = asn1c
+
+dist_man1_MANS = asn1c.1
+
+check_SCRIPTS = check-parsing.sh
+TESTS = check-parsing.sh
+EXTRA_DIST = check-parsing.sh
+CLEANFILES = .check-parsing.*.tmp
+subdir = asn1c
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+bin_PROGRAMS = asn1c$(EXEEXT)
+PROGRAMS = $(bin_PROGRAMS)
+
+asn1c_SOURCES = asn1c.c
+asn1c_OBJECTS = asn1c.$(OBJEXT)
+asn1c_LDADD = $(LDADD)
+asn1c_DEPENDENCIES = ${top_builddir}/libasn1parser/libasn1parser.la \
+ ${top_builddir}/libasn1fix/libasn1fix.la \
+ ${top_builddir}/libasn1print/libasn1print.la \
+ ${top_builddir}/libasn1compiler/libasn1compiler.la
+asn1c_LDFLAGS =
+
+DEFS = @DEFS@
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/asn1c.Po
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
+ $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+CFLAGS = @CFLAGS@
+DIST_SOURCES = asn1c.c
+
+NROFF = nroff
+MANS = $(dist_man1_MANS)
+
+RECURSIVE_TARGETS = info-recursive dvi-recursive install-info-recursive \
+ uninstall-info-recursive all-recursive install-data-recursive \
+ install-exec-recursive installdirs-recursive install-recursive \
+ uninstall-recursive check-recursive installcheck-recursive
+DIST_COMMON = README $(dist_man1_MANS) Makefile.am Makefile.in
+DIST_SUBDIRS = $(SUBDIRS)
+SOURCES = asn1c.c
+
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu asn1c/Makefile
+Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) && \
+ CONFIG_HEADERS= CONFIG_LINKS= \
+ CONFIG_FILES=$(subdir)/$@ $(SHELL) ./config.status
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ $(mkinstalldirs) $(DESTDIR)$(bindir)
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ if test -f $$p \
+ || test -f $$p1 \
+ ; then \
+ f=`echo $$p1|sed '$(transform);s/$$/$(EXEEXT)/'`; \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$f"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$f; \
+ else :; fi; \
+ done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ f=`echo $$p|sed 's/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
+ echo " rm -f $(DESTDIR)$(bindir)/$$f"; \
+ rm -f $(DESTDIR)$(bindir)/$$f; \
+ done
+
+clean-binPROGRAMS:
+ -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+asn1c$(EXEEXT): $(asn1c_OBJECTS) $(asn1c_DEPENDENCIES)
+ @rm -f asn1c$(EXEEXT)
+ $(LINK) $(asn1c_LDFLAGS) $(asn1c_OBJECTS) $(asn1c_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT) core *.core
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/asn1c.Po@am__quote@
+
+distclean-depend:
+ -rm -rf $(DEPDIR)
+
+.c.o:
+@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ $(COMPILE) -c `test -f $< || echo '$(srcdir)/'`$<
+
+.c.obj:
+@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ $(COMPILE) -c `cygpath -w $<`
+
+.c.lo:
+@AMDEP_TRUE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ $(LTCOMPILE) -c -o $@ `test -f $< || echo '$(srcdir)/'`$<
+CCDEPMODE = @CCDEPMODE@
+uninstall-info-am:
+
+man1dir = $(mandir)/man1
+install-man1: $(man1_MANS) $(man_MANS)
+ @$(NORMAL_INSTALL)
+ $(mkinstalldirs) $(DESTDIR)$(man1dir)
+ @list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \
+ l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \
+ for i in $$l2; do \
+ case "$$i" in \
+ *.1*) list="$$list $$i" ;; \
+ esac; \
+ done; \
+ for i in $$list; do \
+ if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \
+ else file=$$i; fi; \
+ ext=`echo $$i | sed -e 's/^.*\\.//'`; \
+ inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
+ inst=`echo $$inst | sed -e 's/^.*\///'`; \
+ inst=`echo $$inst | sed '$(transform)'`.$$ext; \
+ echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst"; \
+ $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst; \
+ done
+uninstall-man1:
+ @$(NORMAL_UNINSTALL)
+ @list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \
+ l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \
+ for i in $$l2; do \
+ case "$$i" in \
+ *.1*) list="$$list $$i" ;; \
+ esac; \
+ done; \
+ for i in $$list; do \
+ ext=`echo $$i | sed -e 's/^.*\\.//'`; \
+ inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
+ inst=`echo $$inst | sed -e 's/^.*\///'`; \
+ inst=`echo $$inst | sed '$(transform)'`.$$ext; \
+ echo " rm -f $(DESTDIR)$(man1dir)/$$inst"; \
+ rm -f $(DESTDIR)$(man1dir)/$$inst; \
+ done
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+# (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+ @set fnord $(MAKEFLAGS); amf=$$2; \
+ dot_seen=no; \
+ target=`echo $@ | sed s/-recursive//`; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ dot_seen=yes; \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+ done; \
+ if test "$$dot_seen" = "no"; then \
+ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+ fi; test -z "$$fail"
+
+mostlyclean-recursive clean-recursive distclean-recursive \
+maintainer-clean-recursive:
+ @set fnord $(MAKEFLAGS); amf=$$2; \
+ dot_seen=no; \
+ case "$@" in \
+ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+ *) list='$(SUBDIRS)' ;; \
+ esac; \
+ rev=''; for subdir in $$list; do \
+ if test "$$subdir" = "."; then :; else \
+ rev="$$subdir $$rev"; \
+ fi; \
+ done; \
+ rev="$$rev ."; \
+ target=`echo $@ | sed s/-recursive//`; \
+ for subdir in $$rev; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+ done && test -z "$$fail"
+tags-recursive:
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+ done
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique $(LISP)
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \
+ fi; \
+ done; \
+ list='$(SOURCES) $(HEADERS) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+ || etags $(ETAGS_ARGS) $$tags $$unique $(LISP)
+
+GTAGS:
+ here=`CDPATH=: && cd $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list='$(TESTS)'; \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ echo "XPASS: $$tst"; \
+ ;; \
+ *) \
+ echo "PASS: $$tst"; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xfail=`expr $$xfail + 1`; \
+ echo "XFAIL: $$tst"; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ echo "FAIL: $$tst"; \
+ ;; \
+ esac; \
+ fi; \
+ done; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="All $$all tests passed"; \
+ else \
+ banner="All $$all tests behaved as expected ($$xfail expected failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all tests failed"; \
+ else \
+ banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \
+ fi; \
+ fi; \
+ dashes=`echo "$$banner" | sed s/./=/g`; \
+ echo "$$dashes"; \
+ echo "$$banner"; \
+ echo "$$dashes"; \
+ test "$$failed" -eq 0; \
+ fi
+
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+top_distdir = ..
+distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
+
+distdir: $(DISTFILES)
+ @for file in $(DISTFILES); do \
+ if test -f $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ $(mkinstalldirs) "$(distdir)/$$dir"; \
+ fi; \
+ if test -d $$d/$$file; then \
+ cp -pR $$d/$$file $(distdir) \
+ || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+ for subdir in $(SUBDIRS); do \
+ if test "$$subdir" = .; then :; else \
+ test -d $(distdir)/$$subdir \
+ || mkdir $(distdir)/$$subdir \
+ || exit 1; \
+ (cd $$subdir && \
+ $(MAKE) $(AM_MAKEFLAGS) \
+ top_distdir="$(top_distdir)" \
+ distdir=../$(distdir)/$$subdir \
+ distdir) \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) $(check_SCRIPTS)
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-recursive
+all-am: Makefile $(PROGRAMS) $(MANS)
+installdirs: installdirs-recursive
+installdirs-am:
+ $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir)
+
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES) stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-recursive
+
+distclean-am: clean-am distclean-compile distclean-depend \
+ distclean-generic distclean-libtool distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-man
+
+install-exec-am: install-binPROGRAMS
+
+install-info: install-info-recursive
+
+install-man: install-man1
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+uninstall-am: uninstall-binPROGRAMS uninstall-info-am uninstall-man
+
+uninstall-info: uninstall-info-recursive
+
+uninstall-man: uninstall-man1
+
+.PHONY: $(RECURSIVE_TARGETS) GTAGS all all-am check check-TESTS check-am \
+ clean clean-binPROGRAMS clean-generic clean-libtool \
+ clean-recursive distclean distclean-compile distclean-depend \
+ distclean-generic distclean-libtool distclean-recursive \
+ distclean-tags distdir dvi dvi-am dvi-recursive info info-am \
+ info-recursive install install-am install-binPROGRAMS \
+ install-data install-data-am install-data-recursive \
+ install-exec install-exec-am install-exec-recursive \
+ install-info install-info-am install-info-recursive install-man \
+ install-man1 install-recursive install-strip installcheck \
+ installcheck-am installdirs installdirs-am \
+ installdirs-recursive maintainer-clean maintainer-clean-generic \
+ maintainer-clean-recursive mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool mostlyclean-recursive \
+ tags tags-recursive uninstall uninstall-am \
+ uninstall-binPROGRAMS uninstall-info-am \
+ uninstall-info-recursive uninstall-man uninstall-man1 \
+ uninstall-recursive
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/asn1c/README b/asn1c/README
new file mode 100644
index 00000000..158cd115
--- /dev/null
+++ b/asn1c/README
@@ -0,0 +1 @@
+The ASN.1 Compiler
diff --git a/asn1c/asn1c.1 b/asn1c/asn1c.1
new file mode 100644
index 00000000..1b58f4df
--- /dev/null
+++ b/asn1c/asn1c.1
@@ -0,0 +1,99 @@
+.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 " ].\|.\|."
+.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.
+.SH OPTIONS
+.TP
+.B Overall Options
+\-E
+\-F
+\-L
+\-N
+\-P
+.RI "\-S " directory
+\-R
+.TP
+.B Language Options
+.br
+\-ftypes88
+\-fnative-integers
+\-fno-c99
+\-funnamed-unions
+.TP
+.B Warning Options
+.br
+\-Werror
+\-Wdebug-lexer
+\-Wdebug-fixer
+\-Wdebug-compiler
+.SH OVERALL OPTIONS
+.TP
+.B \-E
+Stop after the parsing stage. The output is reconstructed ASN.1
+specification code, which is sent to the standard output.
+.TP
+.B \-F
+Used together with \c
+.B \-E\c
+, instructs the compiler to stop after the ASN.1 syntax
+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 \-N
+Do not generate certain type of 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.
+.TP
+.B \-S directory
+Use the specified directory with ASN.1 skeleton files.
+.TP
+.B \-R
+Restrict the compiler to generate only the ASN.1 tables,
+omitting the usual support code.
+.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 WARNING OPTIONS
+.TP
+.B \-Werror
+Treat warnings as errors; abort if any warning is produced.
+.TP
+.B \-Wdebug-lexer
+Enable lexer debugging during the ASN.1 parsing stage.
+.TP
+.B \-Wdebug-fixer
+Enable ASN.1 syntax tree fixer debugging during the fixing stage.
+.TP
+.B \-Wdebug-compiler
+Enable debugging during the actual compile time.
+.SH AUTHORS
+Lev Walkin <vlm@lionet.info>
diff --git a/asn1c/asn1c.c b/asn1c/asn1c.c
new file mode 100644
index 00000000..afedf6bf
--- /dev/null
+++ b/asn1c/asn1c.c
@@ -0,0 +1,267 @@
+/*
+ * 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 <libgen.h> /* for basename(3) */
+#include <sysexits.h> /* for EX_USAGE */
+#include <assert.h>
+#include <errno.h>
+
+#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 */
+#include <asn1compiler.h> /* Compile the ASN.1 tree */
+
+static void usage(char *av0); /* Print the Usage screen and exit(EX_USAGE) */
+
+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;
+ int print_arg__print_out = 0; /* Don't compile, just print parsed */
+ int print_arg__fix_n_print = 0; /* Fix and print */
+ enum asn1print_flags_e print_arg__flags = APF_NOFLAGS;
+ int warnings_as_errors = 0; /* Treat warnings as errors */
+ char *skeletons_dir = NULL; /* Directory with supplementary stuff */
+ asn1p_t *asn = 0; /* An ASN.1 parsed tree */
+ int ret; /* Return value from misc functions */
+ int ch; /* Command line character */
+ int i; /* Index in some loops */
+
+ /*
+ * Process command-line options.
+ */
+ while((ch = getopt(ac, av, "EFf:LNPRS:W:")) != -1)
+ switch(ch) {
+ case 'E':
+ print_arg__print_out = 1;
+ break;
+ case 'F':
+ 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;
+ } else {
+ fprintf(stderr, "-f%s: Invalid argument\n", optarg);
+ exit(EX_USAGE);
+ }
+ break;
+ case 'L':
+ print_arg__flags = APF_LINE_COMMENTS;
+ break;
+ case 'N':
+ print_arg__flags = APF_NO_SOURCE_COMMENTS;
+ break;
+ case 'P':
+ asn1_compiler_flags |= A1C_PRINT_COMPILED;
+ break;
+ case 'R':
+ asn1_compiler_flags |= A1C_OMIT_SUPPORT_CODE;
+ break;
+ case 'S':
+ skeletons_dir = optarg;
+ break;
+ case 'W':
+ if(strcmp(optarg, "error") == 0) {
+ warnings_as_errors = 1;
+ break;
+ } else if(strcmp(optarg, "debug-lexer") == 0) {
+ asn1_parser_flags |= A1P_LEXER_DEBUG;
+ break;
+ } else if(strcmp(optarg, "debug-fixer") == 0) {
+ asn1_fixer_flags |= A1F_DEBUG;
+ break;
+ } else if(strcmp(optarg, "debug-compiler") == 0) {
+ asn1_compiler_flags |= A1C_DEBUG;
+ break;
+ } else {
+ fprintf(stderr, "-W%s: Invalid argument\n", optarg);
+ exit(EX_USAGE);
+ }
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ /*
+ * Validate the options combination.
+ */
+ if(!print_arg__print_out) {
+ if(print_arg__fix_n_print) {
+ fprintf(stderr, "Error: -F requires -E\n");
+ exit(EX_USAGE);
+ }
+ }
+
+ /*
+ * Ensure that there are some input files present.
+ */
+ if(ac > optind) {
+ ac -= optind;
+ av += optind;
+ } else {
+ fprintf(stderr, "%s: No input files specified\n",
+ basename(av[0]));
+ exit(1);
+ }
+
+ /*
+ * Iterate over input files and parse each.
+ * All syntax trees from all files will be bundled together.
+ */
+ for(i = 0; i < ac; i++) {
+ asn1p_t *new_asn;
+
+ new_asn = asn1p_parse_file(av[i], asn1_parser_flags);
+ if(new_asn == NULL) {
+ fprintf(stderr, "Cannot parse \"%s\"\n", av[i]);
+ exit(EX_DATAERR);
+ }
+
+ /*
+ * Bundle the parsed tree with existing one.
+ */
+ if(asn) {
+ asn1p_module_t *mod;
+ while((mod = TQ_REMOVE(&(new_asn->modules), mod_next)))
+ TQ_ADD(&(asn->modules), mod, mod_next);
+ asn1p_free(new_asn);
+ } else {
+ asn = new_asn;
+ }
+
+ }
+
+ /*
+ * Dump the parsed ASN.1 tree if -E specified and -F is not given.
+ */
+ if(print_arg__print_out && !print_arg__fix_n_print) {
+ if(asn1print(asn, print_arg__flags))
+ exit(EX_SOFTWARE);
+ return 0;
+ }
+
+
+ /*
+ * Process the ASN.1 specification: perform semantic checks,
+ * expand references, etc, etc.
+ * This function will emit necessary warnings and error messages.
+ */
+ ret = asn1f_process(asn, asn1_fixer_flags,
+ NULL /* default fprintf(stderr) */);
+ switch(ret) {
+ case 1:
+ if(!warnings_as_errors)
+ /* Fall through */
+ case 0:
+ break; /* All clear */
+ case -1:
+ exit(EX_DATAERR); /* Fatal failure */
+ }
+
+ /*
+ * Dump the parsed ASN.1 tree if -E specified and -F is given.
+ */
+ if(print_arg__print_out && print_arg__fix_n_print) {
+ if(asn1print(asn, print_arg__flags))
+ exit(EX_SOFTWARE);
+ 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;
+ int len;
+
+ p = 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)) {
+ exit(EX_SOFTWARE);
+ }
+
+ return 0;
+}
+
+/*
+ * Print the usage screen and exit(EX_USAGE).
+ */
+static void
+usage(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"
+ "\t-N\tDo not generate certain type of comments in -E output\n"
+ "\n"
+ "\t-P \tConcatenate and print the compiled text\n"
+ "\t-S <dir>\tDirectory with support (skeleton?) files\n"
+ "\t \t(Default is \"%s\")\n"
+ "\t-R \tRestrict output (tables only, no support code)\n"
+ "\n"
+ "\t-ftypes88\tUse only ASN.1:1988 embedded types\n"
+/*
+ "\t-fconstr90\tUse only ASN.1:1990 constructs (not available)\n"
+*/
+ "\t-fnative-integers\tUse native integers where possible\n"
+ "\t-fno-c99\tDisable C99 extensions\n"
+ "\t-funnamed-unions\tEnable unnamed unions in structures\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"
+ ,
+ basename(av0), DATADIR
+ );
+ exit(EX_USAGE);
+}
+
diff --git a/asn1c/check-parsing.sh b/asn1c/check-parsing.sh
new file mode 100755
index 00000000..9a7bfde7
--- /dev/null
+++ b/asn1c/check-parsing.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+tmpfile=".check-parsing.$$.tmp"
+
+ec=0
+
+for ref in ../tests/*.asn1.-*; do
+ src=`echo "$ref" | sed -e 's/\.-[a-zA-Z]*$//'`
+ flags=`echo "$ref" | sed -e 's/.*\.-//'`
+ echo "Checking $src against $ref"
+ ./asn1c "-$flags" "$src" > "$tmpfile" || ec=$?
+ if [ $? = 0 ]; then
+ diff "$ref" "$tmpfile" || ec=$?
+ fi
+ rm -f "$tmpfile"
+done
+
+exit $ec
diff --git a/asn1c/tests/Makefile.am b/asn1c/tests/Makefile.am
new file mode 100644
index 00000000..91dc54d3
--- /dev/null
+++ b/asn1c/tests/Makefile.am
@@ -0,0 +1,10 @@
+
+check_SCRIPTS = ./check-assembly.sh
+
+TESTS_ENVIRONMENT= ./check-assembly.sh
+TESTS = check-*.c
+
+EXTRA_DIST = ${check_SCRIPTS} check-*.c
+
+clean:
+ for t in test-*; do rm -rf $$t; done
diff --git a/asn1c/tests/Makefile.in b/asn1c/tests/Makefile.in
new file mode 100644
index 00000000..6689049c
--- /dev/null
+++ b/asn1c/tests/Makefile.in
@@ -0,0 +1,284 @@
+# Makefile.in generated automatically by automake 1.5 from Makefile.am.
+
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+# Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ../..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = @program_transform_name@
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_alias = @build_alias@
+build_triplet = @build@
+host_alias = @host_alias@
+host_triplet = @host@
+target_alias = @target_alias@
+target_triplet = @target@
+ADD_CFLAGS = @ADD_CFLAGS@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AWK = @AWK@
+CC = @CC@
+CONFIGURE_DEPENDS = @CONFIGURE_DEPENDS@
+CPP = @CPP@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+EXEEXT = @EXEEXT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LEX = @LEX@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+MAINT = @MAINT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PATH = @PATH@
+RANLIB = @RANLIB@
+VERSION = @VERSION@
+YACC = @YACC@
+am__include = @am__include@
+am__quote = @am__quote@
+install_sh = @install_sh@
+
+check_SCRIPTS = ./check-assembly.sh
+
+TESTS_ENVIRONMENT = ./check-assembly.sh
+TESTS = check-*.c
+
+EXTRA_DIST = ${check_SCRIPTS} check-*.c
+subdir = asn1c/tests
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+DIST_SOURCES =
+DIST_COMMON = README Makefile.am Makefile.in
+all: all-am
+
+.SUFFIXES:
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu asn1c/tests/Makefile
+Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) && \
+ CONFIG_HEADERS= CONFIG_LINKS= \
+ CONFIG_FILES=$(subdir)/$@ $(SHELL) ./config.status
+uninstall-info-am:
+tags: TAGS
+TAGS:
+
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list='$(TESTS)'; \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ echo "XPASS: $$tst"; \
+ ;; \
+ *) \
+ echo "PASS: $$tst"; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xfail=`expr $$xfail + 1`; \
+ echo "XFAIL: $$tst"; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ echo "FAIL: $$tst"; \
+ ;; \
+ esac; \
+ fi; \
+ done; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="All $$all tests passed"; \
+ else \
+ banner="All $$all tests behaved as expected ($$xfail expected failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all tests failed"; \
+ else \
+ banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \
+ fi; \
+ fi; \
+ dashes=`echo "$$banner" | sed s/./=/g`; \
+ echo "$$dashes"; \
+ echo "$$banner"; \
+ echo "$$dashes"; \
+ test "$$failed" -eq 0; \
+ fi
+
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+top_distdir = ../..
+distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
+
+distdir: $(DISTFILES)
+ @for file in $(DISTFILES); do \
+ if test -f $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ $(mkinstalldirs) "$(distdir)/$$dir"; \
+ fi; \
+ if test -d $$d/$$file; then \
+ cp -pR $$d/$$file $(distdir) \
+ || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) $(check_SCRIPTS)
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile
+
+installdirs:
+
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES) stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+
+distclean-am: clean-am distclean-generic distclean-libtool
+
+dvi: dvi-am
+
+dvi-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+uninstall-am: uninstall-info-am
+
+.PHONY: all all-am check check-TESTS check-am clean clean-generic \
+ clean-libtool distclean distclean-generic distclean-libtool \
+ distdir dvi dvi-am info info-am install install-am install-data \
+ install-data-am install-exec install-exec-am install-info \
+ install-info-am install-man install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic \
+ mostlyclean-libtool uninstall uninstall-am uninstall-info-am
+
+
+clean:
+ for t in test-*; do rm -rf $$t; done
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/asn1c/tests/README b/asn1c/tests/README
new file mode 100644
index 00000000..b7fb5605
--- /dev/null
+++ b/asn1c/tests/README
@@ -0,0 +1,6 @@
+
+This is a very funny test automation. The name of the check-*.c file is used
+as a pointer to the file in ../..//tests/*-*.asn1. This file is compiled
+using the asn1c from above directory. Then, everything is build together
+in a temporary directory with a check-*.c used as a testing engine.
+
diff --git a/asn1c/tests/check-22.c b/asn1c/tests/check-22.c
new file mode 100644
index 00000000..c80f9881
--- /dev/null
+++ b/asn1c/tests/check-22.c
@@ -0,0 +1,141 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <T1.h>
+
+uint8_t buf1[] = {
+ 32 | 16, /* [UNIVERSAL 16], constructed */
+ 12, /* L */
+ /* INTEGER a */
+ ((2 << 6) + 0), /* [0], primitive */
+ 2, /* L */
+ 150,
+ 70,
+ /* b [1] EXPLICIT CHOICE */
+ 32 | ((2 << 6) + 1), /* [1] */
+ 3, /* L */
+ ((2 << 6) + 1), /* [1] */
+ 1,
+ 'i',
+ /* UTF8String c */
+ ((2 << 6) + 2), /* [2], primitive */
+ 1, /* L */
+ 'x'
+};
+
+uint8_t buf2[128];
+int buf2_pos;
+
+static int
+buf2_fill(const void *buffer, size_t size, void *app_key) {
+ if(buf2_pos + size > sizeof(buf2))
+ return -1;
+
+ memcpy(buf2 + buf2_pos, buffer, size);
+ buf2_pos += size;
+
+ return 0;
+}
+
+static void
+check(int is_ok, uint8_t *buf, int size, int consumed) {
+ T1_t t, *tp;
+ ber_dec_rval_t rval;
+ der_enc_rval_t erval;
+ int i;
+
+ tp = memset(&t, 0, sizeof(t));
+
+ fprintf(stderr, "Buf %p\n", buf);
+ rval = ber_decode(&asn1_DEF_T1, (void **)&tp, buf, size);
+ fprintf(stderr, "Returned code %d, consumed %d\n",
+ (int)rval.code, (int)rval.consumed);
+
+ if(is_ok) {
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == consumed);
+ assert(t.a.size == 2);
+ assert(t.b.present == b_PR_n);
+ assert(t.b.choice.n.size == 1);
+ assert(t.b.choice.n.buf[0] == 'i');
+ assert(t.c.size == 1);
+ assert(t.c.buf[0] == 'x');
+
+ } else {
+ if(rval.code == RC_OK) {
+ assert(t.a.size != 2
+ || t.b.present != b_PR_n
+ || t.b.choice.n.size != 1
+ || t.c.size != 1
+ );
+ }
+ assert(rval.consumed <= consumed);
+ return;
+ }
+
+ fprintf(stderr, "=> Re-creating using DER encoder <=\n");
+
+ /*
+ * Try to re-create using DER encoding.
+ */
+ buf2_pos = 0;
+ erval = der_encode(&asn1_DEF_T1, tp, buf2_fill, 0);
+ assert(erval.encoded != -1);
+ if(erval.encoded != sizeof(buf1)) {
+ printf("%d != %d\n", (int)erval.encoded, (int)sizeof(buf1));
+ }
+ assert(erval.encoded == sizeof(buf1));
+ for(i = 0; i < sizeof(buf1); i++) {
+ if(buf1[i] != buf2[i]) {
+ fprintf(stderr, "Recreated buffer content mismatch:\n");
+ fprintf(stderr, "Byte %d, %x != %x (%d != %d)\n",
+ i,
+ buf1[i], buf2[i],
+ buf1[i], buf2[i]
+ );
+ }
+ assert(buf1[i] == buf2[i]);
+ }
+
+ fprintf(stderr, "=== PRINT ===\n");
+ asn_fprint(stderr, &asn1_DEF_T1, tp);
+ fprintf(stderr, "=== EOF ===\n");
+}
+
+static void
+try_corrupt(uint8_t *buf, int size) {
+ uint8_t *tmp;
+ int i;
+
+ fprintf(stderr, "\nCorrupting...\n");
+
+ tmp = alloca(size);
+
+ for(i = 0; i < 1000; i++) {
+ int loc;
+ memcpy(tmp, buf, size);
+
+ /* Corrupt random _non-value_ location. */
+ do { loc = random() % size; } while(tmp[loc] >= 70);
+ do { tmp[loc] ^= random(); } while(tmp[loc] == buf[loc]);
+
+ fprintf(stderr, "\nTry %d: corrupting byte %d (%d->%d)\n",
+ i, loc, buf[loc], tmp[loc]);
+
+ check(0, tmp, size, size);
+ }
+}
+
+int
+main(int ac, char **av) {
+
+ check(1, buf1, sizeof(buf1), sizeof(buf1));
+ try_corrupt(buf1, sizeof(buf1));
+ check(1, buf1, sizeof(buf1) + 10, sizeof(buf1));
+
+ return 0;
+}
diff --git a/asn1c/tests/check-24.c b/asn1c/tests/check-24.c
new file mode 100644
index 00000000..b74ca165
--- /dev/null
+++ b/asn1c/tests/check-24.c
@@ -0,0 +1,94 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <T.h>
+
+uint8_t buf1[] = {
+ 32 | ((2 << 6) + 5), /* [5], constructed */
+ 17, /* L */
+ 32 | 16, /* [UNIVERSAL 16], constructed */
+ 15, /* L */
+ /* INTEGER a */
+ 2, /* [UNIVERSAL 2] */
+ 2, /* L */
+ 150,
+ 70,
+ /* INTEGER b */
+ ((2 << 6) + 0), /* [0] */
+ 1, /* L */
+ 123,
+ /* INTEGER c */
+ ((2 << 6) + 1), /* [1] */
+ 1, /* L */
+ 123,
+ /* INTEGER d */
+ 32 | ((2 << 6) + 5), /* [5], constructed */
+ 3,
+ 2,
+ 1, /* L */
+ 123,
+};
+
+static void
+check(int is_ok, uint8_t *buf, int size, int consumed) {
+ T_t t, *tp;
+ ber_dec_rval_t rval;
+
+ tp = memset(&t, 0, sizeof(t));
+
+ fprintf(stderr, "Buf %p\n", buf);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp, buf, size);
+ fprintf(stderr, "Returned code %d, consumed %d\n",
+ (int)rval.code, (int)rval.consumed);
+
+ if(is_ok) {
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == consumed);
+ } else {
+ if(rval.code == RC_OK) {
+ assert(t.a.size != 2
+ || (!t.b || t.b->size != 1)
+ || (!t.c || t.c->size != 1)
+ || t.d.size != 1
+ );
+ }
+ assert(rval.consumed <= consumed);
+ }
+}
+
+static void
+try_corrupt(uint8_t *buf, int size) {
+ uint8_t *tmp;
+ int i;
+
+ fprintf(stderr, "\nCorrupting...\n");
+
+ tmp = alloca(size);
+
+ for(i = 0; i < 1000; i++) {
+ int loc;
+ memcpy(tmp, buf, size);
+
+ /* Corrupt random _non-value_ location. */
+ do { loc = random() % size; } while(tmp[loc] >= 70);
+ do { tmp[loc] ^= random(); } while(tmp[loc] == buf[loc]);
+
+ fprintf(stderr, "\nTry %d: corrupting byte %d (%d->%d)\n",
+ i, loc, buf[loc], tmp[loc]);
+
+ check(0, tmp, size, size);
+ }
+}
+
+int
+main(int ac, char **av) {
+
+ check(1, buf1, sizeof(buf1), sizeof(buf1));
+ try_corrupt(buf1, sizeof(buf1));
+
+ return 0;
+}
diff --git a/asn1c/tests/check-25.c b/asn1c/tests/check-25.c
new file mode 100644
index 00000000..bd803da3
--- /dev/null
+++ b/asn1c/tests/check-25.c
@@ -0,0 +1,252 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <T.h>
+
+uint8_t buf1[] = {
+ 32 | 16, /* [UNIVERSAL 16], constructed */
+ 128, /* L */
+ /* a INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 2, /* L */
+ 150,
+ 70,
+ /* b BOOLEAN */
+ 128 | 2, /* [2] */
+ 1, /* L */
+ 0xff,
+ /* c NULL */
+ 5, /* [UNIVERSAL 5] */
+ 0, /* L */
+ /* d ENUMERATED */
+ 10, /* [UNIVERSAL 10] */
+ 1, /* L */
+ 222,
+ 4, /* [UNIVERSAL 4] */
+ 3, /* L */
+ 'x',
+ 'y',
+ 'z',
+ /* f OCTET STRING */
+ 32 | 4, /* [UNIVERSAL 4], constructed */
+ 128, /* L indefinite */
+ 4, /* [UNIVERSAL 4], primitive */
+ 2,
+ 'l',
+ 'o',
+ 32 | 4, /* [UNIVERSAL 4], recursively constructed */
+ 128,
+ 4,
+ 1,
+ 'v',
+ 4,
+ 2,
+ 'e',
+ '_',
+ 0,
+ 0,
+ 4, /* [UNIVERSAL 4], primitive */
+ 2,
+ 'i',
+ 't',
+ 0,
+ 0,
+ /* g BIT STRING */
+ 3, /* [UNIVERSAL 3], primitive */
+ 3, /* L */
+ 2, /* Skip 2 bits */
+ 147,
+ 150, /* => 148 */
+ /* h BIT STRING */
+ 32 | 3, /* [UNIVERSAL 3], constructed */
+ 128, /* L indefinite */
+ 3, /* [UNIVERSAL 3], primitive */
+ 3, /* L */
+ 0, /* Skip 0 bits */
+ 140,
+ 141,
+ 3, /* [UNIVERSAL 3], primitive */
+ 2, /* L */
+ 1, /* Skip 1 bit */
+ 143, /* => 142 */
+ 0, /* End of f */
+ 0,
+ 0, /* End of the whole structure */
+ 0,
+ /* Three bytes of planned leftover */
+ 111, 222, 223
+};
+
+static void
+check(int is_ok, uint8_t *buf, int size, int consumed) {
+ T_t t, *tp;
+ ber_dec_rval_t rval;
+
+ tp = memset(&t, 0, sizeof(t));
+
+ fprintf(stderr, "Buf %p (%d)\n", buf, (int)size);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp, buf, size);
+ fprintf(stderr, "Returned code %d, consumed %d, expected %d\n",
+ (int)rval.code, (int)rval.consumed, (int)consumed);
+
+ if(is_ok) {
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == consumed);
+
+ assert(strcmp(t.e->buf, "xyz") == 0);
+ assert(strcmp(t.f->buf, "love_it") == 0);
+
+ assert(t.g->size == 3);
+ assert(t.g->buf[0] == 2);
+ assert(t.g->buf[1] == 147);
+ assert(t.g->buf[2] == 148);
+
+ printf("%d\n", t.h->buf[3]);
+ assert(t.h->size == 4);
+ assert(t.h->buf[0] == 1);
+ assert(t.h->buf[1] == 140);
+ assert(t.h->buf[2] == 141);
+ assert(t.h->buf[3] == 142);
+ } else {
+ if(rval.code == RC_OK) {
+ assert(t.a.size != 2
+ || !t.d
+ || t.d->size != 1
+ || !t.e
+ || t.e->size != 3
+ || !t.f
+ || t.f->size != 7
+ || !t.g
+ || t.g->size != 3
+ || !t.h
+ || t.h->size != 4
+ );
+ }
+ fprintf(stderr, "%d %d\n", (int)rval.consumed, (int)consumed);
+ assert(rval.consumed <= consumed);
+ }
+
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+}
+
+static void
+try_corrupt(uint8_t *buf, int size, int allow_consume) {
+ uint8_t *tmp;
+ int i;
+
+ fprintf(stderr, "\nCorrupting...\n");
+
+ tmp = alloca(size);
+
+ for(i = 0; i < 1000; i++) {
+ int loc;
+ memcpy(tmp, buf, size);
+
+ /* Corrupt random _non-value_ location. */
+ do { loc = random() % size; } while(
+ loc == 44 /* bit skips */
+ || loc == 51 /* bit skips */
+ || loc == 56 /* bit skips */
+ || tmp[loc] >= 70);
+ do { tmp[loc] = buf[loc] ^ random(); } while(
+ (tmp[loc] == buf[loc])
+ || (buf[loc] == 0 && tmp[loc] == 0x80));
+
+ fprintf(stderr, "\nTry %d: corrupting byte %d (%d->%d)\n",
+ i, loc, buf[loc], tmp[loc]);
+
+ check(0, tmp, size, allow_consume);
+ }
+}
+
+static void
+partial_read(uint8_t *buf, int size) {
+ T_t t, *tp;
+ ber_dec_rval_t rval;
+ int i1, i2;
+ uint8_t *buf1 = alloca(size);
+ uint8_t *buf2 = alloca(size);
+ uint8_t *buf3 = alloca(size);
+
+ fprintf(stderr, "\nPartial read sequence...\n");
+
+ /*
+ * Divide the space (size) into three blocks in various combinations:
+ * |<----->i1<----->i2<----->|
+ * ^ buf ^ buf+size
+ * Try to read block by block.
+ */
+ for(i1 = 0; i1 < size; i1++) {
+ for(i2 = i1; i2 < size; i2++) {
+ uint8_t *chunk1 = buf;
+ int size1 = i1;
+ uint8_t *chunk2 = buf + size1;
+ int size2 = i2 - i1;
+ uint8_t *chunk3 = buf + size1 + size2;
+ int size3 = size - size1 - size2;
+
+ fprintf(stderr, "\n%d:{%d, %d, %d}...\n",
+ size, size1, size2, size3);
+
+ memset(buf1, 0, size);
+ memset(buf2, 0, size);
+ memset(buf3, 0, size);
+ memcpy(buf1, chunk1, size1);
+ memcpy(buf2, chunk2, size2);
+ memcpy(buf3, chunk3, size3);
+
+ tp = memset(&t, 0, sizeof(t));
+
+ fprintf(stderr, "=> Chunk 1 (%d):\n", size1);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf1, size1);
+ assert(rval.code == RC_WMORE);
+ assert(rval.consumed <= size1);
+ if(rval.consumed < size1) {
+ int leftover = size1 - rval.consumed;
+ memcpy(buf2, buf1 + rval.consumed, leftover);
+ memcpy(buf2 + leftover, chunk2, size2);
+ size2 += leftover;
+ }
+
+ fprintf(stderr, "=> Chunk 2 (%d):\n", size2);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf2, size2);
+ assert(rval.code == RC_WMORE);
+ assert(rval.consumed <= size2);
+ if(rval.consumed < size2) {
+ int leftover = size2 - rval.consumed;
+ memcpy(buf3, buf2 + rval.consumed, leftover);
+ memcpy(buf3 + leftover, chunk3, size3);
+ size3 += leftover;
+ }
+
+ fprintf(stderr, "=> Chunk 3 (%d):\n", size3);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf3, size3);
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == size3);
+
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+ }
+ }
+}
+
+int
+main(int ac, char **av) {
+
+ /* Check that the full buffer may be decoded normally */
+ check(1, buf1, sizeof(buf1), sizeof(buf1) - 3);
+
+ /* Check that some types of buffer corruptions will lead to failure */
+ try_corrupt(buf1, sizeof(buf1) - 3, sizeof(buf1) - 3);
+
+ /* Split the buffer in parts and check decoder restartability */
+ partial_read(buf1, sizeof(buf1) - 3);
+
+ return 0;
+}
diff --git a/asn1c/tests/check-30.c b/asn1c/tests/check-30.c
new file mode 100644
index 00000000..9e5adf22
--- /dev/null
+++ b/asn1c/tests/check-30.c
@@ -0,0 +1,116 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <T.h>
+
+uint8_t buf1[] = {
+ 32 | 17, /* [UNIVERSAL 17], constructed */
+ 8, /* L */
+
+ /* a INTEGER */
+ 64 | 3, /* [APPLICATION 3] */
+ 1, /* L */
+ 96,
+
+ /* b IA5String */
+ 22, /* [UNIVERSAL 22] */
+ 3, /* L */
+ 'x',
+ 'y',
+ 'z'
+};
+
+/*
+ * This buffer aims at checking the duplication.
+ */
+uint8_t buf2[] = {
+ 32 | 17, /* [UNIVERSAL 17], constructed */
+ 8, /* L */
+
+ /* a INTEGER */
+ 64 | 3, /* [APPLICATION 3] */
+ 1, /* L */
+ 96,
+
+ /* a INTEGER _again_ */
+ 64 | 3, /* [APPLICATION 3] */
+ 1, /* L */
+ 97,
+};
+
+static void
+check(int is_ok, uint8_t *buf, int size, int consumed) {
+ T_t t, *tp;
+ ber_dec_rval_t rval;
+
+ tp = memset(&t, 0, sizeof(t));
+
+ fprintf(stderr, "Buf %p\n", buf);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp, buf, size);
+ fprintf(stderr, "Returned code %d, consumed %d\n",
+ (int)rval.code, (int)rval.consumed);
+
+ if(is_ok) {
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == consumed);
+
+ assert(t.a.size == 1);
+ assert(t.a.buf[0] == 96);
+ assert(t.b.size == 3);
+ assert(t.c == 0);
+ assert(strcmp(t.b.buf, "xyz") == 0);
+ } else {
+ if(rval.code == RC_OK) {
+ assert(t.a.size != 1
+ || t.b.size != 3
+ || !t.c
+ );
+ }
+ assert(rval.consumed <= consumed);
+ }
+}
+
+static void
+try_corrupt(uint8_t *buf, int size) {
+ uint8_t *tmp;
+ int i;
+
+ fprintf(stderr, "\nCorrupting...\n");
+
+ tmp = alloca(size);
+
+ for(i = 0; i < 1000; i++) {
+ int loc;
+ memcpy(tmp, buf, size);
+
+ /* Corrupt random _non-value_ location. */
+ do { loc = random() % size; } while(tmp[loc] >= 70);
+ do { tmp[loc] = buf[loc] ^ random(); } while(
+ (tmp[loc] == buf[loc])
+ || (buf[loc] == 0 && tmp[loc] == 0x80));
+
+ fprintf(stderr, "\nTry %d: corrupting byte %d (%d->%d)\n",
+ i, loc, buf[loc], tmp[loc]);
+
+ check(0, tmp, size, size);
+ }
+}
+
+int
+main(int ac, char **av) {
+
+ fprintf(stderr, "Must succeed:\n");
+ check(1, buf1, sizeof(buf1) + 20, sizeof(buf1));
+
+ fprintf(stderr, "\nMust fail:\n");
+ check(0, buf2, sizeof(buf2) + 1, 5);
+
+ fprintf(stderr, "\nPseudo-random buffer corruptions must fail\n");
+ try_corrupt(buf1, sizeof(buf1));
+
+ return 0;
+}
diff --git a/asn1c/tests/check-31.c b/asn1c/tests/check-31.c
new file mode 100644
index 00000000..53a90cba
--- /dev/null
+++ b/asn1c/tests/check-31.c
@@ -0,0 +1,175 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <Forest.h>
+
+uint8_t buf1[] = {
+ 32 | 17, /* [UNIVERSAL 17], constructed */
+ 128, /* L, indefinite */
+
+ 32 | 16, /* [UNIVERSAL 16], constructed */
+ 6, /* L */
+
+ /* height INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 1, /* L */
+ 100,
+ /* width INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 1, /* L */
+ 80,
+
+ 32 | 16, /* [UNIVERSAL 16], constructed */
+ 6, /* L */
+
+ /* height INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 1, /* L */
+ 110,
+ /* width INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 1, /* L */
+ 82,
+
+ 0, /* End of forest */
+ 0
+};
+
+uint8_t buf1_reconstr[] = {
+ 32 | 17, /* [UNIVERSAL 17], constructed */
+ 16, /* L */
+
+ 32 | 16, /* [UNIVERSAL 16], constructed */
+ 6, /* L */
+
+ /* height INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 1, /* L */
+ 100,
+ /* width INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 1, /* L */
+ 80,
+
+ 32 | 16, /* [UNIVERSAL 16], constructed */
+ 6, /* L */
+
+ /* height INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 1, /* L */
+ 110,
+ /* width INTEGER */
+ 2, /* [UNIVERSAL 2] */
+ 1, /* L */
+ 82
+
+};
+
+int buf_pos;
+int bytes_compare(const void *bufferp, size_t size, void *key) {
+ const uint8_t *buffer = bufferp;
+ assert(buf_pos + size <= sizeof(buf1_reconstr));
+
+ fprintf(stderr, " writing %d (%d)\n", (int)size, buf_pos + (int)size);
+
+ for(; size; buf_pos++, size--, buffer++) {
+ if(buf1_reconstr[buf_pos] != *buffer) {
+ fprintf(stderr,
+ "Byte %d is different: %d != %d (%x != %x)\n",
+ buf_pos,
+ *buffer, buf1_reconstr[buf_pos],
+ *buffer, buf1_reconstr[buf_pos]
+ );
+ assert(buf1_reconstr[buf_pos] == *buffer);
+ }
+ }
+
+ return 0;
+}
+
+static void
+check(int is_ok, uint8_t *buf, int size, int consumed) {
+ Forest_t t, *tp;
+ ber_dec_rval_t rval;
+
+ tp = memset(&t, 0, sizeof(t));
+
+ fprintf(stderr, "Buf %p\n", buf);
+ rval = ber_decode(&asn1_DEF_Forest, (void **)&tp, buf, size);
+ fprintf(stderr, "Returned code %d, consumed %d\n",
+ (int)rval.code, (int)rval.consumed);
+
+ if(is_ok) {
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == consumed);
+
+ assert(t.list.count == 2);
+ assert(t.list.array[0]->height.size == 1);
+ assert(t.list.array[0]->width.size == 1);
+ assert(t.list.array[1]->height.size == 1);
+ assert(t.list.array[1]->width.size == 1);
+ } else {
+ if(rval.code == RC_OK) {
+ assert(t.list.count != 2
+ || t.list.array[0]->height.size != 1
+ || t.list.array[0]->width.size != 1
+ || t.list.array[1]->height.size != 1
+ || t.list.array[1]->width.size != 1
+ );
+ }
+ assert(rval.consumed <= consumed);
+ return;
+ }
+
+ /*
+ * Try to re-create the buffer.
+ */
+ buf_pos = 0;
+ der_encode(&asn1_DEF_Forest, &t,
+ bytes_compare, buf1_reconstr);
+ assert(buf_pos == sizeof(buf1_reconstr));
+
+ asn_fprint(stderr, &asn1_DEF_Forest, &t);
+
+ asn1_DEF_Forest.free_struct(&asn1_DEF_Forest, &t, 1);
+}
+
+static void
+try_corrupt(uint8_t *buf, int size) {
+ uint8_t *tmp;
+ int i;
+
+ fprintf(stderr, "\nCorrupting...\n");
+
+ tmp = alloca(size);
+
+ for(i = 0; i < 1000; i++) {
+ int loc;
+ memcpy(tmp, buf, size);
+
+ /* Corrupt random _non-value_ location. */
+ do { loc = random() % size; } while(tmp[loc] >= 70);
+ do { tmp[loc] = buf[loc] ^ random(); } while(
+ (tmp[loc] == buf[loc])
+ || (buf[loc] == 0 && tmp[loc] == 0x80));
+
+ fprintf(stderr, "\nTry %d: corrupting byte %d (%d->%d)\n",
+ i, loc, buf[loc], tmp[loc]);
+
+ check(0, tmp, size, size);
+ }
+}
+
+int
+main(int ac, char **av) {
+
+ check(1, buf1, sizeof(buf1), sizeof(buf1));
+ try_corrupt(buf1, sizeof(buf1));
+ check(1, buf1, sizeof(buf1) + 20, sizeof(buf1));
+
+ return 0;
+}
diff --git a/asn1c/tests/check-32.c b/asn1c/tests/check-32.c
new file mode 100644
index 00000000..3cb0fdac
--- /dev/null
+++ b/asn1c/tests/check-32.c
@@ -0,0 +1,21 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <Programming.h>
+
+int
+main(int ac, char **av) {
+ Programming_t p;
+
+ memset(&p, 0, sizeof(p));
+
+ /*
+ * No plans to fill it up: just checking whether it compiles or not.
+ */
+
+ return 0;
+}
diff --git a/asn1c/tests/check-33.c b/asn1c/tests/check-33.c
new file mode 100644
index 00000000..14f5377a
--- /dev/null
+++ b/asn1c/tests/check-33.c
@@ -0,0 +1,21 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <T.h>
+
+int
+main(int ac, char **av) {
+ T_t t;
+
+ memset(&t, 0, sizeof(t));
+
+ /*
+ * No plans to fill it up: just checking whether it compiles or not.
+ */
+
+ return 0;
+}
diff --git a/asn1c/tests/check-35.c b/asn1c/tests/check-35.c
new file mode 100644
index 00000000..6b6c04d6
--- /dev/null
+++ b/asn1c/tests/check-35.c
@@ -0,0 +1,277 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <T.h>
+
+uint8_t buf1[] = {
+ 32 | 17, /* [UNIVERSAL 17], constructed */
+ 13, /* L */
+
+ /* b CHOICE { b2 ObjectDescriptor }*/
+ 7, /* [UNIVERSAL 7] */
+ 1, /* L */
+ 'z',
+
+ /* c BOOLEAN */
+ 1, /* [UNIVERSAL 1] */
+ 0, /* L */
+
+ /* a NumericString */
+ 18, /* [UNIVERSAL 18] */
+ 2, /* L */
+ 'n',
+ 's',
+
+ /* d.r-oid RELATIVE-OID */
+ 13, /* [UNIVERSAL 13] */
+ 2, /* L */
+ 85,
+ 79,
+
+};
+
+uint8_t buf1_reconstr[] = {
+ 32 | 17, /* [UNIVERSAL 17], constructed */
+ 14, /* L */
+
+ /* c BOOLEAN */
+ 1, /* [UNIVERSAL 1] */
+ 1, /* L */
+ 0,
+
+ /* b CHOICE { b2 ObjectDescriptor }*/
+ 7, /* [UNIVERSAL 7] */
+ 1, /* L */
+ 'z',
+
+ /* d.r-oid RELATIVE-OID */
+ 13, /* [UNIVERSAL 1] */
+ 2, /* L */
+ 85,
+ 79,
+
+ /* a NumericString */
+ 18, /* [UNIVERSAL 18] */
+ 2, /* L */
+ 'n',
+ 's'
+};
+
+uint8_t buf2[] = {
+ 32 | 17, /* [UNIVERSAL 17], constructed */
+ 13, /* L */
+
+ /* a NumericString */
+ 18, /* [UNIVERSAL 18] */
+ 2, /* L */
+ 'n',
+ 's',
+
+ /* c BOOLEAN */
+ 1, /* [UNIVERSAL 1] */
+ 1, /* L */
+ 2, /* True */
+
+ /* b CHOICE { b1 IA5String }*/
+ 22, /* [UNIVERSAL 22] */
+ 1, /* L */
+ 'z',
+
+ /* d.oid RELATIVE-OID */
+ 6, /* [UNIVERSAL 6] */
+ 1, /* L */
+ 81,
+
+};
+
+uint8_t buf2_reconstr[] = {
+ 32 | 17, /* [UNIVERSAL 17], constructed */
+ 13, /* L */
+
+ /* c BOOLEAN */
+ 1, /* [UNIVERSAL 1] */
+ 1, /* L */
+ 0xff, /* Canonical True */
+
+ /* d.oid RELATIVE-OID */
+ 6, /* [UNIVERSAL 6] */
+ 1, /* L */
+ 81,
+
+ /* a NumericString */
+ 18, /* [UNIVERSAL 18] */
+ 2, /* L */
+ 'n',
+ 's',
+
+ /* b CHOICE { b1 IA5String }*/
+ 22, /* [UNIVERSAL 22] */
+ 1, /* L */
+ 'z'
+};
+
+static void
+check(T_t *tp, uint8_t *buf, int size, int consumed) {
+ ber_dec_rval_t rval;
+
+ tp = memset(tp, 0, sizeof(*tp));
+
+ fprintf(stderr, "Buf %p (%d)\n", buf, size);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp, buf, size);
+ fprintf(stderr, "Returned code %d, consumed %d\n",
+ (int)rval.code, (int)rval.consumed);
+
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == consumed);
+
+ assert(strcmp(tp->a.buf, "ns") == 0);
+ assert(strcmp(tp->b.choice.b1.buf, "z") == 0
+ && strcmp(tp->b.choice.b2.buf, "z") == 0);
+}
+
+int buf_pos;
+int buf_size;
+uint8_t *buf;
+
+static int
+buf_fill(const void *buffer, size_t size, void *app_key) {
+
+ if(buf_pos + size > buf_size) {
+ fprintf(stderr, "%d + %d > %d\n", buf_pos, (int)size, buf_size);
+ return -1;
+ }
+
+ memcpy(buf + buf_pos, buffer, size);
+ buf_pos += size;
+ fprintf(stderr, " written %d (%d)\n", (int)size, buf_pos);
+
+ return 0;
+}
+
+void
+compare(T_t *tp, uint8_t *cmp_buf, int cmp_buf_size) {
+ der_enc_rval_t erval;
+ int i;
+
+ buf_size = cmp_buf_size + 100;
+ buf = alloca(buf_size);
+ buf_pos = 0;
+
+ /*
+ * Try to re-create using DER encoding.
+ */
+ erval = der_encode(&asn1_DEF_T, tp, buf_fill, 0);
+ assert(erval.encoded != -1);
+ if(erval.encoded != cmp_buf_size) {
+ printf("%d != %d\n", erval.encoded, cmp_buf_size);
+ }
+ assert(erval.encoded == cmp_buf_size);
+ for(i = 0; i < cmp_buf_size; i++) {
+ if(buf[i] != cmp_buf[i]) {
+ fprintf(stderr, "Recreated buffer content mismatch:\n");
+ fprintf(stderr, "Byte %d, %x != %x (%d != %d)\n",
+ i,
+ buf[i], cmp_buf[i],
+ buf[i], cmp_buf[i]
+ );
+ }
+ assert(buf[i] == cmp_buf[i]);
+ }
+}
+
+static void
+partial_read(uint8_t *buf, int size) {
+ T_t t, *tp;
+ ber_dec_rval_t rval;
+ int i1, i2;
+ uint8_t *buf1 = alloca(size);
+ uint8_t *buf2 = alloca(size);
+ uint8_t *buf3 = alloca(size);
+
+ fprintf(stderr, "\nPartial read sequence...\n");
+
+ /*
+ * Divide the space (size) into three blocks in various combinations:
+ * |<----->i1<----->i2<----->|
+ * ^ buf ^ buf+size
+ * Try to read block by block.
+ */
+ for(i1 = 0; i1 < size; i1++) {
+ for(i2 = i1; i2 < size; i2++) {
+ uint8_t *chunk1 = buf;
+ int size1 = i1;
+ uint8_t *chunk2 = buf + size1;
+ int size2 = i2 - i1;
+ uint8_t *chunk3 = buf + size1 + size2;
+ int size3 = size - size1 - size2;
+
+ fprintf(stderr, "\n%d:{%d, %d, %d}...\n",
+ size, size1, size2, size3);
+
+ memset(buf1, 0, size);
+ memset(buf2, 0, size);
+ memset(buf3, 0, size);
+ memcpy(buf1, chunk1, size1);
+ memcpy(buf2, chunk2, size2);
+ memcpy(buf3, chunk3, size3);
+
+ tp = memset(&t, 0, sizeof(t));
+
+ fprintf(stderr, "=> Chunk 1 (%d):\n", size1);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf1, size1);
+ assert(rval.code == RC_WMORE);
+ assert(rval.consumed <= size1);
+ if(rval.consumed < size1) {
+ int leftover = size1 - rval.consumed;
+ memcpy(buf2, buf1 + rval.consumed, leftover);
+ memcpy(buf2 + leftover, chunk2, size2);
+ size2 += leftover;
+ }
+
+ fprintf(stderr, "=> Chunk 2 (%d):\n", size2);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf2, size2);
+ assert(rval.code == RC_WMORE);
+ assert(rval.consumed <= size2);
+ if(rval.consumed < size2) {
+ int leftover = size2 - rval.consumed;
+ memcpy(buf3, buf2 + rval.consumed, leftover);
+ memcpy(buf3 + leftover, chunk3, size3);
+ size3 += leftover;
+ }
+
+ fprintf(stderr, "=> Chunk 3 (%d):\n", size3);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf3, size3);
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == size3);
+
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+ }
+ }
+}
+
+int
+main(int ac, char **av) {
+ T_t t;
+
+ check(&t, buf1, sizeof(buf1) + 10, sizeof(buf1));
+ compare(&t, buf1_reconstr, sizeof(buf1_reconstr));
+ asn_fprint(stderr, &asn1_DEF_T, &t);
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+
+ check(&t, buf2, sizeof(buf2) + 10, sizeof(buf2));
+ compare(&t, buf2_reconstr, sizeof(buf2_reconstr));
+ asn_fprint(stderr, &asn1_DEF_T, &t);
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+
+ /* Split the buffer in parts and check decoder restartability */
+ partial_read(buf1, sizeof(buf1));
+
+ return 0;
+}
diff --git a/asn1c/tests/check-41.c b/asn1c/tests/check-41.c
new file mode 100644
index 00000000..c2238cf5
--- /dev/null
+++ b/asn1c/tests/check-41.c
@@ -0,0 +1,315 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <T.h>
+
+uint8_t buf0[] = {
+ 32 | ((2 << 6) + 1), /* [1], constructed */
+ 18,
+
+ /* string [0] IMPLICIT UTF8String, */
+ (2 << 6), /* [0] */
+ 16, /* L */
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+};
+
+uint8_t buf0_reconstr[] = {
+ 32 | ((2 << 6) + 1), /* [1], constructed */
+ 18,
+
+ /* string [0] IMPLICIT UTF8String, */
+ (2 << 6), /* [0] */
+ 16, /* L */
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+};
+
+
+
+uint8_t buf1[] = {
+ 32 | (2 << 6), /* [0], constructed */
+ 0x80 | 1, /* L */
+ 134,
+
+ /* string [0] IMPLICIT UTF8String, */
+ (2 << 6), /* [0] */
+ 0x80 | 1, /* L */
+ 128,
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+
+ /* alpha [1] IMPLICIT INTEGER OPTIONAL */
+ (2 << 6) + 1, /* [1] */
+ 1, /* L */
+ 75,
+};
+
+uint8_t buf1_reconstr[] = {
+ 32 | (2 << 6), /* [0], constructed */
+ 0x80 | 1, /* L */
+ 134,
+
+ /* string [0] IMPLICIT UTF8String, */
+ (2 << 6), /* [0] */
+ 0x80 | 1, /* L */
+ 128,
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+
+ /* alpha [1] IMPLICIT INTEGER OPTIONAL */
+ (2 << 6) + 1, /* [1] */
+ 1, /* L */
+ 75,
+};
+
+uint8_t buf2[] = {
+ 32 | ((2 << 6) + 1), /* [1], constructed */
+ 0x80 | 1, /* L */
+ 134,
+
+ /* string [0] IMPLICIT UTF8String, */
+ (2 << 6), /* [0] */
+ 0x80 | 1, /* L */
+ 128,
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+
+ /* beta [2] IMPLICIT INTEGER OPTIONAL */
+ (2 << 6) + 2, /* [2] */
+ 1, /* L */
+ 75,
+};
+
+uint8_t buf2_reconstr[] = {
+ 32 | ((2 << 6) + 1), /* [1], constructed */
+ 0x80 | 1, /* L */
+ 134,
+
+ /* string [0] IMPLICIT UTF8String, */
+ (2 << 6), /* [0] */
+ 0x80 | 1, /* L */
+ 128,
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+ 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z',
+
+ /* beta [2] IMPLICIT INTEGER OPTIONAL */
+ (2 << 6) + 2, /* [2] */
+ 1, /* L */
+ 75,
+};
+
+
+
+
+
+static void
+check(T_t *tp, uint8_t *buf, int size, int consumed) {
+ ber_dec_rval_t rval;
+
+ tp = memset(tp, 0, sizeof(*tp));
+
+ fprintf(stderr, "Buf %p (%d)\n", buf, size);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp, buf, size);
+ fprintf(stderr, "Returned code %d, consumed %d\n",
+ (int)rval.code, (int)rval.consumed);
+
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == consumed);
+
+ /*
+ assert(tp->string.size == 128);
+ assert(strncmp(tp->string.buf, "zz") == 0);
+ assert(strcmp(tp->b.choice.b1.buf, "z") == 0
+ && strcmp(tp->b.choice.b2.buf, "z") == 0);
+ */
+}
+
+int buf_pos;
+int buf_size;
+uint8_t *buf;
+
+static int
+buf_fill(const void *buffer, size_t size, void *app_key) {
+
+ if(buf_pos + size > buf_size) {
+ fprintf(stderr, "%d + %d > %d\n", buf_pos, (int)size, buf_size);
+ return -1;
+ }
+
+ memcpy(buf + buf_pos, buffer, size);
+ buf_pos += size;
+ fprintf(stderr, " written %d (%d)\n", (int)size, buf_pos);
+
+ return 0;
+}
+
+void
+compare(T_t *tp, uint8_t *cmp_buf, int cmp_buf_size) {
+ der_enc_rval_t erval;
+ int i;
+
+ buf_size = cmp_buf_size + 100;
+ buf = alloca(buf_size);
+ buf_pos = 0;
+
+ /*
+ * Try to re-create using DER encoding.
+ */
+ erval = der_encode(&asn1_DEF_T, tp, buf_fill, 0);
+ assert(erval.encoded != -1);
+ if(erval.encoded != cmp_buf_size) {
+ printf("%d != %d\n", erval.encoded, cmp_buf_size);
+ }
+ assert(erval.encoded == cmp_buf_size);
+ for(i = 0; i < cmp_buf_size; i++) {
+ if(buf[i] != cmp_buf[i]) {
+ fprintf(stderr, "Recreated buffer content mismatch:\n");
+ fprintf(stderr, "Byte %d, %x != %x (%d != %d)\n",
+ i,
+ buf[i], cmp_buf[i],
+ buf[i], cmp_buf[i]
+ );
+ }
+ assert(buf[i] == cmp_buf[i]);
+ }
+}
+
+static void
+partial_read(uint8_t *buf, int size) {
+ T_t t, *tp;
+ ber_dec_rval_t rval;
+ int i1, i2;
+ uint8_t *buf1 = alloca(size);
+ uint8_t *buf2 = alloca(size);
+ uint8_t *buf3 = alloca(size);
+
+ fprintf(stderr, "\nPartial read sequence...\n");
+
+ /*
+ * Divide the space (size) into three blocks in various combinations:
+ * |<----->i1<----->i2<----->|
+ * ^ buf ^ buf+size
+ * Try to read block by block.
+ */
+ for(i1 = 0; i1 < size; i1++) {
+ for(i2 = i1; i2 < size; i2++) {
+ uint8_t *chunk1 = buf;
+ int size1 = i1;
+ uint8_t *chunk2 = buf + size1;
+ int size2 = i2 - i1;
+ uint8_t *chunk3 = buf + size1 + size2;
+ int size3 = size - size1 - size2;
+
+ fprintf(stderr, "\n%d:{%d, %d, %d}...\n",
+ size, size1, size2, size3);
+
+ memset(buf1, 0, size);
+ memset(buf2, 0, size);
+ memset(buf3, 0, size);
+ memcpy(buf1, chunk1, size1);
+ memcpy(buf2, chunk2, size2);
+ memcpy(buf3, chunk3, size3);
+
+ tp = memset(&t, 0, sizeof(t));
+
+ fprintf(stderr, "=> Chunk 1 (%d):\n", size1);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf1, size1);
+ assert(rval.code == RC_WMORE);
+ assert(rval.consumed <= size1);
+ if(rval.consumed < size1) {
+ int leftover = size1 - rval.consumed;
+ memcpy(buf2, buf1 + rval.consumed, leftover);
+ memcpy(buf2 + leftover, chunk2, size2);
+ size2 += leftover;
+ }
+
+ fprintf(stderr, "=> Chunk 2 (%d):\n", size2);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf2, size2);
+ assert(rval.code == RC_WMORE);
+ assert(rval.consumed <= size2);
+ if(rval.consumed < size2) {
+ int leftover = size2 - rval.consumed;
+ memcpy(buf3, buf2 + rval.consumed, leftover);
+ memcpy(buf3 + leftover, chunk3, size3);
+ size3 += leftover;
+ }
+
+ fprintf(stderr, "=> Chunk 3 (%d):\n", size3);
+ rval = ber_decode(&asn1_DEF_T, (void **)&tp,
+ buf3, size3);
+ assert(rval.code == RC_OK);
+ assert(rval.consumed == size3);
+
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+ }
+ }
+}
+
+int
+main(int ac, char **av) {
+ T_t t;
+
+ /* Check exact buf0 */
+ check(&t, buf0, sizeof(buf0), sizeof(buf0));
+ compare(&t, buf0_reconstr, sizeof(buf0_reconstr));
+ asn_fprint(stderr, &asn1_DEF_T, &t);
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+
+ /* Check exact buf1 */
+ check(&t, buf1, sizeof(buf1), sizeof(buf1));
+ compare(&t, buf1_reconstr, sizeof(buf1_reconstr));
+ asn_fprint(stderr, &asn1_DEF_T, &t);
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+
+ /* Check slightly more than buf1 */
+ check(&t, buf1, sizeof(buf1) + 10, sizeof(buf1));
+ compare(&t, buf1_reconstr, sizeof(buf1_reconstr));
+ asn_fprint(stderr, &asn1_DEF_T, &t);
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+
+ /* Check exact buf2 */
+ check(&t, buf2, sizeof(buf2), sizeof(buf2));
+ compare(&t, buf2_reconstr, sizeof(buf2_reconstr));
+ asn_fprint(stderr, &asn1_DEF_T, &t);
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+
+ /* Check slightly more than buf2 */
+ check(&t, buf2, sizeof(buf2) + 10, sizeof(buf2));
+ compare(&t, buf2_reconstr, sizeof(buf2_reconstr));
+ asn_fprint(stderr, &asn1_DEF_T, &t);
+ asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
+
+ /* Split the buffer in parts and check decoder restartability */
+ partial_read(buf0, sizeof(buf0));
+
+ return 0;
+}
diff --git a/asn1c/tests/check-43.c b/asn1c/tests/check-43.c
new file mode 100644
index 00000000..e44218d8
--- /dev/null
+++ b/asn1c/tests/check-43.c
@@ -0,0 +1,24 @@
+#undef NDEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <assert.h>
+
+#include <Test-structure-1.h>
+#include <Sets.h>
+
+int
+main(int ac, char **av) {
+ Test_structure_1_t ts1;
+ Sets_t s1;
+
+ memset(&ts1, 0, sizeof(ts1));
+ memset(&s1, 0, sizeof(s1));
+
+ /*
+ * No plans to fill it up: just checking whether it compiles or not.
+ */
+
+ return 0;
+}
diff --git a/asn1c/tests/check-assembly.sh b/asn1c/tests/check-assembly.sh
new file mode 100755
index 00000000..a1756b4d
--- /dev/null
+++ b/asn1c/tests/check-assembly.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+#
+# This script is designed to quickly create lots of files in underlying
+# test-* directories, do lots of other magic stuff and exit cleanly.
+#
+
+# Compute the .asn1 spec name by the given file name.
+source=$(echo "$1" | sed -e 's/.*\///')
+testno=`echo "$source" | cut -f2 -d'-' | cut -f1 -d'.'`
+
+args=$(echo "$source" | sed -e 's/\.c$//')
+testdir=test-${args}
+
+OFS=$IFS
+IFS="."
+set $args
+shift
+IFS=$OFS
+
+if [ ! -d $testdir ]; then
+ mkdir $testdir || exit $?
+fi
+cd $testdir || exit $?
+ln -fs ../$source || exit $?
+# Compile the corresponding .asn1 spec.
+set -x
+../../asn1c \
+ -S ../../../skeletons \
+ -Wdebug-compiler "$@" \
+ ../../../tests/${testno}-*.asn1 || exit $?
+set +x
+
+# Create a Makefile for the project.
+cat > Makefile <<EOM
+CFLAGS=-I. -Wall -g ${CFLAGS} -DEMIT_ASN_DEBUG
+SRCS=`echo *.c`
+OBJS=\${SRCS:.c=.o}
+check-executable: \${OBJS}
+ \${CC} \${CFLAGS} -o check-executable \${OBJS}
+.SUFFIXES:
+.SUFFIXES: .c .o
+.c.o:
+ \${CC} \${CFLAGS} -o \$@ -c \$<
+check: check-executable
+ ./check-executable
+clean:
+ @rm -f *.o
+EOM
+
+# Perform building and checking
+make check || exit $?
+
+# Uncomment this to jeopardize debugging
+# make clean
+