...
 
Commits (36)
......@@ -4,6 +4,7 @@
*~
ChangeLog
INSTALL
README
Makefile
Makefile.in
aclocal.m4
......
image: centos:7
before_script:
- yum install -y git make bison autoconf libtool automake gettext-devel glibc-devel gcc valgrind clang libasan-static libubsan
variables:
BUILD_IMAGES_PROJECT: gnutls/build-images
FEDORA_BUILD: buildenv-f29
DEBIAN_X86_CROSS_BUILD: buildenv-debian-x86-cross
GET_SOURCES_ATTEMPTS: "3"
# See http://doc.gitlab.com/ce/ci/yaml/ for documentation.
Build and Check (x86-64):
x86-64:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- git submodule update --init && make autoreconf && ./configure --disable-doc && make -j4 && make -j4 check
- git submodule update --init && make autoreconf && ./configure --disable-doc && make -j$(nproc) && make -j$(nproc) check
except:
- tags
tags:
- shared
Build and Check (x86):
x86:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_X86_CROSS_BUILD
script:
- yum install -y libgcc.i686 glibc-devel.i686
- git submodule update --init && make autoreconf &&
PKG_CONFIG_PATH="/usr/lib/pkgconfig/" CFLAGS="-O2 -g -m32" LDFLAGS="-m32" ./configure --build=i686-redhat-linux --target=i686-redhat-linux --disable-doc && make -j4 && make -j4 check
except:
- tags
- build=$(dpkg-architecture -qDEB_HOST_GNU_TYPE)
- host=i686-linux-gnu
- export CC_FOR_BUILD="gcc"
- export CC="$host-gcc"
- git submodule update --init && make autoreconf
- mkdir -p build
- cd build
- dash ../configure --build=$build --host=$host --disable-doc
- make -j$(nproc)
- make check -j$(nproc)
- cd ..
tags:
- shared
Build and Check with clang:
- docker
except:
- tags
artifacts:
expire_in: 1 week
when: on_failure
paths:
- build/guile/tests/*.log
- build/*.log
- build/tests/*.log
- build/tests/*/*.log
- build/tests/suite/*/*.log
retry: 1
clang:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- git submodule update --init && make autoreconf && CC=clang
./configure --disable-doc --disable-valgrind-tests && make -j4 && make check -j4
- git submodule update --init && make autoreconf && CC=clang
./configure --disable-doc --disable-valgrind-tests && make -j$(nproc) && make check -j$(nproc)
except:
- tags
tags:
- shared
Build and Check with asan:
asan:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- git submodule update --init && make autoreconf && CFLAGS="-fsanitize=address -g
-O2" LDFLAGS="-static-libasan" ./configure --disable-doc --disable-valgrind-tests && make -j4 && make check -j4
-O2" LDFLAGS="-static-libasan" ./configure --disable-doc --disable-valgrind-tests && make -j$(nproc) && make check -j$(nproc)
except:
- tags
tags:
- shared
Build and Check with ubsan:
image: fedora:24
ubsan:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- yum install -y git make autoconf libtool automake gettext-devel glibc-devel gcc valgrind clang libasan-static libubsan
- git submodule update --init && make autoreconf && CFLAGS="-fsanitize=undefined -fno-sanitize-recover -g
-O2" ./configure --disable-doc --disable-valgrind-tests && make -j4 && make check -j4
-O2" ./configure --disable-doc --disable-valgrind-tests && make -j$(nproc) && make check -j$(nproc)
tags:
- shared
except:
- tags
MinGW32:
image: fedora:24
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- dnf install -y wine.i686 mingw32-gcc util-linux
- mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
......@@ -68,3 +96,76 @@ MinGW32:
- build/tests/*.log
- build/tests/*/*.log
gnutls:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- ./.bootstrap &&
- ./configure --disable-doc --prefix=/usr --libdir=/usr/lib64 &&
make -j$(nproc) && make install
- git clone --depth 1 --branch master https://gitlab.com/gnutls/gnutls.git gnutls-git
- cd gnutls-git && git submodule update --init && ./bootstrap &&
./configure --disable-cxx --disable-guile --disable-doc && make -j$(nproc) &&
make -j $(nproc) check
tags:
- shared
except:
- tags
artifacts:
expire_in: 1 week
when: on_failure
paths:
- gnutls-git/guile/tests/*.log
- gnutls-git/tests/*.log
- gnutls-git/*.log
- gnutls-git/tests/*/*.log
- gnutls-git/tests/suite/*/*.log
static-analyzers:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- git submodule update --init && make autoreconf
- scan-build ./configure --disable-doc
- make -j$(nproc) syntax-check
- make -j$(nproc) -C gl
- make -j$(nproc) -C lib ASN1.lo
- scan-build --status-bugs -o scan-build-lib make -j$(nproc) -C lib
tags:
- shared
except:
- tags
artifacts:
expire_in: 1 week
when: on_failure
paths:
- scan-build-lib/
# Target to run code coverage on non-master branches. That is intended
# to ensure that compilation in master will not break the pages rule.
pages-test:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- git submodule update --init && make autoreconf
- ./configure --enable-gtk-doc --disable-gcc-warnings
- make -C doc libtasn1.html libtasn1.pdf
tags:
- shared
except:
- master
pages:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
script:
- git submodule update --init && make autoreconf
- ./configure --enable-gtk-doc --disable-gcc-warnings
- mkdir -p public
- make -C doc libtasn1.html libtasn1.pdf
- mv doc/libtasn1.pdf doc/libtasn1.html public/
- cp public/libtasn1.html public/index.html
tags:
- shared
artifacts:
when: on_success
paths:
- public
only:
- master
# libtasn1 -- Information about our contribution rules and coding style
Unless otherwise stated or implied the [GnuTLS contribution rules apply](https://gitlab.com/gnutls/gnutls/blob/master/CONTRIBUTING.md).
The following sections document any differences that apply:
# Function names
All the function names use underscore `_`, to separate words, functions like
asn1DoThat are not used. The exported function names start with the
`asn1_` prefix.
......@@ -62,4 +62,7 @@ abi-dump:
dist-hook: abi-check
make -C doc/ compare-makefile
.PHONY: abi-dump abi-check
README:
cp README.md README
.PHONY: abi-dump abi-check README
GNU Libtasn1 NEWS -*- outline -*-
* Noteworthy changes in release 4.14 (unreleased) [stable]
- Simplify ordering of SET OF elements.
- Several fixes in gtk-doc generation.
* Noteworthy changes in release 4.13 (released 2018-01-16) [stable]
- On indefinite string decoding, set a maximum level of allowed recursions
(3) to protect the BER decoder from a stack exhaustion.
......
|Branch|CI system|Status|
|:----:|:-------:|-----:|
|Master|Gitlab|[![build status](https://gitlab.com/gnutls/libtasn1/badges/master/build.svg)](https://gitlab.com/gnutls/libtasn1/commits/master)|
# libtasn1
This is GNU Libtasn1, a small ASN.1 library.
The C library (libtasn1.*) is licensed under the GNU Lesser General
......@@ -7,16 +13,21 @@ The command line tool, self tests, examples, and other auxilliary
files, are licensed under the GNU General Public License version 3.0
or later. See the file COPYING.
The manual is in doc/. You can also browse the manual and see updates
about the project on the homepage:
## Manual
The manual is in the `doc/` directory of the release. You can also browse
the manual online at:
https://gnutls.gitlab.io/libtasn1/
## Homepage
The project homepage at the gnu site is at:
http://www.gnu.org/software/libtasn1/
For any copyright year range specified as YYYY-ZZZZ in this package
note that the range specifies every single year in that closed interval.
----------------------------------------------------------------------
Copyright (C) 2002-2014 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
......@@ -38,9 +38,13 @@ exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^tests/TestIndef.p12$
exclude_file_name_regexp--sc_GPL_version = ^lib/libtasn1.h$$
exclude_file_name_regexp--sc_program_name = ^tests/|examples/
exclude_file_name_regexp--sc_prohibit_atoi_atof = ^src/asn1Coding.c|src/asn1Decoding.c$$
exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^tests/crlf.cer|tests/TestIndef.p12$$
exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^tests/.*.(cer|der|asn|txt|p12)|tests/TestIndef.p12|msvc/.*$$
exclude_file_name_regexp--sc_error_message_uppercase = ^tests/Test_tree.c$$
exclude_file_name_regexp--sc_unmarked_diagnostics = ^tests/Test_tree.c$$
exclude_file_name_regexp--sc_prohibit_undesirable_word_seq = ^msvc/.*$$
exclude_file_name_regexp--sc_trailing_blank = ^msvc/.*$$
exclude_file_name_regexp--sc_useless_cpp_parens = ^lib/libtasn1.h$$
exclude_file_name_regexp--sc_prohibit_intprops_without_use = ^lib/decoding.c$$
bootstrap-tools := autoconf,automake,libtool,bison
gpg_key_ID = b565716f
......
......@@ -98,6 +98,7 @@ if test "$gl_gcc_warnings" = yes; then
gl_WARN_ADD([-Wno-unused-parameter])
gl_WARN_ADD([-Wno-stack-protector]) # Some functions cannot be protected
gl_WARN_ADD([-fdiagnostics-show-option])
gl_WARN_ADD([-Wabi=11])
fi
AC_CONFIG_FILES([
......@@ -105,7 +106,6 @@ AC_CONFIG_FILES([
doc/Makefile
doc/cyclo/Makefile
doc/reference/Makefile
doc/reference/version.xml
examples/Makefile
gl/Makefile
lib/Makefile
......
......@@ -5,7 +5,7 @@ in order to avoid having people working on the same thing.
Current list:
+ Audit the code
* Avoid the usage of any global state in array2tree or parser2tree
functions.
functions.
* Allow extracting the time in a reasonable format (e.g. time_t)
* C structure generation instead of a single array
* CHOICE in CHOICE (e.g., RDN in byName in ResponderID in OCSP) cannot
......
......@@ -15,7 +15,7 @@ This manual is for GNU Libtasn1
which is a library for Abstract Syntax Notation One (ASN.1) and
Distinguished Encoding Rules (DER) manipulation.
Copyright @copyright{} 2001-2015 Free Software Foundation, Inc.
Copyright @copyright{} 2001-2019 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
......
## Process this file with automake to produce Makefile.in
# We require automake 1.6 at least.
AUTOMAKE_OPTIONS = 1.6
# -*- mode: makefile -*-
#
# Makefile.am - template makefile for gtk-doc module
# Copyright (C) 2007-2017 Stefan Sauer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the above copyright owner gives unlimited
# permission to copy, distribute and modify this Makefile.am template.
# You need not follow the terms of the GNU General Public License when
# using or distributing such Makefile.am files, even though portions of
# the text of the Makefile.am appear in them. The GNU General Public
# License (GPL) does govern all other use of the material that constitutes
# the Makefile.am template.
# This is a blank Makefile.am for using gtk-doc.
# Copy this to your project's API docs directory and modify the variables to
......@@ -14,9 +35,8 @@ DOC_MODULE=$(PACKAGE)
# Uncomment for versioned docs and specify the version of the module, e.g. '2'.
#DOC_MODULE_VERSION=2
# The top-level SGML file. You can change this if you want to.
DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
# The top-level XML file.
DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml
# Directories containing the source code.
# gtk-doc will search all .c and .h files beneath these paths
......@@ -24,25 +44,21 @@ DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
# e.g. DOC_SOURCE_DIR=$(top_srcdir)/gtk $(top_srcdir)/gdk
DOC_SOURCE_DIR=$(top_srcdir)/lib
# Extra options to pass to gtkdoc-scangobj. Not normally needed.
# Extra options to pass to gtkdoc-scangobj. Normally not needed.
SCANGOBJ_OPTIONS=
# Extra options to supply to gtkdoc-scan.
# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED"
SCAN_OPTIONS=--ignore-decorators=ASN1_API
# Extra options to supply to gtkdoc-mkdb.
# Extra options to supply to gtkdoc-mkdb
# e.g. MKDB_OPTIONS=--xml-mode --output-format=xml
MKDB_OPTIONS=--xml-mode --output-format=xml
# Extra options to supply to gtkdoc-mktmpl
# e.g. MKTMPL_OPTIONS=--only-section-tmpl
MKTMPL_OPTIONS=
# Extra options to supply to gtkdoc-mkhtml
MKHTML_OPTIONS=
# Extra options to supply to gtkdoc-fixref. Not normally needed.
# Extra options to supply to gtkdoc-fixref. Normally not needed.
# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html
FIXXREF_OPTIONS=
......@@ -64,13 +80,12 @@ IGNORE_HFILES=element.h gstr.h int.h parser_aux.h structure.h gllib
# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
HTML_IMAGES=
# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE).
# e.g. content_files=running.sgml building.sgml changes-2.0.sgml
# Extra files that are included by $(DOC_MAIN_SGML_FILE).
# e.g. content_files=running.xml building.xml changes-2.0.xml
content_files=
# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded
# These files must be listed here *and* in content_files
# e.g. expand_content_files=running.sgml
# Files where gtk-doc abbrevations (#GtkWidget) are expanded
# e.g. expand_content_files=running.xml
expand_content_files=
# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
......@@ -84,19 +99,10 @@ GTKDOC_LIBS=
# This includes the standard gtk-doc make rules, copied by gtkdocize.
include $(top_srcdir)/gtk-doc.make
# Other files to distribute
# e.g. EXTRA_DIST += version.xml.in
EXTRA_DIST +=
# Files not to distribute
# for --rebuild-types in $(SCAN_OPTIONS), e.g. $(DOC_MODULE).types
# for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt
#DISTCLEANFILES +=
# Comment this out if you want 'make check' to test you doc status
# Comment this out if you don't want 'make check' to test you doc status
# and run some sanity checks
if ENABLE_GTK_DOC
TESTS_ENVIRONMENT = cd $(srcdir) && \
TESTS_ENVIRONMENT = \
DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \
SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir)
#TESTS = $(GTKDOC_CHECK)
......
......@@ -3,19 +3,20 @@
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
[
<!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
<!ENTITY % gtkdocentities SYSTEM "xml/gtkdocentities.ent">
%gtkdocentities;
]>
<book id="index">
<bookinfo>
<title>GNU Libtasn1 API Reference Manual</title>
<title>&package_name; Reference Manual</title>
<releaseinfo>
for GNU Libtasn1 &version;.
for &package_string;.
The latest version of this documentation can be found on-line at
<ulink role="online-location" url="https://www.gnu.org/software/libtasn1/reference/">https://www.gnu.org/software/libtasn1/reference/</ulink>.
</releaseinfo>
</bookinfo>
<chapter id="intro">
<chapter>
<title>GNU Libtasn1 API Reference Manual</title>
<para>
......@@ -30,20 +31,30 @@
https://www.gnu.org/software/libtasn1/</ulink>.
</para>
<xi:include href="xml/libtasn1.xml"/>
<xi:include href="xml/libtasn1.xml"/>
</chapter>
<chapter id="object-tree">
<title>Object Hierarchy</title>
<xi:include href="xml/tree_index.sgml"/>
</chapter>
<index id="api-index-full">
<title>API Index</title>
<xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
</index>
<index role="deprecated">
<title>Index of deprecated symbols</title>
<index id="deprecated-api-index" role="deprecated">
<title>Index of deprecated API</title>
<xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
</index>
<index role="1.6">
<title>Index of new symbols in 1.6</title>
<index id="api-index-1-6" role="1.6">
<title>Index of new API in 1.6</title>
<xi:include href="xml/api-index-1.6.xml"><xi:fallback /></xi:include>
</index>
<index role="2.0">
<title>Index of new symbols in 2.0</title>
<index id="api-index-2-0" role="2.0">
<title>Index of new API in 2.0</title>
<xi:include href="xml/api-index-2.0.xml"><xi:fallback /></xi:include>
</index>
<!-- enable this when you use gobject introspection annotations
<xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
-->
</book>
This diff is collapsed.
This diff is collapsed.
......@@ -52,6 +52,15 @@ static const char *file_name; /* file to parse */
static void _asn1_yyerror (const char *);
static int _asn1_yylex(void);
#define SAFE_COPY(dst, dst_size, fmt, ...) { \
int _ret = snprintf(dst, dst_size, fmt, __VA_ARGS__); \
if (_ret != (int)strlen(dst)) \
{ \
fprintf(stderr, "%s:%u: Oversize value\n", \
file_name, line_number); \
exit(1); \
} \
}
%}
/* Prefix symbols and functions with _asn1_ */
......@@ -149,7 +158,7 @@ pos_num : NUM {snprintf($$,sizeof($$),"%s",$1);}
| '+' NUM {snprintf($$,sizeof($$),"%s",$2);}
;
neg_num : '-' NUM {snprintf($$,sizeof($$),"-%s",$2);}
neg_num : '-' NUM {SAFE_COPY($$,sizeof($$),"-%s",$2);}
;
pos_neg_num : pos_num {snprintf($$,sizeof($$),"%s",$1);}
......@@ -161,7 +170,7 @@ num_identifier : NUM {snprintf($$,sizeof($$),"%s",$1);}
;
int_identifier : NUM {snprintf($$,sizeof($$),"%s",$1);}
| '-' NUM {snprintf($$,sizeof($$),"-%s",$2);}
| '-' NUM {SAFE_COPY($$,sizeof($$),"-%s",$2);}
| IDENTIFIER {snprintf($$,sizeof($$),"%s",$1);}
;
......
......@@ -265,6 +265,9 @@ _asn1_time_der (unsigned char *str, int str_len, unsigned char *der,
int len_len;
int max_len;
if (der == NULL)
return ASN1_VALUE_NOT_VALID;
max_len = *der_len;
asn1_length_der (str_len, (max_len > 0) ? der : NULL, &len_len);
......@@ -342,6 +345,9 @@ _asn1_objectid_der (unsigned char *str, unsigned char *der, int *der_len)
max_len = *der_len;
if (der == NULL && max_len > 0)
return ASN1_VALUE_NOT_VALID;
temp = malloc (str_len + 2);
if (temp == NULL)
return ASN1_MEM_ALLOC_ERROR;
......@@ -473,6 +479,10 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned char *der,
int is_tag_implicit, len2, len3;
unsigned char temp[SIZEOF_UNSIGNED_INT];
if (der == NULL && *max_len > 0) {
return ASN1_VALUE_NOT_VALID;
}
is_tag_implicit = 0;
if (node->type & CONST_TAG)
......@@ -830,6 +840,39 @@ error:
return err;
}
struct vet
{
unsigned char *ptr;
int size;
};
static int setof_compar(const void *_e1, const void *_e2)
{
unsigned length;
const struct vet *e1 = _e1, *e2 = _e2;
int rval;
/* The encodings of the component values of a set-of value shall
* appear in ascending order, the encodings being compared
* as octet strings with the shorter components being
* padded at their trailing end with 0-octets.
* The padding octets are for comparison purposes and
* do not appear in the encodings.
*/
length = MIN(e1->size, e2->size);
rval = memcmp(e1->ptr, e2->ptr, length);
if (rval == 0 && e1->size != e2->size)
{
if (e1->size > e2->size)
rval = 1;
else if (e2->size > e1->size)
rval = -1;
}
return rval;
}
/******************************************************/
/* Function : _asn1_ordering_set_of */
/* Description: puts the elements of a SET OF type in */
......@@ -844,19 +887,19 @@ error:
static int
_asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node)
{
struct vet
{
int end;
struct vet *next, *prev;
};
int counter, len, len2, change;
struct vet *first, *last, *p_vet, *p2_vet;
int counter, len, len2;
struct vet *list = NULL, *tlist;
unsigned list_size = 0;
struct vet *p_vet;
asn1_node p;
unsigned char *temp, class;
unsigned long k, length;
unsigned char class;
unsigned i;
unsigned char *out = NULL;
int err;
if (der == NULL)
return ASN1_VALUE_NOT_VALID;
counter = 0;
if (type_field (node->type) != ASN1_ETYPE_SET_OF)
......@@ -873,33 +916,30 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node)
if ((p == NULL) || (p->right == NULL))
return ASN1_SUCCESS;
first = last = NULL;
while (p)
{
p_vet = malloc (sizeof (struct vet));
if (p_vet == NULL)
list_size++;
tlist = realloc (list, list_size*sizeof(struct vet));
if (tlist == NULL)
{
err = ASN1_MEM_ALLOC_ERROR;
goto error;
}
list = tlist;
p_vet = &list[list_size-1];
p_vet->next = NULL;
p_vet->prev = last;
if (first == NULL)
first = p_vet;
else
last->next = p_vet;
last = p_vet;
p_vet->ptr = der+counter;
p_vet->size = 0;
/* extraction of tag and length */
if (der_len - counter > 0)
{
err = asn1_get_tag_der (der + counter, der_len - counter, &class,
&len, NULL);
if (err != ASN1_SUCCESS)
goto error;
counter += len;
p_vet->size += len;
len2 = asn1_get_length_der (der + counter, der_len - counter, &len);
if (len2 < 0)
......@@ -908,84 +948,46 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node)
goto error;
}
counter += len + len2;
p_vet->size += len + len2;
}
else
{
err = ASN1_DER_ERROR;
goto error;
}
p_vet->end = counter;
p = p->right;
}
p_vet = first;
while (p_vet)
if (counter > der_len)
{
p2_vet = p_vet->next;
counter = 0;
while (p2_vet)
{
length = MIN(p_vet->end - counter, p2_vet->end - p_vet->end);
change = -1;
for (k = 0; k < length; k++)
if (der[counter + k] > der[p_vet->end + k])
{
change = 1;
break;
}
else if (der[counter + k] < der[p_vet->end + k])
{
change = 0;
break;
}
if ((change == -1)
&& ((p_vet->end - counter) > (p2_vet->end - p_vet->end)))
change = 1;
if (change == 1)
{
/* change position */
temp = malloc (p_vet->end - counter);
if (temp == NULL)
{
err = ASN1_MEM_ALLOC_ERROR;
goto error;
}
err = ASN1_DER_ERROR;
goto error;
}
memcpy (temp, der + counter, (p_vet->end) - counter);
memcpy (der + counter, der + (p_vet->end),
(p2_vet->end) - (p_vet->end));
memcpy (der + counter + (p2_vet->end) - (p_vet->end), temp,
(p_vet->end) - counter);
free (temp);
qsort(list, list_size, sizeof(struct vet), setof_compar);
p_vet->end = counter + (p2_vet->end - p_vet->end);
}
counter = p_vet->end;
out = malloc(der_len);
if (out == NULL)
{
err = ASN1_MEM_ERROR;
goto error;
}
p2_vet = p2_vet->next;
p_vet = p_vet->next;
}
/* the sum of p_vet->size == der_len */
counter = 0;
for (i=0;i<list_size;i++) {
p_vet = &list[i];
memcpy(out+counter, p_vet->ptr, p_vet->size);
counter += p_vet->size;
}
memcpy(der, out, der_len);
free(out);
if (p_vet != first)
p_vet->prev->next = NULL;
else
first = NULL;
free (p_vet);
p_vet = first;
}
return ASN1_SUCCESS;
err = ASN1_SUCCESS;
error:
while (first != NULL)
{
p_vet = first;
first = first->next;
free(p_vet);
}
free(list);
return err;
}
......@@ -1037,6 +1039,9 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
max_len = *len;
if (der == NULL && max_len > 0)
return ASN1_VALUE_NOT_VALID;
counter = 0;
move = DOWN;
p = node;
......@@ -1057,7 +1062,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
{
case ASN1_ETYPE_NULL:
max_len--;
if (max_len >= 0)
if (der != NULL && max_len >= 0)
der[counter] = 0;
counter++;
move = RIGHT;
......@@ -1078,7 +1083,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
goto error;
}
max_len -= 2;
if (max_len >= 0)
if (der != NULL && max_len >= 0)
{
der[counter++] = 1;
if (p->value[0] == 'F')
......@@ -1114,7 +1119,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
goto error;
}
max_len -= len2 + len3;
if (max_len >= 0)
if (der != NULL && max_len >= 0)
memcpy (der + counter, p->value, len3 + len2);
counter += len3 + len2;
}
......@@ -1186,7 +1191,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
goto error;
}
max_len -= len2 + len3;
if (max_len >= 0)
if (der != NULL && max_len >= 0)
memcpy (der + counter, p->value, len3 + len2);
counter += len3 + len2;
move = RIGHT;
......@@ -1228,7 +1233,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
}
asn1_length_der (counter - len2, temp, &len3);
max_len -= len3;
if (max_len >= 0)
if (der != NULL && max_len >= 0)
{
memmove (der + len2 + len3, der + len2, counter - len2);
memcpy (der + len2, temp, len3);
......@@ -1269,7 +1274,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
}
asn1_length_der (counter - len2, temp, &len3);
max_len -= len3;
if (max_len >= 0)
if (der != NULL && max_len >= 0)
{
memmove (der + len2 + len3, der + len2, counter - len2);
memcpy (der + len2, temp, len3);
......@@ -1292,7 +1297,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
goto error;
}
max_len -= len2;
if (max_len >= 0)
if (der != NULL && max_len >= 0)
memcpy (der + counter, p->value + len3, len2);
counter += len2;
move = RIGHT;
......
......@@ -306,7 +306,7 @@ asn1_get_octet_der (const unsigned char *der, int der_len,
}
/*-
/*-
* _asn1_get_time_der:
* @type: %ASN1_ETYPE_GENERALIZED_TIME or %ASN1_ETYPE_UTC_TIME
* @der: DER data to decode containing the time
......@@ -391,7 +391,7 @@ _asn1_get_time_der (unsigned type, const unsigned char *der, int der_len, int *r
}
/**
* asn1_get_objectid_der:
* asn1_get_object_id_der:
* @der: DER data to decode containing the OBJECT IDENTIFIER
* @der_len: Length of DER data to decode.
* @ret_len: Output variable containing the length of the DER data.
......@@ -1049,7 +1049,7 @@ asn1_der_decoding2 (asn1_node *element, const void *ider, int *max_ider_len,
if (ris == ASN1_SUCCESS)
ris =
extract_tag_der_recursive (p, der + counter, ider_len,
extract_tag_der_recursive (p, der + counter, ider_len,
&tag_len, &inner_tag_len, flags);
if (ris != ASN1_SUCCESS)
......@@ -1414,8 +1414,8 @@ asn1_der_decoding2 (asn1_node *element, const void *ider, int *max_ider_len,
break;
case ASN1_ETYPE_ANY:
/* Check indefinite lenth method in an EXPLICIT TAG */
if (!(flags & ASN1_DECODE_FLAG_STRICT_DER) && (p->type & CONST_TAG) &&
if (!(flags & ASN1_DECODE_FLAG_STRICT_DER) && (p->type & CONST_TAG) &&
tag_len == 2 && (der[counter - 1] == 0x80))
indefinite = 1;
else
......@@ -1555,7 +1555,7 @@ cleanup:
*
* Fill the structure *@element with values of a DER encoding
* string. The structure must just be created with function
* asn1_create_element().
* asn1_create_element().
*
* Note that the *@element variable is provided as a pointer for
* historical reasons.
......@@ -1697,7 +1697,7 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int ider_len,
int
asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element)
{
char name[2 * ASN1_MAX_NAME_SIZE + 1],
char name[2 * ASN1_MAX_NAME_SIZE + 2],
value[ASN1_MAX_NAME_SIZE];
int retCode = ASN1_SUCCESS, result;
int len, len2, len3;
......@@ -2159,7 +2159,7 @@ static int append(uint8_t **dst, unsigned *dst_size, const unsigned char *src, u
* @ber_len: the total length occupied by BER (may be %NULL)
* @have_tag: whether a DER tag is included
*
* Decodes a BER encoded type. The output is an allocated value
* Decodes a BER encoded type. The output is an allocated value
* of the data. This decodes BER STRINGS only. Other types are
* decoded as DER.
*
......@@ -2361,7 +2361,7 @@ cleanup:
* @str_len: the length of the data
* @ber_len: the total length occupied by BER (may be %NULL)
*
* Decodes a BER encoded type. The output is an allocated value
* Decodes a BER encoded type. The output is an allocated value
* of the data. This decodes BER STRINGS only. Other types are
* decoded as DER.
*
......
......@@ -135,7 +135,7 @@ _asn1_convert_integer (const unsigned char *value, unsigned char *value_out,
* The last element in the list may be provided in @pcache, to avoid
* traversing the list, an expensive operation in long lists.
*
* On success it returns in @pcache the added element (which is the
* On success it returns in @pcache the added element (which is the
* tail in the list of added elements).
*/
int
......@@ -699,7 +699,7 @@ asn1_write_value (asn1_node node_root, const char *name,
* @len: number of bytes of *value: value[0]..value[len-1]. Initialy
* holds the sizeof value.
*
* Returns the value of one element inside a structure.
* Returns the value of one element inside a structure.
* If an element is OPTIONAL and this returns
* %ASN1_ELEMENT_NOT_FOUND, it means that this element wasn't present
* in the der encoding that created the structure. The first element
......@@ -772,7 +772,7 @@ asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len)
* holds the sizeof value.
* @etype: The type of the value read (ASN1_ETYPE)
*
* Returns the type and value of one element inside a structure.
* Returns the type and value of one element inside a structure.
* If an element is OPTIONAL and this returns
* %ASN1_ELEMENT_NOT_FOUND, it means that this element wasn't present
* in the der encoding that created the structure. The first element
......
This diff is collapsed.
......@@ -393,9 +393,11 @@ asn1_delete_element (asn1_node structure, const char *element_name)
return asn1_delete_structure (&source_node);
}
#ifndef __clang_analyzer__
asn1_node
_asn1_copy_structure3 (asn1_node source_node)
{
/* FIXME: there may be a leak here */
asn1_node dest_node, p_s, p_d, p_d_prev;
int move;
......@@ -448,9 +450,17 @@ _asn1_copy_structure3 (asn1_node source_node)
}
}
while (p_s != source_node);
return dest_node;
}
#else
/* Non-production code */
asn1_node
_asn1_copy_structure3 (asn1_node source_node)
{
return NULL;
}
#endif /* __clang_analyzer__ */
static asn1_node
......@@ -1091,7 +1101,7 @@ asn1_number_of_elements (asn1_node element, const char *name, int *num)
const char *
asn1_find_structure_from_oid (asn1_node definitions, const char *oidValue)
{
char name[2 * ASN1_MAX_NAME_SIZE + 1];
char name[2 * ASN1_MAX_NAME_SIZE + 2];
char value[ASN1_MAX_NAME_SIZE];
asn1_node p;
int len;
......
dnl -*- mode: autoconf -*-
# -*- mode: autoconf -*-
#
# gtk-doc.m4 - configure macro to check for gtk-doc
# Copyright (C) 2003 James Henstridge
# 2007-2017 Stefan Sauer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the above copyright owner gives unlimited
# permission to copy, distribute and modify the configure scripts that
# are the output of Autoconf when processing the Macro. You need not
# follow the terms of the GNU General Public License when using or
# distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
# serial 1
# serial 2
dnl Usage:
dnl GTK_DOC_CHECK([minimum-gtk-doc-version])
......@@ -10,8 +35,24 @@ AC_DEFUN([GTK_DOC_CHECK],
AC_BEFORE([AC_PROG_LIBTOOL],[$0])dnl setup libtool first
AC_BEFORE([AM_PROG_LIBTOOL],[$0])dnl setup libtool first
ifelse([$1],[],[gtk_doc_requires="gtk-doc"],[gtk_doc_requires="gtk-doc >= $1"])
AC_MSG_CHECKING([for gtk-doc])
PKG_CHECK_EXISTS([$gtk_doc_requires],[have_gtk_doc=yes],[have_gtk_doc=no])
AC_MSG_RESULT($have_gtk_doc)
if test "$have_gtk_doc" = "no"; then
AC_MSG_WARN([
You will not be able to create source packages with 'make dist'
because $gtk_doc_requires is not found.])
fi
dnl check for tools we added during development
AC_PATH_PROG([GTKDOC_CHECK],[gtkdoc-check])
dnl Use AC_CHECK_PROG to avoid the check target using an absolute path that
dnl may not be writable by the user. Currently, automake requires that the
dnl test name must end in '.test'.
dnl https://bugzilla.gnome.org/show_bug.cgi?id=701638
AC_CHECK_PROG([GTKDOC_CHECK],[gtkdoc-check],[gtkdoc-check.test])
AC_PATH_PROG([GTKDOC_CHECK_PATH],[gtkdoc-check])
AC_PATH_PROGS([GTKDOC_REBASE],[gtkdoc-rebase],[true])
AC_PATH_PROG([GTKDOC_MKPDF],[gtkdoc-mkpdf])
......@@ -28,17 +69,22 @@ AC_DEFUN([GTK_DOC_CHECK],
[use gtk-doc to build documentation [[default=no]]]),,
[enable_gtk_doc=no])
if test x$enable_gtk_doc = xyes; then
ifelse([$1],[],
[PKG_CHECK_EXISTS([gtk-doc],,
AC_MSG_ERROR([gtk-doc not installed and --enable-gtk-doc requested]))],
[PKG_CHECK_EXISTS([gtk-doc >= $1],,
AC_MSG_ERROR([You need to have gtk-doc >= $1 installed to build $PACKAGE_NAME]))])
fi
AC_MSG_CHECKING([whether to build gtk-doc documentation])
AC_MSG_RESULT($enable_gtk_doc)
if test "x$enable_gtk_doc" = "xyes" && test "$have_gtk_doc" = "no"; then
AC_MSG_ERROR([
You must have $gtk_doc_requires installed to build documentation for
$PACKAGE_NAME. Please install gtk-doc or disable building the
documentation by adding '--disable-gtk-doc' to '[$]0'.])
fi
dnl don't check for glib if we build glib
if test "x$PACKAGE_NAME" != "xglib"; then
dnl don't fail if someone does not have glib
PKG_CHECK_MODULES(GTKDOC_DEPS, glib-2.0 >= 2.10.0 gobject-2.0 >= 2.10.0,,[:])
fi
dnl enable/disable output formats
AC_ARG_ENABLE([gtk-doc-html],
AS_HELP_STRING([--enable-gtk-doc-html],
......@@ -53,7 +99,12 @@ AC_DEFUN([GTK_DOC_CHECK],
enable_gtk_doc_pdf=no
fi
if test -z "$AM_DEFAULT_VERBOSITY"; then
AM_DEFAULT_VERBOSITY=1
fi
AC_SUBST([AM_DEFAULT_VERBOSITY])
AM_CONDITIONAL([HAVE_GTK_DOC], [test x$have_gtk_doc = xyes])
AM_CONDITIONAL([ENABLE_GTK_DOC], [test x$enable_gtk_doc = xyes])
AM_CONDITIONAL([GTK_DOC_BUILD_HTML], [test x$enable_gtk_doc_html = xyes])
AM_CONDITIONAL([GTK_DOC_BUILD_PDF], [test x$enable_gtk_doc_pdf = xyes])
......
......@@ -25,7 +25,7 @@ LDADD = ../lib/libtasn1.la ../gl/libgnu.la
EXTRA_DIST = Test_parser.asn Test_tree.asn Test_tree_asn1_tab.c mscat.asn \
Test_encoding.asn pkix.asn TestIndef.p12 choice.asn coding-decoding2.asn \
TestIndef2.p12 TestIndef3.der TestCertOctetOverflow.der \
cert-invalid-time.der \
cert-invalid-time.der setof.asn \
libtasn1.supp ocsp-basic-response.der spc_pe_image_data.der \
invalid-x509/id-000000.der invalid-x509/id-000001.der \
invalid-x509/id-000002.der invalid-x509/id-000003.der \
......@@ -60,14 +60,14 @@ check_PROGRAMS = Test_parser Test_tree Test_encoding Test_indefinite \
Test_errors Test_simple Test_overflow Test_strings Test_choice \
Test_encdec copynode coding-decoding2 strict-der Test_choice_ocsp \
ocsp-basic-response octet-string coding-long-oid object-id-decoding \
spc_pe_image_data
spc_pe_image_data setof
TESTS = Test_parser Test_tree Test_encoding Test_indefinite \
Test_errors Test_simple Test_overflow crlf threadsafety \
Test_strings Test_choice Test_encdec copynode coding-decoding2 \
strict-der Test_choice_ocsp decoding decoding-invalid-x509 \
ocsp-basic-response octet-string coding-long-oid object-id-decoding \
spc_pe_image_data decoding-invalid-pkcs7 coding
spc_pe_image_data decoding-invalid-pkcs7 coding setof
TESTS_ENVIRONMENT = \
ASN1PARSER=$(srcdir)/Test_parser.asn \
......@@ -75,6 +75,7 @@ TESTS_ENVIRONMENT = \
ASN1CHOICE=$(srcdir)/choice.asn \
ASN1CODINGDECODING2=$(srcdir)/coding-decoding2.asn \
ASN1PKIX=$(srcdir)/pkix.asn \
ASN1SETOF=$(srcdir)/setof.asn \
ASN1CRLDER=$(srcdir)/crl.der \
ASN1INDEF=$(srcdir)/TestIndef.p12 \
ASN1INDEF2=$(srcdir)/TestIndef2.p12 \
......
......@@ -164,8 +164,8 @@ main (int argc, char *argv[])
printf ("Cannot encode data (size %ld)\n", (long) size);
exit (1);
}
if (size2 != size || memcmp(buffer, buffer2, size) != 0)
if (size2 != size || memcmp(buffer, buffer2, size) != 0)
{
printf("DER encoded data differ!\n");
exit(1);
......
......@@ -56,7 +56,7 @@ static const struct tv tv[] = {
#define SSTR(x) sizeof(x)-1,x
static const struct tv ber[] = {
{ASN1_ETYPE_OCTET_STRING,
{ASN1_ETYPE_OCTET_STRING,
SSTR("\xa0\xa0"),
SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x00\x00")},
{ASN1_ETYPE_OCTET_STRING,
......
......@@ -144,8 +144,8 @@ main (int argc, char *argv[])
printf ("Cannot encode data (size %ld)\n", (long) size);
exit (1);
}
if (size2 != size || memcmp(buffer, buffer2, size) != 0)
if (size2 != size || memcmp(buffer, buffer2, size) != 0)
{
printf("DER encoded data differ!\n");
exit(1);
......@@ -170,8 +170,8 @@ main (int argc, char *argv[])
printf ("Cannot encode data (size %ld)\n", (long) size);
exit (1);
}
if (size2 != size || memcmp(buffer, buffer2, size) != 0)
if (size2 != size || memcmp(buffer, buffer2, size) != 0)
{
printf("DER encoded data differ!\n");
exit(1);
......
......@@ -106,8 +106,6 @@ main (int argc, char** argv)
exit (1);
}
len = sizeof(data);
result = asn1_read_value(node1, "tbsResponseData.responderID.byKey", data, &len);
if (result != ASN1_SUCCESS)
......
......@@ -939,7 +939,7 @@ pkcs-7-ContentInfo ::= SEQUENCE {
pkcs-7-DigestInfo ::= SEQUENCE {
digestAlgorithm AlgorithmIdentifier,
digest OCTET STRING
digest OCTET STRING
}
pkcs-7-SignedData ::= SEQUENCE {
......@@ -948,7 +948,7 @@ pkcs-7-SignedData ::= SEQUENCE {
encapContentInfo pkcs-7-EncapsulatedContentInfo,
certificates [0] IMPLICIT pkcs-7-CertificateSet OPTIONAL,
crls [1] IMPLICIT pkcs-7-CertificateRevocationLists OPTIONAL,
signerInfos pkcs-7-SignerInfos
signerInfos pkcs-7-SignerInfos
}
pkcs-7-DigestAlgorithmIdentifiers ::= SET OF AlgorithmIdentifier
......@@ -1263,7 +1263,7 @@ ResponseData ::= SEQUENCE {
ResponderID ::= CHOICE {
-- Changed to work with the libtasn1 parser.
byName [1] EXPLICIT RDNSequence, --Name
byKey [2] EXPLICIT OCTET STRING --SHA-1 hash of responder's public key
byKey [2] EXPLICIT OCTET STRING --SHA-1 hash of responder's public key
}
CertID ::= SEQUENCE {
......
TEST {}
DEFINITIONS IMPLICIT TAGS ::=
BEGIN
Seq ::= SEQUENCE {
val OCTET STRING
}
Set ::= SET OF Seq
END
/*
* Copyright (C) 2002-2018 Free Software Foundation, Inc.
*
* This file is part of LIBTASN1.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/****************************************************************/
/* File: Test_setof.c */
/* Description: Test writing of SET OF values and DER encoding. */
/****************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "libtasn1.h"
static unsigned char expected_der[] = {
0x31, 0x40, 0x30, 0x03, 0x04, 0x01, 0x01, 0x30,
0x03, 0x04, 0x01, 0x05, 0x30, 0x04, 0x04, 0x02,
0x00, 0x02, 0x30, 0x06, 0x04, 0x04, 0x00, 0x00,
0x00, 0x00, 0x30, 0x06, 0x04, 0x04, 0x00, 0x00,
0x00, 0x01, 0x30, 0x06, 0x04, 0x04, 0x00, 0x00,
0x00, 0x02, 0x30, 0x06, 0x04, 0x04, 0x00, 0x01,
0x00, 0x00, 0x30, 0x06, 0x04, 0x04, 0x01, 0x00,
0x00, 0x00, 0x30, 0x06, 0x04, 0x04, 0x01, 0x01,
0x00, 0x00
};
static unsigned char data[1024];
int data_size = sizeof (data);
int
main (int argc, char *argv[])
{
int result, verbose = 0;
asn1_node definitions = NULL;
asn1_node asn1_element = NULL;
char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
const char *treefile = getenv ("ASN1SETOF");
unsigned i;
if (argc > 1)
verbose = 1;
if (!treefile)
treefile = "setof.asn";
if (verbose != 0)
{
printf ("\n\n/****************************************/\n");
printf ("/* Test sequence : coding-decoding */\n");
printf ("/****************************************/\n\n");
}
/* Check version */
if (asn1_check_version ("0.3.3") == NULL)
printf ("\nLibrary version check ERROR:\n actual version: %s\n\n",
asn1_check_version (NULL));
result = asn1_parser2tree (treefile, &definitions, errorDescription);
if (result != ASN1_SUCCESS)
{
asn1_perror (result);
printf ("ErrorDescription = %s\n\n", errorDescription);
exit (1);
}
result = asn1_create_element (definitions, "TEST.Set", &asn1_element);
if (result != ASN1_SUCCESS)
{
fprintf (stderr, "asn1_create_element(): ");
asn1_perror (result);
exit (1);
}
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x00\x02", 2);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x00\x01\x00\x00", 4);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x00\x00\x00\x00", 4);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x00\x00\x00\x02", 4);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x00\x00\x00\x01", 4);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x01\x00\x00\x00", 4);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x01\x01\x00\x00", 4);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x05", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "", "NEW", 1);
assert(result == ASN1_SUCCESS);
result = asn1_write_value (asn1_element, "?LAST.val", "\x01", 1);
assert(result == ASN1_SUCCESS);
/* Clear the definition structures */
result = asn1_der_coding (asn1_element, "", data, &data_size, NULL);
if (result != ASN1_SUCCESS)
{
fprintf (stderr, "Encoding error.\n");
asn1_perror (result);
exit (1);
}
asn1_delete_structure (&asn1_element);
asn1_delete_structure (&definitions);
if (data_size != sizeof(expected_der) || memcmp(data, expected_der, data_size) != 0)
{
fprintf(stderr, "encoded data differ to expected [%d - %d]!\n", data_size, (int)sizeof(expected_der));
printf("static unsigned char got[] = {\n");
for (i=0;i<(unsigned)data_size;i++) {
printf("0x%.2x, ", (unsigned)data[i]);
if ((i+1) % 8 == 0)
printf("\n");
}
printf("};\n");
printf("static unsigned char expected[] = {\n");
for (i=0;i<(unsigned)sizeof(expected_der);i++) {
printf("0x%.2x, ", (unsigned)expected_der[i]);
if ((i+1) % 8 == 0)
printf("\n");
}
printf("};\n");
exit(1);
}
if (verbose)
printf ("Success\n");
exit (0);
}