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_3_6-32-g220c35d


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU libtasn1 branch, master, updated. libtasn1_3_6-32-g220c35d
Date: Mon, 09 Jun 2014 09:32:09 +0000

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=220c35dfae010a503b3993044376f96d57e062a1

The branch, master has been updated
       via  220c35dfae010a503b3993044376f96d57e062a1 (commit)
       via  f908a06812970930ca6c0e8545e9d4c8e2d0c690 (commit)
       via  9ca7c7bf196c6572e115cf60ac51dfb7f4b2037c (commit)
       via  ec726e0058149f890023aadaeeaa6c77edfa32b3 (commit)
       via  2318607f3dad6e7a7009385917dafe6d02654189 (commit)
       via  8c34df998d95dd17f6349e4032aa84f5945d3a5e (commit)
      from  c7effec4b878feff6f74ae58ef5d57fdcaa6d843 (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 220c35dfae010a503b3993044376f96d57e062a1
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Jun 9 11:30:06 2014 +0200

    When encoding DER note the positions of the DER start and end.
    
    That will allow using asn1_der_decoding_startEnd() without
    performing decoding.

commit f908a06812970930ca6c0e8545e9d4c8e2d0c690
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Jun 9 11:29:22 2014 +0200

    Added new test that combines asn1_der_decoding_startEnd() with 
asn1_der_coding().

commit 9ca7c7bf196c6572e115cf60ac51dfb7f4b2037c
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Jun 9 11:28:53 2014 +0200

    Added copyright information

commit ec726e0058149f890023aadaeeaa6c77edfa32b3
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Jun 9 10:11:59 2014 +0200

    Added test for asn1_der_decoding_startEnd() after an asn1_dup_node().

commit 2318607f3dad6e7a7009385917dafe6d02654189
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Jun 9 10:11:19 2014 +0200

    When duplicating a node, keep the DER start and end information.

commit 8c34df998d95dd17f6349e4032aa84f5945d3a5e
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Jun 9 09:58:34 2014 +0200

    decoding: corrected the end position of the total structure.

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

Summary of changes:
 lib/coding.c                               |    3 +
 lib/decoding.c                             |    2 +-
 lib/structure.c                            |    2 +
 tests/Makefile.am                          |    7 +-
 tests/Test_choice.c                        |   20 +++
 tests/{choice.asn => coding-decoding2.asn} |    7 +
 tests/coding-decoding2.c                   |  199 ++++++++++++++++++++++++++++
 tests/copynode.c                           |   27 ++++
 8 files changed, 263 insertions(+), 4 deletions(-)
 copy tests/{choice.asn => coding-decoding2.asn} (79%)
 create mode 100644 tests/coding-decoding2.c

diff --git a/lib/coding.c b/lib/coding.c
index dc79fcc..2dd80ba 100644
--- a/lib/coding.c
+++ b/lib/coding.c
@@ -1035,6 +1035,7 @@ asn1_der_coding (asn1_node element, const char *name, 
void *ider, int *len,
   counter = 0;
   move = DOWN;
   p = node;
+
   while (1)
     {
 
@@ -1042,6 +1043,7 @@ asn1_der_coding (asn1_node element, const char *name, 
void *ider, int *len,
       max_len_old = max_len;
       if (move != UP)
        {
+          p->start = counter;
          err = _asn1_insert_tag_der (p, der, &counter, &max_len);
          if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR)
            goto error;
@@ -1297,6 +1299,7 @@ asn1_der_coding (asn1_node element, const char *name, 
void *ider, int *len,
 
       if ((move != DOWN) && (counter != counter_old))
        {
+          p->end = counter - 1;
          err = _asn1_complete_explicit_tag (p, der, &counter, &max_len);
          if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR)
            goto error;
diff --git a/lib/decoding.c b/lib/decoding.c
index f3ac191..f5a8fca 100644
--- a/lib/decoding.c
+++ b/lib/decoding.c
@@ -982,7 +982,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, 
int ider_len,
 
          /* the position in the DER structure this starts */
          p->start = counter;
-         p->end = total_len;
+         p->end = total_len - 1;
 
          if ((p->type & CONST_OPTION) || (p->type & CONST_DEFAULT))
            {
diff --git a/lib/structure.c b/lib/structure.c
index acd2f2e..ffb6aa5 100644
--- a/lib/structure.c
+++ b/lib/structure.c
@@ -423,6 +423,8 @@ _asn1_copy_structure3 (asn1_node source_node)
              _asn1_set_down (p_d_prev, p_d);
              continue;
            }
+         p_d->start = p_s->start;
+         p_d->end = p_s->end;
        }
 
       if (p_s == source_node)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4762a69..1dc9a98 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,7 +23,7 @@ AM_LDFLAGS = -no-install
 LDADD = ../lib/libtasn1.la ../gl/libgnu.la
 
 EXTRA_DIST = Test_parser.asn Test_tree.asn Test_tree_asn1_tab.c        \
-       Test_encoding.asn pkix.asn TestIndef.p12 choice.asn
+       Test_encoding.asn pkix.asn TestIndef.p12 choice.asn coding-decoding2.asn
 
 # For crlf.
 EXTRA_DIST += crlf.cer crl.der
@@ -35,16 +35,17 @@ 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
+       Test_encdec copynode coding-decoding2
 
 TESTS = Test_parser Test_tree Test_encoding Test_indefinite    \
        Test_errors Test_simple Test_overflow crlf threadsafety \
-       Test_strings Test_choice Test_encdec copynode
+       Test_strings Test_choice Test_encdec copynode coding-decoding2
 
 TESTS_ENVIRONMENT = \
        ASN1PARSER=$(srcdir)/Test_parser.asn \
        ASN1TREE=$(srcdir)/Test_tree.asn \
        ASN1CHOICE=$(srcdir)/choice.asn \
+       ASN1CODINGDECODING2=$(srcdir)/codingdecoding2.asn \
        ASN1PKIX=$(srcdir)/pkix.asn \
        ASN1CRLDER=$(srcdir)/crl.der \
        ASN1INDEF=$(srcdir)/TestIndef.p12 \
diff --git a/tests/Test_choice.c b/tests/Test_choice.c
index 8a0b5c1..c00d738 100644
--- a/tests/Test_choice.c
+++ b/tests/Test_choice.c
@@ -1,3 +1,23 @@
+/*
+ * Copyright (C) 2014 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/>.
+ *
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <libtasn1.h>
diff --git a/tests/choice.asn b/tests/coding-decoding2.asn
similarity index 79%
copy from tests/choice.asn
copy to tests/coding-decoding2.asn
index b309204..ee167a1 100644
--- a/tests/choice.asn
+++ b/tests/coding-decoding2.asn
@@ -8,6 +8,7 @@ Choice2 ::= CHOICE {
  oct2 OCTET STRING
 }
 
+
 Choice1 ::= CHOICE {
  int4 [0] INTEGER,
  choice2 Choice2,
@@ -20,4 +21,10 @@ Choice0 ::= CHOICE {
  int7 [1] INTEGER
 }
 
+Main ::= SEQUENCE {
+  pad1 INTEGER,
+  choice0 Choice0,
+  pad2 INTEGER
+}
+
 END
diff --git a/tests/coding-decoding2.c b/tests/coding-decoding2.c
new file mode 100644
index 0000000..e5d5f32
--- /dev/null
+++ b/tests/coding-decoding2.c
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2014 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/>.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <libtasn1.h>
+
+int
+main (int argc, char** argv)
+{
+  int result = 0;
+  asn1_node definitions = NULL, node1 = NULL, node2 = NULL;
+  char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
+  const char *choicefile = getenv ("ASN1CODINGDECODING2");
+  int start, end;
+
+  char data[1024];
+  int data_size = sizeof (data);
+
+  if (!choicefile)
+    choicefile = "coding-decoding2.asn";
+
+  /* Encode */
+  result = asn1_parser2tree (choicefile, &definitions, errorDescription);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  result = asn1_create_element (definitions, "TEST.Main", &node1);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  result = asn1_write_value (node1, "pad1", "\x01\x02\x03", 3);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  result = asn1_write_value (node1, "pad2", "\x00\x01", 2);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  result = asn1_write_value (node1, "choice0", "choice1", 1);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  result = asn1_write_value (node1, "choice0.choice1", "choice2", 1);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  result = asn1_write_value (node1, "choice0.choice1.choice2", "int1", 1);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  result = asn1_write_value (node1, "choice0.choice1.choice2.int1", "1234", 0);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  result = asn1_der_coding (node1, "", data, &data_size, errorDescription);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+  /*asn1_print_structure(stdout, node1, "", ASN1_PRINT_ALL);*/
+
+  result = asn1_der_decoding_startEnd (node1, data, data_size, 
"choice0.choice1.choice2.int1", &start, &end);
+  if (result != ASN1_SUCCESS)
+    {
+      asn1_perror (result);
+      printf ("Cannot find start End: %d\n", __LINE__);
+      exit (1);
+    }
+  if (start != 7 && end != 10)
+    {
+      printf("Error in start and end values for choice1.choice2.int1. Have: 
%d..%d\n", start, end);
+      exit(1);
+    }
+
+  result = asn1_der_decoding_startEnd (node1, data, data_size, 
"choice0.choice1", &start, &end);
+  if (result != ASN1_SUCCESS)
+    {
+      asn1_perror (result);
+      printf ("Cannot find start End: %d\n", __LINE__);
+      exit (1);
+    }
+  if (start != 7 && end != 10)
+    {
+      printf("Error in start and end values for choice1. Have: %d..%d\n", 
start, end);
+      exit(1);
+    }
+
+  result = asn1_der_decoding_startEnd (node1, data, data_size, "pad2", &start, 
&end);
+  if (result != ASN1_SUCCESS)
+    {
+      asn1_perror (result);
+      printf ("Cannot find start End\n");
+      exit (1);
+    }
+  if (start != 11 && end != 13)
+    {
+      printf("Error in start and end values for pad2. Have: %d..%d\n", start, 
end);
+      exit(1);
+    }
+
+  asn1_delete_structure (&node1);
+
+  /* Decode */
+  result = asn1_create_element (definitions, "TEST.Main", &node2);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d\n", __LINE__);
+      exit (1);
+    }
+
+#if 0
+  printf ("der:");
+  for (i = 0; i < data_size; i++)
+    printf ("%.2x ", (unsigned char) (data[i]));
+  printf ("\n");
+#endif
+
+  result = asn1_der_decoding (&node2, data, data_size, errorDescription);
+  if (result != ASN1_SUCCESS)
+    {
+      printf ("error in %d: %s\n", __LINE__, errorDescription);
+      exit (1);
+    }
+
+  result = asn1_der_decoding_startEnd (node2, data, data_size, 
"choice0.choice1.choice2.int1", &start, &end);
+  if (result != ASN1_SUCCESS)
+    {
+      asn1_perror (result);
+      printf ("Cannot find start End: %d\n", __LINE__);
+      exit (1);
+    }
+  if (start != 7 && end != 10)
+    {
+      printf("Error in start and end values for choice0.choice1.choice2.int1. 
Have: %d..%d\n", start, end);
+      exit(1);
+    }
+
+  result = asn1_der_decoding_startEnd (node2, data, data_size, "pad2", &start, 
&end);
+  if (result != ASN1_SUCCESS)
+    {
+      asn1_perror (result);
+      printf ("Cannot find start End: %d\n", __LINE__);
+      exit (1);
+    }
+  if (start != 11 && end != 13)
+    {
+      printf("Error in start and end values for pad2. Have: %d..%d\n", start, 
end);
+      exit(1);
+    }
+
+  asn1_delete_structure (&node2);
+  asn1_delete_structure (&definitions);
+
+  return 0;
+}
diff --git a/tests/copynode.c b/tests/copynode.c
index a24f1ce..29a8a51 100644
--- a/tests/copynode.c
+++ b/tests/copynode.c
@@ -46,6 +46,7 @@ main (int argc, char *argv[])
   asn1_node asn1_element = NULL, cpy_node = NULL;
   char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
   FILE *out, *fd;
+  int start, end;
   ssize_t size;
   int size2;
   const char *treefile = getenv ("ASN1PKIX");
@@ -176,6 +177,32 @@ main (int argc, char *argv[])
       exit(1);
     }
 
+  result = asn1_der_decoding_startEnd (asn1_element, buffer, size, 
"tbsCertList.issuer", &start, &end);
+  if (result != ASN1_SUCCESS)
+    {
+      asn1_perror (result);
+      printf ("Cannot find start End\n");
+      exit (1);
+    }
+  if (start != 24 && end != 291)
+    {
+      printf("Error in start and end values for issuer. Have: %d..%d\n", 
start, end);
+      exit(1);
+    }
+
+  result = asn1_der_decoding_startEnd (asn1_element, buffer, size, 
"signature", &start, &end);
+  if (result != ASN1_SUCCESS)
+    {
+      asn1_perror (result);
+      printf ("Cannot find start End\n");
+      exit (1);
+    }
+  if (start != 372 && end != 503)
+    {
+      printf("Error in start and end values for signature. Have: %d..%d\n", 
start, end);
+      exit(1);
+    }
+
   /* Clear the definition structures */
   asn1_delete_structure (&asn1_element);
   asn1_delete_structure (&cpy_node);


hooks/post-receive
-- 
GNU libtasn1



reply via email to

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