[gnome-keyring] Remove run time dependency on libtasn1.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] Remove run time dependency on libtasn1.
- Date: Sun, 11 Jul 2010 02:25:45 +0000 (UTC)
commit 33a420424b92c0ff8d633b3111ee63e8c6b74b8c
Author: Stef Walter <stef memberwebs com>
Date: Sun Jul 11 02:25:13 2010 +0000
Remove run time dependency on libtasn1.
* Required for build when we actually parse ASN.1 files.
configure.in | 2 +-
egg/egg-asn1x.c | 187 ++++++++++++++++++++++++++++++--
egg/egg-openssl.c | 1 -
gcr/Makefile.am | 1 -
gcr/gcr-parser.c | 1 -
gcr/tests/Makefile.am | 5 +-
gcr/tests/unit-test-parser.c | 1 -
pkcs11/gkm/gkm-certificate.c | 2 -
pkcs11/gkm/gkm-data-der.c | 1 -
pkcs11/gkm/gkm-data-der.h | 1 -
pkcs11/gkm/tests/unit-test-data-asn1.c | 1 -
pkcs11/roots-store/Makefile.am | 1 -
pkcs11/ssh-store/Makefile.am | 1 -
pkcs11/user-store/Makefile.am | 1 -
pkcs11/user-store/gkm-user-storage.c | 2 -
tool/Makefile.am | 1 -
16 files changed, 178 insertions(+), 31 deletions(-)
---
diff --git a/configure.in b/configure.in
index cbaf446..4d1d3a3 100644
--- a/configure.in
+++ b/configure.in
@@ -378,7 +378,7 @@ AC_SUBST([LIBTASN1_LIBS])
AC_SUBST([LIBTASN1_CFLAGS])
DAEMON_CFLAGS="$DAEMON_CFLAGS $LIBTASN1_CFLAGS"
-DAEMON_LIBS="$DAEMON_LIBS $LIBTASN1_LIBS"
+DAEMON_LIBS="$DAEMON_LIBS"
AC_PATH_PROG(ASN1PARSER, asn1Parser, no)
if test "$ASN1PARSER" = "no" ; then
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index 3a46ddf..cfe51a3 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -21,6 +21,30 @@
Author: Stef Walter <stef memberwebs com>
*/
+/*
+ * Some portions are:
+ *
+ * Copyright (C) 2004, 2006, 2008, 2009 Free Software Foundation
+ * Copyright (C) 2002 Fabio Fiorina
+ *
+ * This file is part of LIBTASN1.
+ *
+ * The LIBTASN1 library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ */
+
#include "config.h"
#include "egg-asn1x.h"
@@ -545,16 +569,125 @@ anode_calc_explicit (GNode *node)
*/
static gboolean
+anode_decode_cls_tag (const guchar *data, const guchar *end,
+ guchar *cls, gulong *tag, gint *cb)
+{
+ gint punt, ris, last;
+ gint n_data;
+
+ g_assert (end >= data);
+ g_assert (cls);
+ g_assert (cb);
+
+ n_data = end - data;
+
+ if (n_data < 2)
+ return FALSE;
+
+ *cls = data[0] & 0xE0;
+
+ /* short form */
+ if ((data[0] & 0x1F) != 0x1F) {
+ *cb = 1;
+ ris = data[0] & 0x1F;
+
+ /* Long form */
+ } else {
+ punt = 1;
+ ris = 0;
+ while (punt <= n_data && data[punt] & 128) {
+ int last = ris;
+ ris = ris * 128 + (data[punt++] & 0x7F);
+
+ /* wrapper around, and no bignums... */
+ if (ris < last)
+ return FALSE;
+ }
+
+ if (punt >= n_data)
+ return FALSE;
+
+ last = ris;
+ ris = ris * 128 + (data[punt++] & 0x7F);
+
+ /* wrapper around, and no bignums... */
+ if (ris < last)
+ return FALSE;
+
+ *cb = punt;
+ }
+
+ if (tag)
+ *tag = ris;
+
+ return TRUE;
+}
+
+static gint
+anode_decode_length (const guchar *data, const guchar *end, gint *cb)
+{
+ gint ans, last;
+ gint k, punt;
+ gint n_data;
+
+ g_assert (data);
+ g_assert (end);
+ g_assert (end >= data);
+ g_assert (cb);
+
+ *cb = 0;
+ n_data = end - data;
+
+ if (n_data == 0)
+ return 0;
+
+ /* short form */
+ if (!(data[0] & 128)) {
+ *cb = 1;
+ return data[0];
+
+ /* Long form */
+ } else {
+ k = data[0] & 0x7F;
+ punt = 1;
+
+ /* definite length method */
+ if (k) {
+ ans = 0;
+ while (punt <= k && punt < n_data) {
+ last = ans;
+ ans = ans * 256 + data[punt++];
+
+ /* we wrapped around, no bignum support... */
+ if (ans < last)
+ return -2;
+ }
+
+ /* indefinite length method */
+ } else {
+ ans = -1;
+ }
+
+ *cb = punt;
+ return ans;
+ }
+}
+
+static gboolean
anode_decode_cls_tag_len (const guchar *data, const guchar *end,
guchar *cls, gulong *tag, gint *off, gint *len)
{
gint cb1, cb2;
- gint der_len;
+
+ g_assert (data);
+ g_assert (end);
g_assert (end >= data);
- der_len = end - data;
- if (asn1_get_tag_der (data, der_len, cls, &cb1, tag) != ASN1_SUCCESS)
+ g_assert (off);
+ g_assert (len);
+
+ if (!anode_decode_cls_tag (data, end, cls, tag, &cb1))
return FALSE;
- *len = asn1_get_length_der (data + cb1, der_len - cb1, &cb2);
+ *len = anode_decode_length (data + cb1, end, &cb2);
if (*len < -1)
return FALSE;
*off = cb1 + cb2;
@@ -991,12 +1124,42 @@ egg_asn1x_decode (GNode *asn, gconstpointer data, gsize n_data)
* ENCODING
*/
+static void
+anode_encode_length (gulong len, guchar *ans, gint *cb)
+{
+ guchar temp[sizeof (gulong)];
+ gint k;
+
+ g_assert (cb);
+
+ /* short form */
+ if (len < 128) {
+ if (ans != NULL)
+ ans[0] = (unsigned char)len;
+ *cb = 1;
+
+ /* Long form */
+ } else {
+ k = 0;
+ while (len) {
+ temp[k++] = len & 0xFF;
+ len = len >> 8;
+ }
+ *cb = k + 1;
+ if (ans != NULL) {
+ ans[0] = ((unsigned char) k & 0x7F) + 128;
+ while (k--)
+ ans[*cb - 1 - k] = temp[k];
+ }
+ }
+}
+
static gint
anode_encode_cls_tag_len (guchar *data, gsize n_data, guchar cls,
gulong tag, gint len)
{
guchar temp[sizeof(gulong)];
- gint length;
+ gint cb;
gint off = 0;
gint k;
@@ -1025,9 +1188,9 @@ anode_encode_cls_tag_len (guchar *data, gsize n_data, guchar cls,
}
/* And now the length */
- length = n_data - off;
- asn1_length_der (len, data ? data + off : NULL, &length);
- off += length;
+ cb = n_data - off;
+ anode_encode_length (len, data ? data + off : NULL, &cb);
+ off += cb;
g_assert (!data || n_data >= off);
return off;
@@ -3641,9 +3804,9 @@ egg_asn1x_element_length (gconstpointer data, gsize n_data)
int cb, len;
gulong tag;
- if (asn1_get_tag_der (data, n_data, &cls, &cb, &tag) == ASN1_SUCCESS) {
+ if (anode_decode_cls_tag (data, (const guchar*)data + n_data, &cls, &tag, &cb)) {
counter += cb;
- len = asn1_get_length_der ((const guchar*)data + cb, n_data - cb, &cb);
+ len = anode_decode_length ((const guchar*)data + cb, (const guchar*)data + n_data, &cb);
counter += cb;
if (len >= 0) {
len += counter;
@@ -3667,11 +3830,11 @@ egg_asn1x_element_content (gconstpointer data, gsize n_data, gsize *n_content)
g_return_val_if_fail (n_content != NULL, NULL);
/* Now get the data out of this element */
- if (asn1_get_tag_der (data, n_data, &cls, &cb, &tag) != ASN1_SUCCESS)
+ if (!anode_decode_cls_tag (data, (const guchar*)data + n_data, &cls, &tag, &cb))
return NULL;
counter += cb;
- len = asn1_get_length_der ((const guchar*)data + cb, n_data - cb, &cb);
+ len = anode_decode_length ((const guchar*)data + cb, (const guchar*)data + n_data, &cb);
if (len < 0)
return NULL;
counter += cb;
diff --git a/egg/egg-openssl.c b/egg/egg-openssl.c
index 9794093..ef715dd 100644
--- a/egg/egg-openssl.c
+++ b/egg/egg-openssl.c
@@ -29,7 +29,6 @@
#include "egg-symkey.h"
#include <gcrypt.h>
-#include <libtasn1.h>
#include <glib.h>
diff --git a/gcr/Makefile.am b/gcr/Makefile.am
index 3ae7f57..e0ae779 100644
--- a/gcr/Makefile.am
+++ b/gcr/Makefile.am
@@ -71,7 +71,6 @@ libgcr_la_LIBADD = \
$(GOBJECT_LIBS) \
$(GLIB_LIBS) \
$(LIBGCRYPT_LIBS) \
- $(LIBTASN1_LIBS) \
$(GTK_LIBS)
gcr-marshal.h: gcr-marshal.list $(GLIB_GENMARSHAL)
diff --git a/gcr/gcr-parser.c b/gcr/gcr-parser.c
index 2a052e7..3d7febe 100644
--- a/gcr/gcr-parser.c
+++ b/gcr/gcr-parser.c
@@ -39,7 +39,6 @@
#include <stdlib.h>
#include <gcrypt.h>
-#include <libtasn1.h>
enum {
PROP_0,
diff --git a/gcr/tests/Makefile.am b/gcr/tests/Makefile.am
index 5600bff..d100859 100644
--- a/gcr/tests/Makefile.am
+++ b/gcr/tests/Makefile.am
@@ -30,8 +30,7 @@ ui_test_details_CFLAGS = \
ui_test_details_LDADD = \
$(top_builddir)/gcr/libgcr.la \
$(GTK_LIBS) \
- $(LIBGCRYPT_LIBS) \
- $(LIBTASN1_LIBS)
-
+ $(LIBGCRYPT_LIBS)
+
EXTRA_DIST = \
test-data
diff --git a/gcr/tests/unit-test-parser.c b/gcr/tests/unit-test-parser.c
index 7d4027b..16248d9 100644
--- a/gcr/tests/unit-test-parser.c
+++ b/gcr/tests/unit-test-parser.c
@@ -34,7 +34,6 @@
#include <glib.h>
#include <gcrypt.h>
-#include <libtasn1.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/pkcs11/gkm/gkm-certificate.c b/pkcs11/gkm/gkm-certificate.c
index 7f3dfd9..734535e 100644
--- a/pkcs11/gkm/gkm-certificate.c
+++ b/pkcs11/gkm/gkm-certificate.c
@@ -44,8 +44,6 @@
#include <glib/gi18n.h>
-#include <libtasn1.h>
-
enum {
PROP_0,
PROP_LABEL,
diff --git a/pkcs11/gkm/gkm-data-der.c b/pkcs11/gkm/gkm-data-der.c
index dbfef24..c91316e 100644
--- a/pkcs11/gkm/gkm-data-der.c
+++ b/pkcs11/gkm/gkm-data-der.c
@@ -35,7 +35,6 @@
#include <glib.h>
#include <gcrypt.h>
-#include <libtasn1.h>
/* -----------------------------------------------------------------------------
* QUARKS
diff --git a/pkcs11/gkm/gkm-data-der.h b/pkcs11/gkm/gkm-data-der.h
index 4a69091..d8321fe 100644
--- a/pkcs11/gkm/gkm-data-der.h
+++ b/pkcs11/gkm/gkm-data-der.h
@@ -26,7 +26,6 @@
#include <glib.h>
#include <gcrypt.h>
-#include <libtasn1.h>
#include "gkm-data-types.h"
diff --git a/pkcs11/gkm/tests/unit-test-data-asn1.c b/pkcs11/gkm/tests/unit-test-data-asn1.c
index 24c74e8..872a7e5 100644
--- a/pkcs11/gkm/tests/unit-test-data-asn1.c
+++ b/pkcs11/gkm/tests/unit-test-data-asn1.c
@@ -29,7 +29,6 @@
#include <glib.h>
#include <gcrypt.h>
-#include <libtasn1.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/pkcs11/roots-store/Makefile.am b/pkcs11/roots-store/Makefile.am
index ed0e26c..5d6108b 100644
--- a/pkcs11/roots-store/Makefile.am
+++ b/pkcs11/roots-store/Makefile.am
@@ -40,7 +40,6 @@ gkm_roots_store_standalone_la_LIBADD = \
$(GOBJECT_LIBS) \
$(GTHREAD_LIBS) \
$(GLIB_LIBS) \
- $(LIBTASN1_LIBS) \
$(LIBGCRYPT_LIBS)
diff --git a/pkcs11/ssh-store/Makefile.am b/pkcs11/ssh-store/Makefile.am
index b62e7f9..39d0965 100644
--- a/pkcs11/ssh-store/Makefile.am
+++ b/pkcs11/ssh-store/Makefile.am
@@ -42,7 +42,6 @@ gkm_ssh_store_standalone_la_LIBADD = \
$(GOBJECT_LIBS) \
$(GTHREAD_LIBS) \
$(GLIB_LIBS) \
- $(LIBTASN1_LIBS) \
$(LIBGCRYPT_LIBS)
diff --git a/pkcs11/user-store/Makefile.am b/pkcs11/user-store/Makefile.am
index 0ee726c..80aa20a 100644
--- a/pkcs11/user-store/Makefile.am
+++ b/pkcs11/user-store/Makefile.am
@@ -42,7 +42,6 @@ gkm_user_store_standalone_la_LIBADD = \
$(GOBJECT_LIBS) \
$(GTHREAD_LIBS) \
$(GLIB_LIBS) \
- $(LIBTASN1_LIBS) \
$(LIBGCRYPT_LIBS)
diff --git a/pkcs11/user-store/gkm-user-storage.c b/pkcs11/user-store/gkm-user-storage.c
index ea97be3..4b3a6ae 100644
--- a/pkcs11/user-store/gkm-user-storage.c
+++ b/pkcs11/user-store/gkm-user-storage.c
@@ -44,8 +44,6 @@
#include <glib/gstdio.h>
-#include <libtasn1.h>
-
#include <sys/file.h>
#include <sys/stat.h>
#include <errno.h>
diff --git a/tool/Makefile.am b/tool/Makefile.am
index 09c03bd..9bb405d 100644
--- a/tool/Makefile.am
+++ b/tool/Makefile.am
@@ -23,5 +23,4 @@ gnome_keyring_LDADD = \
$(GTHREAD_LIBS) \
$(GTK_LIBS) \
$(GCRYPT_LIBS) \
- $(LIBTASN1_LIBS) \
$(DAEMON_LIBS)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]