80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Daniel Axtens <dja@axtens.net>
80913e
Date: Fri, 1 May 2020 17:12:23 +1000
80913e
Subject: [PATCH] libtasn1: disable code not needed in grub
80913e
80913e
We don't expect to be able to write ASN.1, only read it,
80913e
so we can disable some code.
80913e
80913e
Do that with #if 0/#endif, rather than deletion. This means
80913e
that the difference between upstream and grub is smaller,
80913e
which should make updating libtasn1 easier in the future.
80913e
80913e
With these exclusions we also avoid the need for minmax.h,
80913e
which is convenient because it means we don't have to
80913e
import it from gnulib.
80913e
80913e
Signed-off-by: Daniel Axtens <dja@axtens.net>
80913e
---
80913e
 grub-core/lib/libtasn1/lib/coding.c    | 12 ++++++++++--
80913e
 grub-core/lib/libtasn1/lib/decoding.c  |  2 ++
80913e
 grub-core/lib/libtasn1/lib/element.c   |  4 ++--
80913e
 grub-core/lib/libtasn1/lib/errors.c    |  3 +++
80913e
 grub-core/lib/libtasn1/lib/structure.c | 10 ++++++----
80913e
 include/grub/libtasn1.h                | 15 +++++++++++++++
80913e
 6 files changed, 38 insertions(+), 8 deletions(-)
80913e
80913e
diff --git a/grub-core/lib/libtasn1/lib/coding.c b/grub-core/lib/libtasn1/lib/coding.c
b32e65
index 245ea64cf..52def5983 100644
80913e
--- a/grub-core/lib/libtasn1/lib/coding.c
80913e
+++ b/grub-core/lib/libtasn1/lib/coding.c
80913e
@@ -30,11 +30,11 @@
80913e
 #include "parser_aux.h"
80913e
 #include <gstr.h>
80913e
 #include "element.h"
80913e
-#include "minmax.h"
80913e
 #include <structure.h>
80913e
 
80913e
 #define MAX_TAG_LEN 16
80913e
 
80913e
+#if 0
80913e
 /******************************************************/
80913e
 /* Function : _asn1_error_description_value_not_found */
80913e
 /* Description: creates the ErrorDescription string   */
80913e
@@ -58,6 +58,7 @@ _asn1_error_description_value_not_found (asn1_node node,
80913e
   Estrcat (ErrorDescription, "' not found");
80913e
 
80913e
 }
80913e
+#endif
80913e
 
80913e
 /**
80913e
  * asn1_length_der:
80913e
@@ -244,6 +245,7 @@ asn1_encode_simple_der (unsigned int etype, const unsigned char *str,
80913e
   return ASN1_SUCCESS;
80913e
 }
80913e
 
80913e
+#if 0
80913e
 /******************************************************/
80913e
 /* Function : _asn1_time_der                          */
80913e
 /* Description: creates the DER coding for a TIME     */
80913e
@@ -281,7 +283,7 @@ _asn1_time_der (unsigned char *str, int str_len, unsigned char *der,
80913e
 
80913e
   return ASN1_SUCCESS;
80913e
 }
80913e
-
80913e
+#endif
80913e
 
80913e
 /*
80913e
 void
80913e
@@ -520,6 +522,7 @@ asn1_bit_der (const unsigned char *str, int bit_len,
80913e
 }
80913e
 
80913e
 
80913e
+#if 0
80913e
 /******************************************************/
80913e
 /* Function : _asn1_complete_explicit_tag             */
80913e
 /* Description: add the length coding to the EXPLICIT */
80913e
@@ -596,6 +599,7 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned char *der,
80913e
 
80913e
   return ASN1_SUCCESS;
80913e
 }
80913e
+#endif
80913e
 
80913e
 const tag_and_class_st _asn1_tags[] = {
80913e
   [ASN1_ETYPE_GENERALSTRING] =
80913e
@@ -648,6 +652,8 @@ const tag_and_class_st _asn1_tags[] = {
80913e
 
80913e
 unsigned int _asn1_tags_size = sizeof (_asn1_tags) / sizeof (_asn1_tags[0]);
80913e
 
80913e
+
80913e
+#if 0
80913e
 /******************************************************/
80913e
 /* Function : _asn1_insert_tag_der                    */
80913e
 /* Description: creates the DER coding of tags of one */
80913e
@@ -1413,3 +1419,5 @@ error:
80913e
   asn1_delete_structure (&node);
80913e
   return err;
80913e
 }
80913e
+
80913e
+#endif
80913e
\ No newline at end of file
80913e
diff --git a/grub-core/lib/libtasn1/lib/decoding.c b/grub-core/lib/libtasn1/lib/decoding.c
b32e65
index ff04eb778..42f9a92b5 100644
80913e
--- a/grub-core/lib/libtasn1/lib/decoding.c
80913e
+++ b/grub-core/lib/libtasn1/lib/decoding.c
80913e
@@ -1613,6 +1613,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len,
80913e
   return asn1_der_decoding2 (element, ider, &ider_len, 0, errorDescription);
80913e
 }
