libtasn1-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU libtasn1 branch, master, updated. libtasn1_4_8-14-g27c8a4c


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU libtasn1 branch, master, updated. libtasn1_4_8-14-g27c8a4c
Date: Fri, 8 Jul 2016 08:05:01 +0000 (UTC)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU libtasn1".

http://git.savannah.gnu.org/cgit/libtasn1.git/commit/?id=27c8a4cce51e9e9f5959389f52dd2889c4e788a6

The branch, master has been updated
       via  27c8a4cce51e9e9f5959389f52dd2889c4e788a6 (commit)
       via  ba21f8fe6a82bb8cfad22bd81639ea0920a082fe (commit)
      from  ee6662412559a06b3ec85878c617214bd045ccdd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 27c8a4cce51e9e9f5959389f52dd2889c4e788a6
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Fri Jul 8 10:04:20 2016 +0200

    tests: added unit tests for asn1_get_object_id_der()

commit ba21f8fe6a82bb8cfad22bd81639ea0920a082fe
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Fri Jul 8 09:59:31 2016 +0200

    asn1_get_object_id_der: doc update

-----------------------------------------------------------------------

Summary of changes:
 lib/decoding.c             |    3 +-
 tests/Makefile.am          |    4 +-
 tests/object-id-decoding.c |   89 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 3 deletions(-)
 create mode 100644 tests/object-id-decoding.c

diff --git a/lib/decoding.c b/lib/decoding.c
index 31c3708..2cd9ac3 100644
--- a/lib/decoding.c
+++ b/lib/decoding.c
@@ -384,7 +384,8 @@ _asn1_get_time_der (unsigned type, const unsigned char 
*der, int der_len, int *r
  * @str: Pre-allocated output buffer to put the textual object id in.
  * @str_size: Length of pre-allocated output buffer.
  *
- * Converts a DER encoded object identifier to its textual form.
+ * Converts a DER encoded object identifier to its textual form. This
+ * function expects the DER object identifier without the tag.
  *
  * Returns: %ASN1_SUCCESS on success, or an error.
  **/
diff --git a/tests/Makefile.am b/tests/Makefile.am
index eea4eda..379525e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -54,13 +54,13 @@ MOSTLYCLEANFILES = Test_parser_ERROR.asn
 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
+       ocsp-basic-response octet-string coding-long-oid object-id-decoding
 
 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
+       ocsp-basic-response octet-string coding-long-oid object-id-decoding
 
 TESTS_ENVIRONMENT = \
        ASN1PARSER=$(srcdir)/Test_parser.asn \
diff --git a/tests/object-id-decoding.c b/tests/object-id-decoding.c
new file mode 100644
index 0000000..e3e9669
--- /dev/null
+++ b/tests/object-id-decoding.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2016 Red Hat, 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/>.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "libtasn1.h"
+
+struct tv
+{
+  int der_len;
+  const unsigned char *der_str;
+  const char *oid;
+  int expected_error;
+};
+
+static const struct tv tv[] = {
+  {.der_len = 12,
+   .der_str = (void *) "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x05\x01",
+   .oid = "1.3.6.1.4.1.2312.9.5.1",
+   .expected_error = ASN1_SUCCESS},
+  {.der_len = 19,
+   .der_str =
+   (void *)
+   
"\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x07",
+   .oid = "1.3.6.1.4.1.2312.9.2.1467399257458.1.7",
+   .expected_error = ASN1_SUCCESS},
+};
+
+int
+main (int argc, char *argv[])
+{
+  char str[128];
+  int ret, ret_len;
+  size_t i;
+
+  for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
+    {
+      /* decode */
+      ret =
+       asn1_get_object_id_der (tv[i].der_str+1,
+                               tv[i].der_len-1, &ret_len, str,
+                               sizeof (str));
+      if (ret != tv[i].expected_error)
+       {
+         fprintf (stderr,
+                  "%d: asn1_get_object_id_der iter %lu: got %d expected %d\n",
+                  __LINE__, (unsigned long) i, ret, tv[i].expected_error);
+         return 1;
+       }
+
+      if (ret_len != tv[i].der_len-1)
+       {
+         fprintf (stderr,
+                  "%d: iter %lu: error in DER, length returned is %d, had 
%d\n",
+                  __LINE__, (unsigned long)i, ret_len, tv[i].der_len-1);
+         return 1;
+       }
+
+      if (strcmp (tv[i].oid, str) != 0)
+       {
+         fprintf (stderr,
+                  "%d: strcmp iter %lu: got invalid OID: %s, expected: %s\n",
+                  __LINE__, (unsigned long) i, str, tv[i].oid);
+         return 1;
+       }
+
+    }
+
+  return 0;
+}


hooks/post-receive
-- 
GNU libtasn1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]