summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2013-03-24 10:28:25 +0100
committerSimon Josefsson <simon@josefsson.org>2013-03-24 10:28:25 +0100
commit36f03daf3361187cc556a35dd36761302ccd94d5 (patch)
tree2bab7700940de89f49f038b7f6b093e5590099bf /lib
parentf36dd027a9002fcd2eec72aa3f445e03b8c7984d (diff)
downloadlibtasn1-36f03daf3361187cc556a35dd36761302ccd94d5.tar.gz
libtasn1-36f03daf3361187cc556a35dd36761302ccd94d5.tar.bz2
libtasn1-36f03daf3361187cc556a35dd36761302ccd94d5.zip
Indent code.
Diffstat (limited to 'lib')
-rw-r--r--lib/coding.c116
-rw-r--r--lib/decoding.c147
-rw-r--r--lib/element.c92
-rw-r--r--lib/element.h4
-rw-r--r--lib/gstr.c3
-rw-r--r--lib/gstr.h3
-rw-r--r--lib/int.h21
-rw-r--r--lib/libtasn1.h45
-rw-r--r--lib/parser_aux.c41
-rw-r--r--lib/structure.c37
-rw-r--r--lib/structure.h3
11 files changed, 275 insertions, 237 deletions
diff --git a/lib/coding.c b/lib/coding.c
index b83b61a..80adf85 100644
--- a/lib/coding.c
+++ b/lib/coding.c
@@ -140,9 +140,9 @@ _asn1_tag_der (unsigned char class, unsigned int tag_value,
{
temp[k++] = tag_value & 0x7F;
tag_value >>= 7;
-
- if (k > ASN1_MAX_TAG_SIZE-1)
- break; /* will not encode larger tags */
+
+ if (k > ASN1_MAX_TAG_SIZE - 1)
+ break; /* will not encode larger tags */
}
*ans_len = k + 1;
while (k--)
@@ -201,43 +201,43 @@ asn1_octet_der (const unsigned char *str, int str_len,
* Returns: %ASN1_SUCCESS if successful or an error value.
**/
int
-asn1_encode_simple_der (unsigned int etype, const unsigned char *str, unsigned int str_len,
- unsigned char *tl, unsigned int *tl_len)
+asn1_encode_simple_der (unsigned int etype, const unsigned char *str,
+ unsigned int str_len, unsigned char *tl,
+ unsigned int *tl_len)
{
int tag_len, len_len;
unsigned tlen;
unsigned char der_tag[ASN1_MAX_TAG_SIZE];
unsigned char der_length[ASN1_MAX_LENGTH_SIZE];
- unsigned char* p;
+ unsigned char *p;
if (str == NULL)
return ASN1_VALUE_NOT_VALID;
- if (ETYPE_OK(etype) == 0)
+ if (ETYPE_OK (etype) == 0)
return ASN1_VALUE_NOT_VALID;
/* doesn't handle constructed classes */
- if (ETYPE_CLASS(etype) != ASN1_CLASS_UNIVERSAL)
+ if (ETYPE_CLASS (etype) != ASN1_CLASS_UNIVERSAL)
return ASN1_VALUE_NOT_VALID;
- _asn1_tag_der (ETYPE_CLASS(etype), ETYPE_TAG(etype),
- der_tag, &tag_len);
+ _asn1_tag_der (ETYPE_CLASS (etype), ETYPE_TAG (etype), der_tag, &tag_len);
- asn1_length_der(str_len, der_length, &len_len);
+ asn1_length_der (str_len, der_length, &len_len);
if (tag_len <= 0 || len_len <= 0)
return ASN1_VALUE_NOT_VALID;
-
+
tlen = tag_len + len_len;
if (*tl_len < tlen)
return ASN1_MEM_ERROR;
p = tl;
- memcpy(p, der_tag, tag_len);
- p+=tag_len;
- memcpy(p, der_length, len_len);
-
+ memcpy (p, der_tag, tag_len);
+ p += tag_len;
+ memcpy (p, der_length, len_len);
+
*tl_len = tlen;
return ASN1_SUCCESS;
@@ -258,7 +258,8 @@ asn1_encode_simple_der (unsigned int etype, const unsigned char *str, unsigned i
/* ASN1_SUCCESS otherwise */
/******************************************************/
static int
-_asn1_time_der (unsigned char *str, int str_len, unsigned char *der, int *der_len)
+_asn1_time_der (unsigned char *str, int str_len, unsigned char *der,
+ int *der_len)
{
int len_len;
int max_len;
@@ -517,33 +518,56 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned char *der,
return ASN1_SUCCESS;
}
-const tag_and_class_st _asn1_tags[] =
-{
- [ASN1_ETYPE_GENERALSTRING] = {ASN1_TAG_GENERALSTRING, ASN1_CLASS_UNIVERSAL, "type:GENERALSTRING"},
- [ASN1_ETYPE_NUMERIC_STRING] = {ASN1_TAG_NUMERIC_STRING, ASN1_CLASS_UNIVERSAL, "type:NUMERIC_STR"},
- [ASN1_ETYPE_IA5_STRING] = {ASN1_TAG_IA5_STRING, ASN1_CLASS_UNIVERSAL, "type:IA5_STR"},
- [ASN1_ETYPE_TELETEX_STRING] = {ASN1_TAG_TELETEX_STRING, ASN1_CLASS_UNIVERSAL, "type:TELETEX_STR"},
- [ASN1_ETYPE_PRINTABLE_STRING] = {ASN1_TAG_PRINTABLE_STRING, ASN1_CLASS_UNIVERSAL, "type:PRINTABLE_STR"},
- [ASN1_ETYPE_UNIVERSAL_STRING] = {ASN1_TAG_UNIVERSAL_STRING, ASN1_CLASS_UNIVERSAL, "type:UNIVERSAL_STR"},
- [ASN1_ETYPE_BMP_STRING] = {ASN1_TAG_BMP_STRING, ASN1_CLASS_UNIVERSAL, "type:BMP_STR"},
- [ASN1_ETYPE_UTF8_STRING] = {ASN1_TAG_UTF8_STRING, ASN1_CLASS_UNIVERSAL, "type:UTF8_STR"},
- [ASN1_ETYPE_VISIBLE_STRING] = {ASN1_TAG_VISIBLE_STRING, ASN1_CLASS_UNIVERSAL, "type:VISIBLE_STR"},
- [ASN1_ETYPE_OCTET_STRING] = {ASN1_TAG_OCTET_STRING, ASN1_CLASS_UNIVERSAL, "type:OCT_STR"},
- [ASN1_ETYPE_BIT_STRING] = {ASN1_TAG_BIT_STRING, ASN1_CLASS_UNIVERSAL, "type:BIT_STR"},
- [ASN1_ETYPE_OBJECT_ID] = {ASN1_TAG_OBJECT_ID, ASN1_CLASS_UNIVERSAL, "type:OBJ_ID"},
- [ASN1_ETYPE_NULL] = {ASN1_TAG_NULL, ASN1_CLASS_UNIVERSAL, "type:NULL"},
- [ASN1_ETYPE_BOOLEAN] = {ASN1_TAG_BOOLEAN, ASN1_CLASS_UNIVERSAL, "type:BOOLEAN"},
- [ASN1_ETYPE_INTEGER] = {ASN1_TAG_INTEGER, ASN1_CLASS_UNIVERSAL, "type:INTEGER"},
- [ASN1_ETYPE_ENUMERATED] = {ASN1_TAG_ENUMERATED, ASN1_CLASS_UNIVERSAL, "type:ENUMERATED"},
- [ASN1_ETYPE_SEQUENCE] = {ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SEQUENCE"},
- [ASN1_ETYPE_SEQUENCE_OF] ={ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SEQ_OF"},
- [ASN1_ETYPE_SET] = {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SET"},
- [ASN1_ETYPE_SET_OF] = {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SET_OF"},
- [ASN1_ETYPE_GENERALIZED_TIME] = {ASN1_TAG_GENERALIZEDTime, ASN1_CLASS_UNIVERSAL, "type:GENERALIZED_TIME"},
- [ASN1_ETYPE_UTC_TIME] = {ASN1_TAG_UTCTime, ASN1_CLASS_UNIVERSAL, "type:UTC_TIME"},
+const tag_and_class_st _asn1_tags[] = {
+ [ASN1_ETYPE_GENERALSTRING] =
+ {ASN1_TAG_GENERALSTRING, ASN1_CLASS_UNIVERSAL, "type:GENERALSTRING"},
+ [ASN1_ETYPE_NUMERIC_STRING] =
+ {ASN1_TAG_NUMERIC_STRING, ASN1_CLASS_UNIVERSAL, "type:NUMERIC_STR"},
+ [ASN1_ETYPE_IA5_STRING] =
+ {ASN1_TAG_IA5_STRING, ASN1_CLASS_UNIVERSAL, "type:IA5_STR"},
+ [ASN1_ETYPE_TELETEX_STRING] =
+ {ASN1_TAG_TELETEX_STRING, ASN1_CLASS_UNIVERSAL, "type:TELETEX_STR"},
+ [ASN1_ETYPE_PRINTABLE_STRING] =
+ {ASN1_TAG_PRINTABLE_STRING, ASN1_CLASS_UNIVERSAL, "type:PRINTABLE_STR"},
+ [ASN1_ETYPE_UNIVERSAL_STRING] =
+ {ASN1_TAG_UNIVERSAL_STRING, ASN1_CLASS_UNIVERSAL, "type:UNIVERSAL_STR"},
+ [ASN1_ETYPE_BMP_STRING] =
+ {ASN1_TAG_BMP_STRING, ASN1_CLASS_UNIVERSAL, "type:BMP_STR"},
+ [ASN1_ETYPE_UTF8_STRING] =
+ {ASN1_TAG_UTF8_STRING, ASN1_CLASS_UNIVERSAL, "type:UTF8_STR"},
+ [ASN1_ETYPE_VISIBLE_STRING] =
+ {ASN1_TAG_VISIBLE_STRING, ASN1_CLASS_UNIVERSAL, "type:VISIBLE_STR"},
+ [ASN1_ETYPE_OCTET_STRING] =
+ {ASN1_TAG_OCTET_STRING, ASN1_CLASS_UNIVERSAL, "type:OCT_STR"},
+ [ASN1_ETYPE_BIT_STRING] =
+ {ASN1_TAG_BIT_STRING, ASN1_CLASS_UNIVERSAL, "type:BIT_STR"},
+ [ASN1_ETYPE_OBJECT_ID] =
+ {ASN1_TAG_OBJECT_ID, ASN1_CLASS_UNIVERSAL, "type:OBJ_ID"},
+ [ASN1_ETYPE_NULL] = {ASN1_TAG_NULL, ASN1_CLASS_UNIVERSAL, "type:NULL"},
+ [ASN1_ETYPE_BOOLEAN] =
+ {ASN1_TAG_BOOLEAN, ASN1_CLASS_UNIVERSAL, "type:BOOLEAN"},
+ [ASN1_ETYPE_INTEGER] =
+ {ASN1_TAG_INTEGER, ASN1_CLASS_UNIVERSAL, "type:INTEGER"},
+ [ASN1_ETYPE_ENUMERATED] =
+ {ASN1_TAG_ENUMERATED, ASN1_CLASS_UNIVERSAL, "type:ENUMERATED"},
+ [ASN1_ETYPE_SEQUENCE] =
+ {ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED,
+ "type:SEQUENCE"},
+ [ASN1_ETYPE_SEQUENCE_OF] =
+ {ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED,
+ "type:SEQ_OF"},
+ [ASN1_ETYPE_SET] =
+ {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SET"},
+ [ASN1_ETYPE_SET_OF] =
+ {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED,
+ "type:SET_OF"},
+ [ASN1_ETYPE_GENERALIZED_TIME] =
+ {ASN1_TAG_GENERALIZEDTime, ASN1_CLASS_UNIVERSAL, "type:GENERALIZED_TIME"},
+ [ASN1_ETYPE_UTC_TIME] =
+ {ASN1_TAG_UTCTime, ASN1_CLASS_UNIVERSAL, "type:UTC_TIME"},
};
-unsigned int _asn1_tags_size = sizeof(_asn1_tags)/sizeof(_asn1_tags[0]);
+unsigned int _asn1_tags_size = sizeof (_asn1_tags) / sizeof (_asn1_tags[0]);
/******************************************************/
/* Function : _asn1_insert_tag_der */
@@ -613,9 +637,9 @@ _asn1_insert_tag_der (asn1_node node, unsigned char *der, int *counter,
if (!is_tag_implicit)
{
if ((type_field (node->type) == ASN1_ETYPE_SEQUENCE) ||
- (type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF) ||
- (type_field (node->type) == ASN1_ETYPE_SET) ||
- (type_field (node->type) == ASN1_ETYPE_SET_OF))
+ (type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF)
+ || (type_field (node->type) == ASN1_ETYPE_SET)
+ || (type_field (node->type) == ASN1_ETYPE_SET_OF))
class |= ASN1_CLASS_STRUCTURED;
class_implicit = class;
tag_implicit = _asn1_strtoul (p->value, NULL, 10);
@@ -636,7 +660,7 @@ _asn1_insert_tag_der (asn1_node node, unsigned char *der, int *counter,
unsigned type = type_field (node->type);
switch (type)
{
- CASE_HANDLED_ETYPES:
+ CASE_HANDLED_ETYPES:
_asn1_tag_der (_asn1_tags[type].class, _asn1_tags[type].tag,
tag_der, &tag_len);
break;
diff --git a/lib/decoding.c b/lib/decoding.c
index efda4dc..4c4e232 100644
--- a/lib/decoding.c
+++ b/lib/decoding.c
@@ -85,14 +85,14 @@ asn1_get_length_der (const unsigned char *der, int der_len, int *len)
ans = 0;
while (punt <= k && punt < der_len)
{
- if (INT_MULTIPLY_OVERFLOW (ans, 256))
- return -2;
- ans *= 256;
+ if (INT_MULTIPLY_OVERFLOW (ans, 256))
+ return -2;
+ ans *= 256;
- if (INT_ADD_OVERFLOW (ans, ((unsigned)der[punt])))
- return -2;
+ if (INT_ADD_OVERFLOW (ans, ((unsigned) der[punt])))
+ return -2;
ans += der[punt];
- punt++;
+ punt++;
}
}
else
@@ -108,7 +108,7 @@ asn1_get_length_der (const unsigned char *der, int der_len, int *len)
if (ans >= INT_MAX || INT_ADD_OVERFLOW (sum, (*len)))
return -2;
sum += *len;
-
+
if (sum > der_len)
return -4;
@@ -152,28 +152,28 @@ asn1_get_tag_der (const unsigned char *der, int der_len,
while (punt <= der_len && der[punt] & 128)
{
- if (INT_MULTIPLY_OVERFLOW (ris, 128))
- return ASN1_DER_ERROR;
- ris *= 128;
+ if (INT_MULTIPLY_OVERFLOW (ris, 128))
+ return ASN1_DER_ERROR;
+ ris *= 128;
- if (INT_ADD_OVERFLOW (ris, ((unsigned)(der[punt] & 0x7F))))
- return ASN1_DER_ERROR;
- ris += (der[punt] & 0x7F);
- punt++;
+ if (INT_ADD_OVERFLOW (ris, ((unsigned) (der[punt] & 0x7F))))
+ return ASN1_DER_ERROR;
+ ris += (der[punt] & 0x7F);
+ punt++;
}
if (punt >= der_len)
return ASN1_DER_ERROR;
if (INT_MULTIPLY_OVERFLOW (ris, 128))
- return ASN1_DER_ERROR;
+ return ASN1_DER_ERROR;
ris *= 128;
- if (INT_ADD_OVERFLOW (ris, ((unsigned)(der[punt] & 0x7F))))
- return ASN1_DER_ERROR;
+ if (INT_ADD_OVERFLOW (ris, ((unsigned) (der[punt] & 0x7F))))
+ return ASN1_DER_ERROR;
ris += (der[punt] & 0x7F);
punt++;
-
+
*len = punt;
}
@@ -314,9 +314,9 @@ _asn1_get_objectid_der (const unsigned char *der, int der_len, int *ret_len,
leading = 0;
/* check for wrap around */
- if (INT_LEFT_SHIFT_OVERFLOW(val, 7))
- return ASN1_DER_ERROR;
-
+ if (INT_LEFT_SHIFT_OVERFLOW (val, 7))
+ return ASN1_DER_ERROR;
+
val = val << 7;
val |= der[len_len + k] & 0x7F;
@@ -328,10 +328,10 @@ _asn1_get_objectid_der (const unsigned char *der, int der_len, int *ret_len,
leading = 1;
}
}
-
- if (INT_ADD_OVERFLOW(len, len_len))
+
+ if (INT_ADD_OVERFLOW (len, len_len))
return ASN1_DER_ERROR;
-
+
*ret_len = len + len_len;
return ASN1_SUCCESS;
@@ -445,9 +445,9 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len,
if (!is_tag_implicit)
{
if ((type_field (node->type) == ASN1_ETYPE_SEQUENCE) ||
- (type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF) ||
- (type_field (node->type) == ASN1_ETYPE_SET) ||
- (type_field (node->type) == ASN1_ETYPE_SET_OF))
+ (type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF)
+ || (type_field (node->type) == ASN1_ETYPE_SET)
+ || (type_field (node->type) == ASN1_ETYPE_SET_OF))
class2 |= ASN1_CLASS_STRUCTURED;
class_implicit = class2;
tag_implicit = strtoul ((char *) p->value, NULL, 10);
@@ -521,7 +521,8 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len,
case ASN1_ETYPE_SET_OF:
case ASN1_ETYPE_GENERALIZED_TIME:
case ASN1_ETYPE_UTC_TIME:
- if ((class != _asn1_tags[type].class) || (tag != _asn1_tags[type].tag))
+ if ((class != _asn1_tags[type].class)
+ || (tag != _asn1_tags[type].tag))
return ASN1_DER_ERROR;
break;
@@ -1074,14 +1075,14 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len,
move = RIGHT;
break;
case ASN1_ETYPE_GENERALSTRING:
- case ASN1_ETYPE_NUMERIC_STRING:
- case ASN1_ETYPE_IA5_STRING:
- case ASN1_ETYPE_TELETEX_STRING:
- case ASN1_ETYPE_PRINTABLE_STRING:
- case ASN1_ETYPE_UNIVERSAL_STRING:
- case ASN1_ETYPE_BMP_STRING:
- case ASN1_ETYPE_UTF8_STRING:
- case ASN1_ETYPE_VISIBLE_STRING:
+ case ASN1_ETYPE_NUMERIC_STRING:
+ case ASN1_ETYPE_IA5_STRING:
+ case ASN1_ETYPE_TELETEX_STRING:
+ case ASN1_ETYPE_PRINTABLE_STRING:
+ case ASN1_ETYPE_UNIVERSAL_STRING:
+ case ASN1_ETYPE_BMP_STRING:
+ case ASN1_ETYPE_UTF8_STRING:
+ case ASN1_ETYPE_VISIBLE_STRING:
case ASN1_ETYPE_BIT_STRING:
len2 =
asn1_get_length_der (der + counter, len - counter, &len3);
@@ -1753,14 +1754,14 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName,
move = RIGHT;
break;
case ASN1_ETYPE_GENERALSTRING:
- case ASN1_ETYPE_NUMERIC_STRING:
- case ASN1_ETYPE_IA5_STRING:
- case ASN1_ETYPE_TELETEX_STRING:
- case ASN1_ETYPE_PRINTABLE_STRING:
- case ASN1_ETYPE_UNIVERSAL_STRING:
- case ASN1_ETYPE_BMP_STRING:
- case ASN1_ETYPE_UTF8_STRING:
- case ASN1_ETYPE_VISIBLE_STRING:
+ case ASN1_ETYPE_NUMERIC_STRING:
+ case ASN1_ETYPE_IA5_STRING:
+ case ASN1_ETYPE_TELETEX_STRING:
+ case ASN1_ETYPE_PRINTABLE_STRING:
+ case ASN1_ETYPE_UNIVERSAL_STRING:
+ case ASN1_ETYPE_BMP_STRING:
+ case ASN1_ETYPE_UTF8_STRING:
+ case ASN1_ETYPE_VISIBLE_STRING:
case ASN1_ETYPE_BIT_STRING:
len2 =
asn1_get_length_der (der + counter, len - counter, &len3);
@@ -1930,7 +1931,8 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName,
_asn1_set_value (p, temp, tlen + 1);
p2 = p->down;
while ((type_field (p2->type) == ASN1_ETYPE_TAG)
- || (type_field (p2->type) == ASN1_ETYPE_SIZE))
+ || (type_field (p2->type) ==
+ ASN1_ETYPE_SIZE))
p2 = p2->right;
if (p2->right == NULL)
_asn1_append_sequence_set (p);
@@ -2216,7 +2218,7 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len,
while (1)
{
if (p == NULL)
- return ASN1_DER_ERROR;
+ return ASN1_DER_ERROR;
ris = ASN1_SUCCESS;
@@ -2225,8 +2227,8 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len,
if (p->type & CONST_SET)
{
p2 = _asn1_find_up (p);
- if (p2 == NULL)
- return ASN1_DER_ERROR;
+ if (p2 == NULL)
+ return ASN1_DER_ERROR;
len2 = _asn1_strtol (p2->value, NULL, 10);
if (len2 == -1)
@@ -2261,8 +2263,8 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len,
else
{
p3 = p2->down;
- if (p3 == NULL)
- return ASN1_DER_ERROR;
+ if (p3 == NULL)
+ return ASN1_DER_ERROR;
ris =
_asn1_extract_tag_der (p3, der + counter,
@@ -2287,8 +2289,8 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len,
if (type_field (p->type) == ASN1_ETYPE_CHOICE)
{
p = p->down;
- if (p == NULL)
- return ASN1_DER_ERROR;
+ if (p == NULL)
+ return ASN1_DER_ERROR;
ris =
_asn1_extract_tag_der (p, der + counter, len - counter,
@@ -2350,14 +2352,14 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len,
case ASN1_ETYPE_INTEGER:
case ASN1_ETYPE_ENUMERATED:
case ASN1_ETYPE_GENERALSTRING:
- case ASN1_ETYPE_NUMERIC_STRING:
- case ASN1_ETYPE_IA5_STRING:
- case ASN1_ETYPE_TELETEX_STRING:
- case ASN1_ETYPE_PRINTABLE_STRING:
- case ASN1_ETYPE_UNIVERSAL_STRING:
- case ASN1_ETYPE_BMP_STRING:
- case ASN1_ETYPE_UTF8_STRING:
- case ASN1_ETYPE_VISIBLE_STRING:
+ case ASN1_ETYPE_NUMERIC_STRING:
+ case ASN1_ETYPE_IA5_STRING:
+ case ASN1_ETYPE_TELETEX_STRING:
+ case ASN1_ETYPE_PRINTABLE_STRING:
+ case ASN1_ETYPE_UNIVERSAL_STRING:
+ case ASN1_ETYPE_BMP_STRING:
+ case ASN1_ETYPE_UTF8_STRING:
+ case ASN1_ETYPE_VISIBLE_STRING:
case ASN1_ETYPE_BIT_STRING:
len2 =
asn1_get_length_der (der + counter, len - counter, &len3);
@@ -2585,8 +2587,8 @@ asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element)
p3 = p3->right;
}
- if ((!p3) || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) ||
- (p3->value == NULL))
+ if ((!p3) || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID)
+ || (p3->value == NULL))
{
retCode = ASN1_ERROR_TYPE_ANY;
break;
@@ -2879,11 +2881,12 @@ asn1_expand_octet_string (asn1_node definitions, asn1_node * element,
* Returns: %ASN1_SUCCESS if successful or an error value.
**/
int
-asn1_decode_simple_der (unsigned int etype, const unsigned char *der, unsigned int der_len,
- const unsigned char **str, unsigned int *str_len)
+asn1_decode_simple_der (unsigned int etype, const unsigned char *der,
+ unsigned int der_len, const unsigned char **str,
+ unsigned int *str_len)
{
int tag_len, len_len;
- const unsigned char* p;
+ const unsigned char *p;
unsigned char class;
unsigned long tag;
long ret;
@@ -2891,31 +2894,31 @@ asn1_decode_simple_der (unsigned int etype, const unsigned char *der, unsigned i
if (der == NULL || der_len == 0)
return ASN1_VALUE_NOT_VALID;
- if (ETYPE_OK(etype) == 0)
+ if (ETYPE_OK (etype) == 0)
return ASN1_VALUE_NOT_VALID;
/* doesn't handle constructed classes */
- if (ETYPE_CLASS(etype) != ASN1_CLASS_UNIVERSAL)
+ if (ETYPE_CLASS (etype) != ASN1_CLASS_UNIVERSAL)
return ASN1_VALUE_NOT_VALID;
p = der;
ret = asn1_get_tag_der (p, der_len, &class, &tag_len, &tag);
if (ret != ASN1_SUCCESS)
return ret;
-
- if (class != ETYPE_CLASS(etype) || tag != ETYPE_TAG(etype))
+
+ if (class != ETYPE_CLASS (etype) || tag != ETYPE_TAG (etype))
return ASN1_DER_ERROR;
p += tag_len;
der_len -= tag_len;
-
+
ret = asn1_get_length_der (p, der_len, &len_len);
- if (ret < 0)
+ if (ret < 0)
return ASN1_DER_ERROR;
p += len_len;
der_len -= len_len;
-
+
*str_len = ret;
*str = p;
diff --git a/lib/element.c b/lib/element.c
index 763ac58..93fa1f1 100644
--- a/lib/element.c
+++ b/lib/element.c
@@ -287,11 +287,10 @@ asn1_write_value (asn1_node node_root, const char *name,
asn1_delete_structure (&node);
return ASN1_SUCCESS;
}
-
- type = type_field(node->type);
- if ((type == ASN1_ETYPE_SEQUENCE_OF) && (value == NULL)
- && (len == 0))
+ type = type_field (node->type);
+
+ if ((type == ASN1_ETYPE_SEQUENCE_OF) && (value == NULL) && (len == 0))
{
p = node->down;
while ((type_field (p->type) == ASN1_ETYPE_TAG)
@@ -499,48 +498,48 @@ asn1_write_value (asn1_node node_root, const char *name,
_asn1_set_value (node, value, _asn1_strlen (value) + 1);
break;
case ASN1_ETYPE_UTC_TIME:
- {
- len = _asn1_strlen(value);
- if (len < 11)
+ {
+ len = _asn1_strlen (value);
+ if (len < 11)
+ return ASN1_VALUE_NOT_VALID;
+ for (k = 0; k < 10; k++)
+ if (!isdigit (value[k]))
return ASN1_VALUE_NOT_VALID;
- for (k = 0; k < 10; k++)
- if (!isdigit (value[k]))
+ switch (len)
+ {
+ case 11:
+ if (value[10] != 'Z')
return ASN1_VALUE_NOT_VALID;
- switch (len)
- {
- case 11:
- if (value[10] != 'Z')
- return ASN1_VALUE_NOT_VALID;
- break;
- case 13:
- if ((!isdigit (value[10])) || (!isdigit (value[11])) ||
- (value[12] != 'Z'))
- return ASN1_VALUE_NOT_VALID;
- break;
- case 15:
- if ((value[10] != '+') && (value[10] != '-'))
- return ASN1_VALUE_NOT_VALID;
- for (k = 11; k < 15; k++)
- if (!isdigit (value[k]))
- return ASN1_VALUE_NOT_VALID;
- break;
- case 17:
- if ((!isdigit (value[10])) || (!isdigit (value[11])))
+ break;
+ case 13:
+ if ((!isdigit (value[10])) || (!isdigit (value[11])) ||
+ (value[12] != 'Z'))
+ return ASN1_VALUE_NOT_VALID;
+ break;
+ case 15:
+ if ((value[10] != '+') && (value[10] != '-'))
+ return ASN1_VALUE_NOT_VALID;
+ for (k = 11; k < 15; k++)
+ if (!isdigit (value[k]))
return ASN1_VALUE_NOT_VALID;
- if ((value[12] != '+') && (value[12] != '-'))
+ break;
+ case 17:
+ if ((!isdigit (value[10])) || (!isdigit (value[11])))
+ return ASN1_VALUE_NOT_VALID;
+ if ((value[12] != '+') && (value[12] != '-'))
+ return ASN1_VALUE_NOT_VALID;
+ for (k = 13; k < 17; k++)
+ if (!isdigit (value[k]))
return ASN1_VALUE_NOT_VALID;
- for (k = 13; k < 17; k++)
- if (!isdigit (value[k]))
- return ASN1_VALUE_NOT_VALID;
- break;
- default:
- return ASN1_VALUE_NOT_FOUND;
- }
- _asn1_set_value (node, value, len);
- }
+ break;
+ default:
+ return ASN1_VALUE_NOT_FOUND;
+ }
+ _asn1_set_value (node, value, len);
+ }
break;
case ASN1_ETYPE_GENERALIZED_TIME:
- len = _asn1_strlen(value);
+ len = _asn1_strlen (value);
_asn1_set_value (node, value, len);
break;
case ASN1_ETYPE_OCTET_STRING:
@@ -711,7 +710,7 @@ asn1_write_value (asn1_node node_root, const char *name,
int
asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len)
{
- return asn1_read_value_type( root, name, ivalue, len, NULL);
+ return asn1_read_value_type (root, name, ivalue, len, NULL);
}
/**
@@ -777,8 +776,8 @@ asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len)
* bytes needed.
**/
int
-asn1_read_value_type (asn1_node root, const char *name, void *ivalue, int *len,
- unsigned int *etype)
+asn1_read_value_type (asn1_node root, const char *name, void *ivalue,
+ int *len, unsigned int *etype)
{
asn1_node node, p, p2;
int len2, len3;
@@ -1038,12 +1037,13 @@ asn1_read_tag (asn1_node root, const char *name, int *tagValue,
*
* Returns: %ASN1_SUCCESS if the node exists.
**/
-int asn1_read_node_value (asn1_node node, asn1_data_node_st* data)
+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);
-
+ data->type = type_field (node->type);
+
return ASN1_SUCCESS;
}
diff --git a/lib/element.h b/lib/element.h
index 3bd38bb..6e166dd 100644
--- a/lib/element.h
+++ b/lib/element.h
@@ -26,8 +26,8 @@
int _asn1_append_sequence_set (asn1_node node);
int _asn1_convert_integer (const unsigned char *value,
- unsigned char *value_out,
- int value_out_size, int *len);
+ unsigned char *value_out,
+ int value_out_size, int *len);
void _asn1_hierarchical_name (asn1_node node, char *name, int name_size);
diff --git a/lib/gstr.c b/lib/gstr.c
index 0558c77..d33704f 100644
--- a/lib/gstr.c
+++ b/lib/gstr.c
@@ -68,6 +68,7 @@ _asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src)
dest[str_size] = 0;
return str_size;
}
- else return 0;
+ else
+ return 0;
}
}
diff --git a/lib/gstr.h b/lib/gstr.h
index 672d59e..0c29f24 100644
--- a/lib/gstr.h
+++ b/lib/gstr.h
@@ -19,7 +19,8 @@
* 02110-1301, USA
*/
-unsigned int _asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src);
+unsigned int _asn1_str_cpy (char *dest, size_t dest_tot_size,
+ const char *src);
void _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src);
#define Estrcpy(x,y) _asn1_str_cpy(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y)
diff --git a/lib/int.h b/lib/int.h
index 3163d50..2d539d4 100644
--- a/lib/int.h
+++ b/lib/int.h
@@ -46,7 +46,7 @@
struct asn1_node_st
{
/* public fields: */
- char name[ASN1_MAX_NAME_SIZE+1]; /* Node name */
+ char name[ASN1_MAX_NAME_SIZE + 1]; /* Node name */
unsigned int name_hash;
unsigned int type; /* Node type */
unsigned char *value; /* Node value */
@@ -58,10 +58,11 @@ struct asn1_node_st
unsigned char small_value[ASN1_SMALL_VALUE_SIZE]; /* For small values */
};
-typedef struct tag_and_class_st {
+typedef struct tag_and_class_st
+{
unsigned tag;
unsigned class;
- const char* desc;
+ const char *desc;
} tag_and_class_st;
/* the types that are handled in _asn1_tags */
@@ -156,23 +157,25 @@ extern const tag_and_class_st _asn1_tags[];
/* Returns the first 8 bits. */
/* Used with the field type of asn1_node_st */
/****************************************/
-inline static unsigned int type_field(unsigned int ntype)
+inline static unsigned int
+type_field (unsigned int ntype)
{
return (ntype & 0xff);
}
/* To convert old types from a static structure */
-inline static unsigned int convert_old_type(unsigned int ntype)
+inline static unsigned int
+convert_old_type (unsigned int ntype)
{
-unsigned int type = ntype & 0xff;
+ unsigned int type = ntype & 0xff;
if (type == ASN1_ETYPE_TIME)
{
if (ntype & CONST_UTC)
- type = ASN1_ETYPE_UTC_TIME;
+ type = ASN1_ETYPE_UTC_TIME;
else
- type = ASN1_ETYPE_GENERALIZED_TIME;
+ type = ASN1_ETYPE_GENERALIZED_TIME;
- ntype &= ~(CONST_UTC|CONST_GENERALIZED);
+ ntype &= ~(CONST_UTC | CONST_GENERALIZED);
ntype &= 0xffffff00;
ntype |= type;
diff --git a/lib/libtasn1.h b/lib/libtasn1.h
index 5cdc3ff..3856097 100644
--- a/lib/libtasn1.h
+++ b/lib/libtasn1.h
@@ -21,19 +21,19 @@
*/
#ifndef LIBTASN1_H
-# define LIBTASN1_H
-
-# ifndef ASN1_API
-# if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
-# define ASN1_API __attribute__((__visibility__("default")))
-# elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC
-# define ASN1_API __declspec(dllexport)
-# elif defined _MSC_VER && ! defined ASN1_STATIC
-# define ASN1_API __declspec(dllimport)
-# else
-# define ASN1_API
-# endif
-# endif
+#define LIBTASN1_H
+
+#ifndef ASN1_API
+#if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
+#define ASN1_API __attribute__((__visibility__("default")))
+#elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC
+#define ASN1_API __declspec(dllexport)
+#elif defined _MSC_VER && ! defined ASN1_STATIC
+#define ASN1_API __declspec(dllimport)
+#else
+#define ASN1_API
+#endif
+#endif
#include <sys/types.h>
#include <time.h>
@@ -172,7 +172,7 @@ extern "C"
{
const char *name; /* Node name */
const void *value; /* Node value */
- unsigned int value_len; /* Node value size */
+ unsigned int value_len; /* Node value size */
unsigned int type; /* Node value type (ASN1_ETYPE_*) */
};
typedef struct asn1_data_node_st asn1_data_node_st;
@@ -227,10 +227,10 @@ extern "C"
extern ASN1_API int
asn1_read_value_type (asn1_node root, const char *name,
- void *ivalue, int *len, unsigned int* etype);
+ void *ivalue, int *len, unsigned int *etype);
extern ASN1_API int
- asn1_read_node_value (asn1_node node, asn1_data_node_st* data);
+ asn1_read_node_value (asn1_node node, asn1_data_node_st * data);
extern ASN1_API int
asn1_number_of_elements (asn1_node element, const char *name, int *num);
@@ -293,12 +293,15 @@ extern "C"
/* Other utility functions. */
extern ASN1_API
- int asn1_decode_simple_der (unsigned int etype, const unsigned char *der, unsigned int der_len,
- const unsigned char **str, unsigned int *str_len);
+ int asn1_decode_simple_der (unsigned int etype, const unsigned char *der,
+ unsigned int der_len,
+ const unsigned char **str,
+ unsigned int *str_len);
extern ASN1_API int
- asn1_encode_simple_der (unsigned int etype, const unsigned char *str, unsigned int str_len,
- unsigned char *tl, unsigned int *tl_len);
+ asn1_encode_simple_der (unsigned int etype, const unsigned char *str,
+ unsigned int str_len, unsigned char *tl,
+ unsigned int *tl_len);
extern ASN1_API asn1_node
asn1_find_node (asn1_node pointer, const char *name);
@@ -332,7 +335,7 @@ extern "C"
/* Compatibility types */
-typedef int asn1_retCode; /* type returned by libtasn1 functions */
+ typedef int asn1_retCode; /* type returned by libtasn1 functions */
#define node_asn_struct asn1_node_st
#define node_asn asn1_node_st
diff --git a/lib/parser_aux.c b/lib/parser_aux.c
index 50238d2..69681e9 100644
--- a/lib/parser_aux.c
+++ b/lib/parser_aux.c
@@ -119,12 +119,12 @@ asn1_find_node (asn1_node pointer, const char *name)
n_start = n_end;
n_start++;
- nhash = hash_pjw_bare(n, nsize);
+ nhash = hash_pjw_bare (n, nsize);
}
else
{
nsize = _asn1_str_cpy (n, sizeof (n), n_start);
- nhash = hash_pjw_bare(n, nsize);
+ nhash = hash_pjw_bare (n, nsize);
n_start = NULL;
}
@@ -157,12 +157,12 @@ asn1_find_node (asn1_node pointer, const char *name)
n_start = n_end;
n_start++;
- nhash = hash_pjw_bare(n, nsize);
+ nhash = hash_pjw_bare (n, nsize);
}
else
{
nsize = _asn1_str_cpy (n, sizeof (n), n_start);
- nhash = hash_pjw_bare(n, nsize);
+ nhash = hash_pjw_bare (n, nsize);
n_start = NULL;
}
@@ -358,7 +358,7 @@ _asn1_append_value (asn1_node node, const void *value, unsigned int len)
asn1_node
_asn1_set_name (asn1_node node, const char *name)
{
-unsigned int nsize;
+ unsigned int nsize;
if (node == NULL)
return node;
@@ -366,12 +366,12 @@ unsigned int nsize;
if (name == NULL)
{
node->name[0] = 0;
- node->name_hash = hash_pjw_bare(node->name, 0);
+ node->name_hash = hash_pjw_bare (node->name, 0);
return node;
}
nsize = _asn1_str_cpy (node->name, sizeof (node->name), name);
- node->name_hash = hash_pjw_bare(node->name, nsize);
+ node->name_hash = hash_pjw_bare (node->name, nsize);
return node;
}
@@ -393,7 +393,7 @@ _asn1_cpy_name (asn1_node dst, asn1_node src)
if (src == NULL)
{
dst->name[0] = 0;
- dst->name_hash = hash_pjw_bare(dst->name, 0);
+ dst->name_hash = hash_pjw_bare (dst->name, 0);
return dst;
}
@@ -581,7 +581,8 @@ _asn1_change_integer_value (asn1_node node)
p = node;
while (p)
{
- if ((type_field (p->type) == ASN1_ETYPE_INTEGER) && (p->type & CONST_ASSIGN))
+ if ((type_field (p->type) == ASN1_ETYPE_INTEGER)
+ && (p->type & CONST_ASSIGN))
{
if (p->value)
{
@@ -666,8 +667,9 @@ _asn1_expand_object_id (asn1_node node)
_asn1_str_cat (name2, sizeof (name2),
(char *) p2->value);
p3 = asn1_find_node (node, name2);
- if (!p3 || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) ||
- !(p3->type & CONST_ASSIGN))
+ if (!p3
+ || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID)
+ || !(p3->type & CONST_ASSIGN))
return ASN1_ELEMENT_NOT_FOUND;
_asn1_set_down (p, p2->right);
_asn1_remove_node (p2);
@@ -677,7 +679,8 @@ _asn1_expand_object_id (asn1_node node)
{
if (type_field (p4->type) == ASN1_ETYPE_CONSTANT)
{
- p5 = _asn1_add_single_node (ASN1_ETYPE_CONSTANT);
+ p5 =
+ _asn1_add_single_node (ASN1_ETYPE_CONSTANT);
_asn1_set_name (p5, p4->name);
tlen = _asn1_strlen (p4->value);
if (tlen > 0)
@@ -752,8 +755,8 @@ _asn1_expand_object_id (asn1_node node)
_asn1_str_cat (name2, sizeof (name2), ".");
_asn1_str_cat (name2, sizeof (name2), (char *) p2->value);
p3 = asn1_find_node (node, name2);
- if (!p3 || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) ||
- !(p3->type & CONST_ASSIGN))
+ if (!p3 || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID)
+ || !(p3->type & CONST_ASSIGN))
return ASN1_ELEMENT_NOT_FOUND;
p4 = p3->down;
name2[0] = 0;
@@ -911,9 +914,9 @@ _asn1_check_identifier (asn1_node node)
if (p2 == NULL)
{
if (p->value)
- _asn1_strcpy (_asn1_identifierMissing, p->value);
- else
- _asn1_strcpy (_asn1_identifierMissing, "(null)");
+ _asn1_strcpy (_asn1_identifierMissing, p->value);
+ else
+ _asn1_strcpy (_asn1_identifierMissing, "(null)");
return ASN1_IDENTIFIER_NOT_FOUND;
}
}
@@ -948,8 +951,8 @@ _asn1_check_identifier (asn1_node node)
_asn1_str_cat (name2, sizeof (name2), (char *) p2->value);
_asn1_strcpy (_asn1_identifierMissing, p2->value);
p2 = asn1_find_node (node, name2);
- if (!p2 || (type_field (p2->type) != ASN1_ETYPE_OBJECT_ID) ||
- !(p2->type & CONST_ASSIGN))
+ if (!p2 || (type_field (p2->type) != ASN1_ETYPE_OBJECT_ID)
+ || !(p2->type & CONST_ASSIGN))
return ASN1_IDENTIFIER_NOT_FOUND;
else
_asn1_identifierMissing[0] = 0;
diff --git a/lib/structure.c b/lib/structure.c
index 31a5f65..58e6f32 100644
--- a/lib/structure.c
+++ b/lib/structure.c
@@ -192,7 +192,7 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions,
k = 0;
while (array[k].value || array[k].type || array[k].name)
{
- type = convert_old_type(array[k].type);
+ type = convert_old_type (array[k].type);
p = _asn1_add_static_node (type & (~CONST_DOWN));
if (array[k].name)
@@ -409,22 +409,22 @@ _asn1_copy_structure3 (asn1_node source_node)
}
if (p_s == source_node)
- break;
+ break;
if (p_s->right)
- {
- move = RIGHT;
- p_s = p_s->right;
- p_d_prev = p_d;
- p_d = _asn1_add_single_node (p_s->type);
- _asn1_set_right (p_d_prev, p_d);
- }
+ {
+ move = RIGHT;
+ p_s = p_s->right;
+ p_d_prev = p_d;
+ p_d = _asn1_add_single_node (p_s->type);
+ _asn1_set_right (p_d_prev, p_d);
+ }
else
- {
- move = UP;
- p_s = _asn1_find_up (p_s);
- p_d = _asn1_find_up (p_d);
- }
+ {
+ move = UP;
+ p_s = _asn1_find_up (p_s);
+ p_d = _asn1_find_up (p_d);
+ }
}
while (p_s != source_node);
@@ -460,7 +460,8 @@ _asn1_type_choice_config (asn1_node node)
{
if (move != UP)
{
- if ((type_field (p->type) == ASN1_ETYPE_CHOICE) && (p->type & CONST_TAG))
+ if ((type_field (p->type) == ASN1_ETYPE_CHOICE)
+ && (p->type & CONST_TAG))
{
p2 = p->down;
while (p2)
@@ -548,7 +549,7 @@ _asn1_expand_identifier (asn1_node * node, asn1_node root)
{
if (type_field (p->type) == ASN1_ETYPE_IDENTIFIER)
{
- snprintf(name2, sizeof (name2), "%s.%s", root->name, p->value);
+ snprintf (name2, sizeof (name2), "%s.%s", root->name, p->value);
p2 = _asn1_copy_structure2 (root, name2);
if (p2 == NULL)
{
@@ -765,7 +766,7 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name,
case ASN1_ETYPE_DEFINITIONS:
fprintf (out, "type:DEFINITIONS");
break;
- CASE_HANDLED_ETYPES:
+ CASE_HANDLED_ETYPES:
fprintf (out, "%s", _asn1_tags[type].desc);
break;
default:
@@ -854,7 +855,7 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name,
if (p->value)
{
fprintf (out, " value:");
- for (k = 0; k < p->value_len; k++)
+ for (k = 0; k < p->value_len; k++)
fprintf (out, "%c", (p->value)[k]);
}
break;
diff --git a/lib/structure.h b/lib/structure.h
index 986e13a..b8d7418 100644
--- a/lib/structure.h
+++ b/lib/structure.h
@@ -29,8 +29,7 @@
#define _STRUCTURE_H
int _asn1_create_static_structure (asn1_node pointer,
- char *output_file_name,
- char *vector_name);
+ char *output_file_name, char *vector_name);
asn1_node _asn1_copy_structure3 (asn1_node source_node);