80913e
 
80913e
+#if 0
80913e
 /**
80913e
  * asn1_der_decoding_element:
80913e
  * @structure: pointer to an ASN1 structure
80913e
@@ -1643,6 +1644,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName,
80913e
 {
80913e
   return asn1_der_decoding(structure, ider, len, errorDescription);
80913e
 }
80913e
+#endif
80913e
 
80913e
 /**
80913e
  * asn1_der_decoding_startEnd:
80913e
diff --git a/grub-core/lib/libtasn1/lib/element.c b/grub-core/lib/libtasn1/lib/element.c
b32e65
index 997eb2725..539008d8e 100644
80913e
--- a/grub-core/lib/libtasn1/lib/element.c
80913e
+++ b/grub-core/lib/libtasn1/lib/element.c
80913e
@@ -191,7 +191,7 @@ _asn1_append_sequence_set (asn1_node node, struct node_tail_cache_st *pcache)
80913e
   return ASN1_SUCCESS;
80913e
 }
80913e
 
80913e
-
80913e
+#if 0
80913e
 /**
80913e
  * asn1_write_value:
80913e
  * @node_root: pointer to a structure
80913e
@@ -645,7 +645,7 @@ asn1_write_value (asn1_node node_root, const char *name,
80913e
 
80913e
   return ASN1_SUCCESS;
80913e
 }
80913e
-
80913e
+#endif
80913e
 
80913e
 #define PUT_VALUE( ptr, ptr_size, data, data_size) \
80913e
 	*len = data_size; \
80913e
diff --git a/grub-core/lib/libtasn1/lib/errors.c b/grub-core/lib/libtasn1/lib/errors.c
b32e65
index cee74daf7..42785e862 100644
80913e
--- a/grub-core/lib/libtasn1/lib/errors.c
80913e
+++ b/grub-core/lib/libtasn1/lib/errors.c
80913e
@@ -57,6 +57,8 @@ static const libtasn1_error_entry error_algorithms[] = {
80913e
   {0, 0}
80913e
 };
80913e
 
80913e
+
80913e
+#if 0
80913e
 /**
80913e
  * asn1_perror:
80913e
  * @error: is an error returned by a libtasn1 function.
80913e
@@ -73,6 +75,7 @@ asn1_perror (int error)
80913e
   const char *str = asn1_strerror (error);
80913e
   fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
80913e
 }
80913e
+#endif
80913e
 
80913e
 /**
80913e
  * asn1_strerror:
80913e
diff --git a/grub-core/lib/libtasn1/lib/structure.c b/grub-core/lib/libtasn1/lib/structure.c
b32e65
index 8189c56a4..fcfde01a3 100644
80913e
--- a/grub-core/lib/libtasn1/lib/structure.c
80913e
+++ b/grub-core/lib/libtasn1/lib/structure.c
80913e
@@ -76,7 +76,7 @@ _asn1_find_left (asn1_node_const node)
80913e
   return node->left;
80913e
 }
80913e
 
80913e
-
80913e
+#if 0
80913e
 int
80913e
 _asn1_create_static_structure (asn1_node_const pointer, char *output_file_name,
80913e
 			       char *vector_name)
80913e
@@ -155,7 +155,7 @@ _asn1_create_static_structure (asn1_node_const pointer, char *output_file_name,
80913e
 
80913e
   return ASN1_SUCCESS;
80913e
 }
80913e
-
80913e
+#endif
80913e
 
80913e
 /**
80913e
  * asn1_array2tree:
80913e
@@ -718,7 +718,7 @@ asn1_create_element (asn1_node_const definitions, const char *source_name,
80913e
   return res;
80913e
 }
80913e
 
80913e
-
80913e
+#if 0
80913e
 /**
80913e
  * asn1_print_structure:
80913e
  * @out: pointer to the output file (e.g. stdout).
80913e
@@ -1058,7 +1058,7 @@ asn1_print_structure (FILE * out, asn1_node_const structure, const char *name,
80913e
 	}
80913e
     }
80913e
 }
80913e
-
80913e
+#endif
80913e
 
80913e
 
80913e
 /**
80913e
@@ -1153,6 +1153,7 @@ asn1_find_structure_from_oid (asn1_node_const definitions, const char *oidValue)
80913e
   return NULL;			/* ASN1_ELEMENT_NOT_FOUND; */
