summaryrefslogtreecommitdiff
path: root/lib/minitasn1/element.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/minitasn1/element.c')
-rw-r--r--lib/minitasn1/element.c90
1 files changed, 52 insertions, 38 deletions
diff --git a/lib/minitasn1/element.c b/lib/minitasn1/element.c
index ead899c953..4c871a1b31 100644
--- a/lib/minitasn1/element.c
+++ b/lib/minitasn1/element.c
@@ -34,9 +34,9 @@
#include "element.h"
void
-_asn1_hierarchical_name (ASN1_TYPE node, char *name, int name_size)
+_asn1_hierarchical_name (asn1_node node, char *name, int name_size)
{
- ASN1_TYPE p;
+ asn1_node p;
char tmp_name[64];
p = node;
@@ -45,7 +45,7 @@ _asn1_hierarchical_name (ASN1_TYPE node, char *name, int name_size)
while (p != NULL)
{
- if (p->name != NULL)
+ if (p->name[0] != 0)
{
_asn1_str_cpy (tmp_name, sizeof (tmp_name), name),
_asn1_str_cpy (name, name_size, p->name);
@@ -74,7 +74,7 @@ _asn1_hierarchical_name (ASN1_TYPE node, char *name, int name_size)
/* len: number of significant byte of value_out. */
/* Return: ASN1_MEM_ERROR or ASN1_SUCCESS */
/******************************************************************/
-asn1_retCode
+int
_asn1_convert_integer (const unsigned char *value, unsigned char *value_out,
int value_out_size, int *len)
{
@@ -127,9 +127,9 @@ _asn1_convert_integer (const unsigned char *value, unsigned char *value_out,
int
-_asn1_append_sequence_set (ASN1_TYPE node)
+_asn1_append_sequence_set (asn1_node node)
{
- ASN1_TYPE p, p2;
+ asn1_node p, p2;
char temp[10];
long n;
@@ -145,7 +145,7 @@ _asn1_append_sequence_set (ASN1_TYPE node)
p = p->right;
_asn1_set_right (p, p2);
- if (p->name == NULL)
+ if (p->name[0] == 0)
_asn1_str_cpy (temp, sizeof (temp), "?1");
else
{
@@ -267,11 +267,11 @@ _asn1_append_sequence_set (ASN1_TYPE node)
* %ASN1_ELEMENT_NOT_FOUND if @name is not a valid element, and
* %ASN1_VALUE_NOT_VALID if @ivalue has a wrong format.
**/
-asn1_retCode
-asn1_write_value (ASN1_TYPE node_root, const char *name,
+int
+asn1_write_value (asn1_node node_root, const char *name,
const void *ivalue, int len)
{
- ASN1_TYPE node, p, p2;
+ asn1_node node, p, p2;
unsigned char *temp, *value_temp = NULL, *default_temp = NULL;
int len2, k, k2, negative;
size_t i;
@@ -343,8 +343,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
{
if ((isdigit (value[0])) || (value[0] == '-'))
{
- value_temp =
- (unsigned char *) _asn1_malloc (SIZEOF_UNSIGNED_LONG_INT);
+ value_temp = malloc (SIZEOF_UNSIGNED_LONG_INT);
if (value_temp == NULL)
return ASN1_MEM_ALLOC_ERROR;
@@ -360,11 +359,9 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
{
if (type_field (p->type) == TYPE_CONSTANT)
{
- if ((p->name) && (!_asn1_strcmp (p->name, value)))
+ if (!_asn1_strcmp (p->name, value))
{
- value_temp =
- (unsigned char *)
- _asn1_malloc (SIZEOF_UNSIGNED_LONG_INT);
+ value_temp = malloc (SIZEOF_UNSIGNED_LONG_INT);
if (value_temp == NULL)
return ASN1_MEM_ALLOC_ERROR;
@@ -383,7 +380,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
}
else
{ /* len != 0 */
- value_temp = (unsigned char *) _asn1_malloc (len);
+ value_temp = malloc (len);
if (value_temp == NULL)
return ASN1_MEM_ALLOC_ERROR;
memcpy (value_temp, value, len);
@@ -397,7 +394,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
if (negative && (type_field (node->type) == TYPE_ENUMERATED))
{
- _asn1_free (value_temp);
+ free (value_temp);
return ASN1_VALUE_NOT_VALID;
}
@@ -420,11 +417,10 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
p = p->right;
if ((isdigit (p->value[0])) || (p->value[0] == '-'))
{
- default_temp =
- (unsigned char *) _asn1_malloc (SIZEOF_UNSIGNED_LONG_INT);
+ default_temp = malloc (SIZEOF_UNSIGNED_LONG_INT);
if (default_temp == NULL)
{
- _asn1_free (value_temp);
+ free (value_temp);
return ASN1_MEM_ALLOC_ERROR;
}
@@ -435,7 +431,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
{ /* is an identifier like v1 */
if (!(node->type & CONST_LIST))
{
- _asn1_free (value_temp);
+ free (value_temp);
return ASN1_VALUE_NOT_VALID;
}
p2 = node->down;
@@ -443,14 +439,12 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
{
if (type_field (p2->type) == TYPE_CONSTANT)
{
- if ((p2->name) && (!_asn1_strcmp (p2->name, p->value)))
+ if (!_asn1_strcmp (p2->name, p->value))
{
- default_temp =
- (unsigned char *)
- _asn1_malloc (SIZEOF_UNSIGNED_LONG_INT);
+ default_temp = malloc (SIZEOF_UNSIGNED_LONG_INT);
if (default_temp == NULL)
{
- _asn1_free (value_temp);
+ free (value_temp);
return ASN1_MEM_ALLOC_ERROR;
}
@@ -465,7 +459,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
}
if (p2 == NULL)
{
- _asn1_free (value_temp);
+ free (value_temp);
return ASN1_VALUE_NOT_VALID;
}
}
@@ -481,9 +475,9 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
if (k2 == len2)
_asn1_set_value (node, NULL, 0);
}
- _asn1_free (default_temp);
+ free (default_temp);
}
- _asn1_free (value_temp);
+ free (value_temp);
break;
case TYPE_OBJECT_ID:
for (i = 0; i < _asn1_strlen (value); i++)
@@ -562,7 +556,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
if (len == 0)
len = _asn1_strlen (value);
asn1_length_der ((len >> 3) + 2, NULL, &len2);
- temp = (unsigned char *) _asn1_malloc ((len >> 3) + 2 + len2);
+ temp = malloc ((len >> 3) + 2 + len2);
if (temp == NULL)
return ASN1_MEM_ALLOC_ERROR;
@@ -699,10 +693,10 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
* to store the result, and in this case @len will contain the number of
* bytes needed.
**/
-asn1_retCode
-asn1_read_value (ASN1_TYPE root, const char *name, void *ivalue, int *len)
+int
+asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len)
{
- ASN1_TYPE node, p, p2;
+ asn1_node node, p, p2;
int len2, len3;
int value_size = *len;
unsigned char *value = ivalue;
@@ -767,7 +761,7 @@ asn1_read_value (ASN1_TYPE root, const char *name, void *ivalue, int *len)
{
if (type_field (p2->type) == TYPE_CONSTANT)
{
- if ((p2->name) && (!_asn1_strcmp (p2->name, p->value)))
+ if (!_asn1_strcmp (p2->name, p->value))
{
if (_asn1_convert_integer
(p2->value, value, value_size,
@@ -877,11 +871,11 @@ asn1_read_value (ASN1_TYPE root, const char *name, void *ivalue, int *len)
* Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if
* @name is not a valid element.
**/
-asn1_retCode
-asn1_read_tag (ASN1_TYPE root, const char *name, int *tagValue,
+int
+asn1_read_tag (asn1_node root, const char *name, int *tagValue,
int *classValue)
{
- ASN1_TYPE node, p, pTag;
+ asn1_node node, p, pTag;
node = asn1_find_node (root, name);
if (node == NULL)
@@ -976,3 +970,23 @@ asn1_read_tag (ASN1_TYPE root, const char *name, int *tagValue,
return ASN1_SUCCESS;
}
+
+/**
+ * asn1_read_node_value:
+ * @node: pointer to a node.
+ * @data: a point to a asn1_data_node_st
+ *
+ * Returns the value a data node inside a asn1_node structure.
+ * The data returned should be handled as constant values.
+ *
+ * Returns: %ASN1_SUCCESS if the node exists.
+ **/
+int asn1_read_node_value (asn1_node node, asn1_data_node_st* data)
+{
+ data->name = node->name;
+ data->value = node->value;
+ data->value_len = node->value_len;
+ data->type = type_field(node->type);
+
+ return ASN1_SUCCESS;
+}