80913e
 }
80913e
 
80913e
+#if 0
80913e
 /**
80913e
  * asn1_copy_node:
80913e
  * @dst: Destination asn1 node.
80913e
@@ -1202,6 +1203,7 @@ asn1_copy_node (asn1_node dst, const char *dst_name,
80913e
 
80913e
   return result;
80913e
 }
80913e
+#endif
80913e
 
80913e
 /**
80913e
  * asn1_dup_node:
80913e
diff --git a/include/grub/libtasn1.h b/include/grub/libtasn1.h
b32e65
index 6fd7a30dc..785eda2ae 100644
80913e
--- a/include/grub/libtasn1.h
80913e
+++ b/include/grub/libtasn1.h
80913e
@@ -319,6 +319,8 @@ typedef struct asn1_data_node_st asn1_data_node_st;
80913e
 /*  Functions definitions          */
80913e
 /***********************************/
80913e
 
80913e
+/* These functions are not used in grub and should not be referenced. */
80913e
+#if 0
80913e
 extern ASN1_API int
80913e
   asn1_parser2tree (const char *file,
80913e
 		      asn1_node * definitions, char *error_desc);
80913e
@@ -327,14 +329,17 @@ extern ASN1_API int
80913e
   asn1_parser2array (const char *inputFileName,
80913e
 		       const char *outputFileName,
80913e
 		       const char *vectorName, char *error_desc);
80913e
+#endif
80913e
 
80913e
 extern ASN1_API int
80913e
   asn1_array2tree (const asn1_static_node * array,
80913e
 		     asn1_node * definitions, char *errorDescription);
80913e
 
80913e
+#if 0
80913e
 extern ASN1_API void
80913e
   asn1_print_structure (FILE * out, asn1_node_const structure,
80913e
 			  const char *name, int mode);
80913e
+#endif
80913e
 
80913e
 extern ASN1_API int
80913e
   asn1_create_element (asn1_node_const definitions,
80913e
@@ -347,9 +352,11 @@ extern ASN1_API int asn1_delete_structure2 (asn1_node * structure, unsigned int
80913e
 extern ASN1_API int
80913e
   asn1_delete_element (asn1_node structure, const char *element_name);
80913e
 
80913e
+#if 0
80913e
 extern ASN1_API int
80913e
   asn1_write_value (asn1_node node_root, const char *name,
80913e
 		      const void *ivalue, int len);
80913e
+#endif
80913e
 
80913e
 extern ASN1_API int
80913e
   asn1_read_value (asn1_node_const root, const char *name,
80913e
@@ -365,9 +372,11 @@ extern ASN1_API int
80913e
 extern ASN1_API int
80913e
   asn1_number_of_elements (asn1_node_const element, const char *name, int *num);
80913e
 
80913e
+#if 0
80913e
 extern ASN1_API int
80913e
   asn1_der_coding (asn1_node_const element, const char *name,
80913e
 		     void *ider, int *len, char *ErrorDescription);
80913e
+#endif
80913e
 
80913e
 extern ASN1_API int
80913e
   asn1_der_decoding2 (asn1_node *element, const void *ider,
80913e
@@ -378,12 +387,14 @@ extern ASN1_API int
80913e
   asn1_der_decoding (asn1_node * element, const void *ider,
80913e
 		       int ider_len, char *errorDescription);
80913e
 
80913e
+#if 0
80913e
 /* Do not use. Use asn1_der_decoding() instead. */
80913e
 extern ASN1_API int
80913e
   asn1_der_decoding_element (asn1_node * structure,
80913e
 			       const char *elementName,
80913e
 			       const void *ider, int len,
80913e
 			       char *errorDescription) _ASN1_GCC_ATTR_DEPRECATED;
80913e
+#endif
80913e
 
80913e
 extern ASN1_API int
80913e
   asn1_der_decoding_startEnd (asn1_node element,
80913e
@@ -408,13 +419,17 @@ extern ASN1_API const char *asn1_find_structure_from_oid (asn1_node_const
80913e
 							    const char
80913e
 							    *oidValue);
80913e
 
80913e
+#if 0
80913e
 __LIBTASN1_PURE__
80913e
 extern ASN1_API const char *asn1_check_version (const char *req_version);
80913e
+#endif
80913e
 
80913e
 __LIBTASN1_PURE__
80913e
 extern ASN1_API const char *asn1_strerror (int error);
80913e
 
80913e
+#if 0
80913e
 extern ASN1_API void asn1_perror (int error);
80913e
+#endif
80913e
 
80913e
 #define ASN1_MAX_TAG_SIZE 4
80913e
 #define ASN1_MAX_LENGTH_SIZE 9