summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--src/asn1Coding.c16
-rw-r--r--src/asn1Decoding.c69
-rw-r--r--src/asn1Parser.c9
-rw-r--r--src/benchmark.c27
-rw-r--r--src/benchmark.h12
-rw-r--r--tests/Test_encoding.c5
-rw-r--r--tests/Test_errors.c6
-rw-r--r--tests/Test_overflow.c137
-rw-r--r--tests/Test_parser.c22
-rw-r--r--tests/Test_strings.c82
-rw-r--r--tests/Test_tree.c89
22 files changed, 537 insertions, 449 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);
diff --git a/src/asn1Coding.c b/src/asn1Coding.c
index 700e958..202d5fc 100644
--- a/src/asn1Coding.c
+++ b/src/asn1Coding.c
@@ -214,8 +214,7 @@ main (int argc, char *argv[])
fputs ("Parse: done.\n", stderr);
break;
case ASN1_FILE_NOT_FOUND:
- fprintf (stderr, "asn1Coding: FILE %s NOT FOUND\n",
- inputFileAsnName);
+ fprintf (stderr, "asn1Coding: FILE %s NOT FOUND\n", inputFileAsnName);
break;
case ASN1_SYNTAX_ERROR:
case ASN1_IDENTIFIER_NOT_FOUND:
@@ -223,8 +222,7 @@ main (int argc, char *argv[])
fprintf (stderr, "asn1Coding: %s\n", errorDescription);
break;
default:
- fprintf (stderr, "libtasn1 ERROR: %s\n",
- asn1_strerror (asn1_result));
+ fprintf (stderr, "libtasn1 ERROR: %s\n", asn1_strerror (asn1_result));
}
if (asn1_result != ASN1_SUCCESS)
@@ -240,7 +238,7 @@ main (int argc, char *argv[])
if (inputFile == NULL)
{
fprintf (stderr, "asn1Coding: file '%s' not found\n",
- inputFileAssignmentName);
+ inputFileAssignmentName);
free (inputFileAsnName);
free (inputFileAssignmentName);
exit (1);
@@ -250,7 +248,7 @@ main (int argc, char *argv[])
putc ('\n', stderr);
while ((last_ra = readAssignment (inputFile, varName, value))
- == ASSIGNMENT_SUCCESS)
+ == ASSIGNMENT_SUCCESS)
{
fprintf (stderr, "var=%s, value=%s\n", varName, value);
if (structure == NULL)
@@ -263,7 +261,7 @@ main (int argc, char *argv[])
if (asn1_result != ASN1_SUCCESS)
{
fprintf (stderr, "libtasn1 ERROR: %s\n",
- asn1_strerror (asn1_result));
+ asn1_strerror (asn1_result));
asn1_delete_structure (&definitions);
asn1_delete_structure (&structure);
@@ -331,8 +329,8 @@ main (int argc, char *argv[])
if (outputFile == NULL)
{
fprintf (stderr,
- "asn1Coding: output file '%s' not available\n",
- outputFileName);
+ "asn1Coding: output file '%s' not available\n",
+ outputFileName);
free (der);
free (inputFileAsnName);
free (inputFileAssignmentName);
diff --git a/src/asn1Decoding.c b/src/asn1Decoding.c
index 00156c5..2a9cc96 100644
--- a/src/asn1Decoding.c
+++ b/src/asn1Decoding.c
@@ -33,7 +33,8 @@
#include <read-file.h>
#include "benchmark.h"
-static int decode(asn1_node definitions, const char* typeName, void* der, int der_len, int benchmark);
+static int decode (asn1_node definitions, const char *typeName, void *der,
+ int der_len, int benchmark);
/* This feature is available in gcc versions 2.5 and later. */
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
@@ -101,9 +102,9 @@ main (int argc, char *argv[])
case 'h': /* HELP */
usage (EXIT_SUCCESS);
break;
- case 'b':
- benchmark = 1;
- break;
+ case 'b':
+ benchmark = 1;
+ break;
case 'v': /* VERSION */
version_etc (stdout, program_name, PACKAGE, VERSION,
"Fabio Fiorina", NULL);
@@ -147,8 +148,7 @@ main (int argc, char *argv[])
fprintf (stderr, "Parse: done.\n");
break;
case ASN1_FILE_NOT_FOUND:
- fprintf (stderr, "asn1Decoding: FILE %s NOT FOUND\n",
- inputFileAsnName);
+ fprintf (stderr, "asn1Decoding: FILE %s NOT FOUND\n", inputFileAsnName);
break;
case ASN1_SYNTAX_ERROR:
case ASN1_IDENTIFIER_NOT_FOUND:
@@ -156,8 +156,7 @@ main (int argc, char *argv[])
fprintf (stderr, "asn1Decoding: %s\n", errorDescription);
break;
default:
- fprintf (stderr, "libtasn1 ERROR: %s\n",
- asn1_strerror (asn1_result));
+ fprintf (stderr, "libtasn1 ERROR: %s\n", asn1_strerror (asn1_result));
}
if (asn1_result != ASN1_SUCCESS)
@@ -178,7 +177,7 @@ main (int argc, char *argv[])
if (der == NULL)
{
fprintf (stderr, "asn1Decoding: could not read '%s'\n",
- inputFileDerName);
+ inputFileDerName);
asn1_delete_structure (&definitions);
free (inputFileAsnName);
@@ -203,7 +202,7 @@ main (int argc, char *argv[])
fclose(inputFile);
*/
- if (decode( definitions, typeName, der, der_len, benchmark) != ASN1_SUCCESS)
+ if (decode (definitions, typeName, der, der_len, benchmark) != ASN1_SUCCESS)
{
asn1_delete_structure (&definitions);
free (inputFileAsnName);
@@ -212,7 +211,7 @@ main (int argc, char *argv[])
free (der);
exit (1);
}
-
+
asn1_delete_structure (&definitions);
free (der);
@@ -227,12 +226,14 @@ main (int argc, char *argv[])
exit (0);
}
-static int simple_decode(asn1_node definitions, const char* typeName, void* der, int der_len, int benchmark)
+static int
+simple_decode (asn1_node definitions, const char *typeName, void *der,
+ int der_len, int benchmark)
{
-
-int asn1_result;
-asn1_node structure = NULL;
-char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
+
+ int asn1_result;
+ asn1_node structure = NULL;
+ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
asn1_result = asn1_create_element (definitions, typeName, &structure);
@@ -242,7 +243,7 @@ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
if (asn1_result != ASN1_SUCCESS)
{
fprintf (stderr, "Structure creation: %s\n",
- asn1_strerror (asn1_result));
+ asn1_strerror (asn1_result));
asn1_delete_structure (&structure);
return asn1_result;
}
@@ -262,31 +263,35 @@ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
if (!benchmark)
{
fprintf (stderr, "\nDECODING RESULT:\n");
- asn1_print_structure (stdout, structure, "", ASN1_PRINT_NAME_TYPE_VALUE);
+ asn1_print_structure (stdout, structure, "",
+ ASN1_PRINT_NAME_TYPE_VALUE);
}
asn1_delete_structure (&structure);
return ASN1_SUCCESS;
}
-static int decode(asn1_node definitions, const char* typeName, void* der, int der_len, int benchmark)
+static int
+decode (asn1_node definitions, const char *typeName, void *der, int der_len,
+ int benchmark)
{
-struct benchmark_st st;
+ struct benchmark_st st;
- if (benchmark == 0) return simple_decode(definitions, typeName, der, der_len, benchmark);
+ if (benchmark == 0)
+ return simple_decode (definitions, typeName, der, der_len, benchmark);
else
{
- start_benchmark(&st);
-
+ start_benchmark (&st);
+
do
- {
- simple_decode(definitions, typeName, der, der_len, benchmark);
- st.size++;
- }
- while(benchmark_must_finish == 0);
-
- stop_benchmark(&st, "structures");
- fprintf(stdout, "\n");
-
+ {
+ simple_decode (definitions, typeName, der, der_len, benchmark);
+ st.size++;
+ }
+ while (benchmark_must_finish == 0);
+
+ stop_benchmark (&st, "structures");
+ fprintf (stdout, "\n");
+
}
return ASN1_SUCCESS;
}
diff --git a/src/asn1Parser.c b/src/asn1Parser.c
index 64bf16b..d77dab0 100644
--- a/src/asn1Parser.c
+++ b/src/asn1Parser.c
@@ -100,8 +100,7 @@ main (int argc, char *argv[])
switch (option_result)
{
case 0:
- fprintf (stderr, "option %s",
- long_options[option_index].name);
+ fprintf (stderr, "option %s", long_options[option_index].name);
if (optarg)
fprintf (stderr, " with arg %s", optarg);
putc ('\n', stderr);
@@ -174,8 +173,7 @@ main (int argc, char *argv[])
fputs ("Done.\n", stderr);
break;
case ASN1_FILE_NOT_FOUND:
- fprintf (stderr, "asn1Parser: file %s was not found\n",
- inputFileName);
+ fprintf (stderr, "asn1Parser: file %s was not found\n", inputFileName);
break;
case ASN1_SYNTAX_ERROR:
case ASN1_IDENTIFIER_NOT_FOUND:
@@ -183,8 +181,7 @@ main (int argc, char *argv[])
fprintf (stderr, "asn1Parser: %s\n", errorDescription);
break;
default:
- fprintf (stderr, "libtasn1 ERROR: %s\n",
- asn1_strerror (parse_result));
+ fprintf (stderr, "libtasn1 ERROR: %s\n", asn1_strerror (parse_result));
}
diff --git a/src/benchmark.c b/src/benchmark.c
index 1ebf6b6..e7430cf 100644
--- a/src/benchmark.c
+++ b/src/benchmark.c
@@ -48,7 +48,7 @@ alarm_handler (int signo)
static void
value2human (unsigned long bytes, double secs, double *data, double *speed,
- char *metric)
+ char *metric)
{
if (bytes > 1000 && bytes < 1000 * 1000)
{
@@ -80,9 +80,10 @@ value2human (unsigned long bytes, double secs, double *data, double *speed,
}
}
-void start_benchmark(struct benchmark_st * st)
+void
+start_benchmark (struct benchmark_st *st)
{
- memset(st, 0, sizeof(*st));
+ memset (st, 0, sizeof (*st));
#ifndef _WIN32
st->old_handler = signal (SIGALRM, alarm_handler);
#endif
@@ -94,28 +95,30 @@ void start_benchmark(struct benchmark_st * st)
if (st->wtimer == NULL)
{
fprintf (stderr, "error: CreateWaitableTimer %u\n", GetLastError ());
- exit(1);
+ exit (1);
}
st->wthread = CreateThread (NULL, 0, alarm_handler, &st->wtimer, 0, NULL);
if (st->wthread == NULL)
{
fprintf (stderr, "error: CreateThread %u\n", GetLastError ());
- exit(1);
+ exit (1);
}
st->alarm_timeout.QuadPart = (5) * 10000000;
- if (SetWaitableTimer (st->wtimer, &st->alarm_timeout, 0, NULL, NULL, FALSE) == 0)
+ if (SetWaitableTimer (st->wtimer, &st->alarm_timeout, 0, NULL, NULL, FALSE)
+ == 0)
{
fprintf (stderr, "error: SetWaitableTimer %u\n", GetLastError ());
- exit(1);
+ exit (1);
}
#else
alarm (5);
#endif
-
+
}
/* returns the elapsed time */
-double stop_benchmark(struct benchmark_st * st, const char* metric)
+double
+stop_benchmark (struct benchmark_st *st, const char *metric)
{
double secs;
unsigned long lsecs;
@@ -129,18 +132,18 @@ double stop_benchmark(struct benchmark_st * st, const char* metric)
if (st->wthread != NULL)
CloseHandle (st->wthread);
#else
- signal(SIGALRM, st->old_handler);
+ signal (SIGALRM, st->old_handler);
#endif
gettime (&stop);
lsecs = (stop.tv_sec * 1000 + stop.tv_nsec / (1000 * 1000) -
- (st->start.tv_sec * 1000 + st->start.tv_nsec / (1000 * 1000)));
+ (st->start.tv_sec * 1000 + st->start.tv_nsec / (1000 * 1000)));
secs = lsecs;
secs /= 1000;
if (metric == NULL)
- { /* assume bytes/sec */
+ { /* assume bytes/sec */
value2human (st->size, secs, &ddata, &dspeed, imetric);
printf (" Processed %.2f %s in %.2f secs: ", ddata, imetric, secs);
printf ("%.2f %s/sec\n", dspeed, imetric);
diff --git a/src/benchmark.h b/src/benchmark.h
index e7d3386..3d5838a 100644
--- a/src/benchmark.h
+++ b/src/benchmark.h
@@ -21,11 +21,11 @@
#include <time.h>
#include <signal.h>
#if defined(_WIN32)
-# include <windows.h>
+#include <windows.h>
#endif
-#include "timespec.h" /* gnulib gettime */
+#include "timespec.h" /* gnulib gettime */
-typedef void (*sighandler_t)(int);
+typedef void (*sighandler_t) (int);
struct benchmark_st
{
@@ -41,12 +41,12 @@ struct benchmark_st
extern int benchmark_must_finish;
-void start_benchmark(struct benchmark_st * st);
-double stop_benchmark(struct benchmark_st * st, const char* metric);
+void start_benchmark (struct benchmark_st *st);
+double stop_benchmark (struct benchmark_st *st, const char *metric);
inline static unsigned int
timespec_sub_ms (struct timespec *a, struct timespec *b)
{
return (a->tv_sec * 1000 + a->tv_nsec / (1000 * 1000) -
- (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000)));
+ (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000)));
}
diff --git a/tests/Test_encoding.c b/tests/Test_encoding.c
index d6c7d57..874cf5c 100644
--- a/tests/Test_encoding.c
+++ b/tests/Test_encoding.c
@@ -53,7 +53,7 @@ main (int argc, char *argv[])
printf ("\n\n/****************************************/\n");
printf ("/* Test sequence : coding-decoding */\n");
printf ("/****************************************/\n\n");
- }
+ }
/* Check version */
if (asn1_check_version ("0.3.3") == NULL)
@@ -130,6 +130,7 @@ main (int argc, char *argv[])
asn1_delete_structure (&asn1_element);
- if (verbose) printf ("Success\n");
+ if (verbose)
+ printf ("Success\n");
exit (0);
}
diff --git a/tests/Test_errors.c b/tests/Test_errors.c
index fcd1704..6adf687 100644
--- a/tests/Test_errors.c
+++ b/tests/Test_errors.c
@@ -26,15 +26,15 @@ main (int argc, char *argv[])
int ec = 0;
const char *errstr;
int verbose = 0;
-
+
if (argc > 1)
- verbose = 1;
+ verbose = 1;
do
{
errstr = asn1_strerror (ec);
if (verbose != 0)
- asn1_perror (ec);
+ asn1_perror (ec);
ec++;
}
while (errstr);
diff --git a/tests/Test_overflow.c b/tests/Test_overflow.c
index fc8466b..1e299ee 100644
--- a/tests/Test_overflow.c
+++ b/tests/Test_overflow.c
@@ -28,12 +28,12 @@
#include "libtasn1.h"
int
-main (int argc, char** argv)
+main (int argc, char **argv)
{
/* Test that values larger than long are rejected. This has worked
fine with all versions of libtasn1. */
int verbose = 0;
-
+
if (argc > 1)
verbose = 1;
@@ -46,7 +46,8 @@ main (int argc, char** argv)
if (l == -2L)
{
- if (verbose) puts ("OK: asn1_get_length_der bignum");
+ if (verbose)
+ puts ("OK: asn1_get_length_der bignum");
}
else
{
@@ -70,9 +71,10 @@ main (int argc, char** argv)
l = asn1_get_length_der (der, der_len, &len);
if (l == -2L)
- {
- if (verbose) puts ("OK: asn1_get_length_der intnum");
- }
+ {
+ if (verbose)
+ puts ("OK: asn1_get_length_der intnum");
+ }
else
{
printf ("ERROR: asn1_get_length_der intnum (l %ld len %d)\n", l,
@@ -83,81 +85,84 @@ main (int argc, char** argv)
/* Test that values larger than would fit in the input string are
rejected. This problem was fixed in libtasn1 2.12. */
- {
- unsigned long num = 64;
- unsigned char der[20];
- int der_len;
- long l;
- int len;
+ {
+ unsigned long num = 64;
+ unsigned char der[20];
+ int der_len;
+ long l;
+ int len;
- asn1_length_der (num, der, &der_len);
+ asn1_length_der (num, der, &der_len);
- der_len = sizeof(der);
- l = asn1_get_length_der (der, der_len, &len);
+ der_len = sizeof (der);
+ l = asn1_get_length_der (der, der_len, &len);
- if (l == -4L)
- {
- if (verbose) puts ("OK: asn1_get_length_der overflow-small");
- }
- else
- {
- printf ("ERROR: asn1_get_length_der overflow-small (l %ld len %d)\n", l,
- len);
- return 1;
- }
- }
+ if (l == -4L)
+ {
+ if (verbose)
+ puts ("OK: asn1_get_length_der overflow-small");
+ }
+ else
+ {
+ printf ("ERROR: asn1_get_length_der overflow-small (l %ld len %d)\n",
+ l, len);
+ return 1;
+ }
+ }
/* Test that values larger than would fit in the input string are
rejected. This problem was fixed in libtasn1 2.12. */
- {
- unsigned long num = 1073741824;
- unsigned char der[20];
- int der_len;
- long l;
- int len;
+ {
+ unsigned long num = 1073741824;
+ unsigned char der[20];
+ int der_len;
+ long l;
+ int len;
- asn1_length_der (num, der, &der_len);
+ asn1_length_der (num, der, &der_len);
- der_len = sizeof(der);
- l = asn1_get_length_der (der, der_len, &len);
+ der_len = sizeof (der);
+ l = asn1_get_length_der (der, der_len, &len);
- if (l == -4L)
- {
- if (verbose) puts ("OK: asn1_get_length_der overflow-large1");
- }
- else
- {
- printf ("ERROR: asn1_get_length_der overflow-large1 (l %ld len %d)\n", l,
- len);
- return 1;
- }
- }
+ if (l == -4L)
+ {
+ if (verbose)
+ puts ("OK: asn1_get_length_der overflow-large1");
+ }
+ else
+ {
+ printf ("ERROR: asn1_get_length_der overflow-large1 (l %ld len %d)\n",
+ l, len);
+ return 1;
+ }
+ }
/* Test that values larger than would fit in the input string are
rejected. This problem was fixed in libtasn1 2.12. */
- {
- unsigned long num = 2147483649;
- unsigned char der[20];
- int der_len;
- long l;
- int len;
+ {
+ unsigned long num = 2147483649;
+ unsigned char der[20];
+ int der_len;
+ long l;
+ int len;
- asn1_length_der (num, der, &der_len);
+ asn1_length_der (num, der, &der_len);
- der_len = sizeof(der);
- l = asn1_get_length_der (der, der_len, &len);
+ der_len = sizeof (der);
+ l = asn1_get_length_der (der, der_len, &len);
- if (l == -2L)
- {
- if (verbose) puts ("OK: asn1_get_length_der overflow-large2");
- }
- else
- {
- printf ("ERROR: asn1_get_length_der overflow-large2 (l %ld len %d)\n", l,
- len);
- return 1;
- }
- }
+ if (l == -2L)
+ {
+ if (verbose)
+ puts ("OK: asn1_get_length_der overflow-large2");
+ }
+ else
+ {
+ printf ("ERROR: asn1_get_length_der overflow-large2 (l %ld len %d)\n",
+ l, len);
+ return 1;
+ }
+ }
return 0;
}
diff --git a/tests/Test_parser.c b/tests/Test_parser.c
index 4ba1636..125ea99 100644
--- a/tests/Test_parser.c
+++ b/tests/Test_parser.c
@@ -47,7 +47,9 @@ test_type test_array[] = {
/* Test DEFINITIONS syntax */
{5,
"TEST_PARSER2 { } DEFINITIONS IMPLICIT TAGS ::= BEGIN int1 ::= INTEGER END",
- ASN1_SYNTAX_ERROR, _FILE_ ":6: Error: syntax error, unexpected IDENTIFIER, expecting $end near 'TEST_PARSER'"},
+ ASN1_SYNTAX_ERROR,
+ _FILE_
+ ":6: Error: syntax error, unexpected IDENTIFIER, expecting $end near 'TEST_PARSER'"},
{6, "TEST_PARSER { }", ASN1_SUCCESS, ""},
/* Test ASN1_MAX_NAME_SIZE (128) */
@@ -79,13 +81,18 @@ test_type test_array[] = {
{14, "int1 [1] IMPLICIT INTEGER,", ASN1_SUCCESS, ""},
{12, "Integer ::= [1] EXPLICIT INTEGER {v1(-1), v2(1)}", ASN1_SUCCESS, ""},
{12, "Integer ::= INTEGER {v1(0), v2}",
- ASN1_SYNTAX_ERROR, _FILE_ ":12: Error: syntax error, unexpected '}', expecting '(' near '}'"},
+ ASN1_SYNTAX_ERROR,
+ _FILE_ ":12: Error: syntax error, unexpected '}', expecting '(' near '}'"},
{12, "Integer ::= INTEGER {v1(0), 1}",
- ASN1_SYNTAX_ERROR, _FILE_ ":12: Error: syntax error, unexpected NUM, expecting IDENTIFIER or '(' near '1'"},
+ ASN1_SYNTAX_ERROR,
+ _FILE_
+ ":12: Error: syntax error, unexpected NUM, expecting IDENTIFIER or '(' near '1'"},
{12, "const1 INTEGER ::= -1", ASN1_SUCCESS, ""},
{12, "const1 INTEGER ::= 1", ASN1_SUCCESS, ""},
{12, "const1 INTEGER ::= v1",
- ASN1_SYNTAX_ERROR, _FILE_ ":12: Error: syntax error, unexpected IDENTIFIER, expecting NUM or '+' or '-' near 'v1'"},
+ ASN1_SYNTAX_ERROR,
+ _FILE_
+ ":12: Error: syntax error, unexpected IDENTIFIER, expecting NUM or '+' or '-' near 'v1'"},
{16, " generic generalstring",
ASN1_IDENTIFIER_NOT_FOUND,
_FILE_ ":: identifier 'generalstring' not found"},
@@ -96,7 +103,8 @@ test_type test_array[] = {
{20, " oid1 OBJECT IDENTIFIER DEFAULT 1",
ASN1_IDENTIFIER_NOT_FOUND, _FILE_ ":: identifier '1' not found"},
{20, " oid1 OBJECT IDENTIFIER DEFAULT",
- ASN1_SYNTAX_ERROR, _FILE_ ":21: Error: syntax error, unexpected '}' near '}'"},
+ ASN1_SYNTAX_ERROR,
+ _FILE_ ":21: Error: syntax error, unexpected '}' near '}'"},
{20, " oid1 OBJECT IDENTIFIER DEFAULT Oid-type1",
ASN1_SUCCESS, ""},
@@ -153,7 +161,7 @@ main (int argc, char *argv[])
test_type *test;
int errorCounter = 0, testCounter = 0;
int verbose = 0;
-
+
if (argc > 1)
verbose = 1;
@@ -208,7 +216,7 @@ main (int argc, char *argv[])
asn1_strerror (test->errorNumber), test->errorDescription);
printf (" Error detected: %s - %s\n\n", asn1_strerror (result),
errorDescription);
- exit(1);
+ exit (1);
}
test++;
diff --git a/tests/Test_strings.c b/tests/Test_strings.c
index b43620f..0887a39 100644
--- a/tests/Test_strings.c
+++ b/tests/Test_strings.c
@@ -36,16 +36,22 @@ struct tv
};
static const struct tv tv[] = {
- {ASN1_ETYPE_IA5_STRING, 20, "\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72",
- 22, "\x16\x14\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72"},
- {ASN1_ETYPE_PRINTABLE_STRING, 5, "\x4e\x69\x6b\x6f\x73",
- 7, "\x13\x05\x4e\x69\x6b\x6f\x73"},
+ {ASN1_ETYPE_IA5_STRING, 20,
+ "\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72",
+ 22,
+ "\x16\x14\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72"},
+ {ASN1_ETYPE_PRINTABLE_STRING, 5, "\x4e\x69\x6b\x6f\x73",
+ 7, "\x13\x05\x4e\x69\x6b\x6f\x73"},
{ASN1_ETYPE_UTF8_STRING, 12, "Αττική",
- 14, "\x0c\x0c\xce\x91\xcf\x84\xcf\x84\xce\xb9\xce\xba\xce\xae"},
- {ASN1_ETYPE_TELETEX_STRING, 15, "\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e",
- 17, "\x14\x0f\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e"},
- {ASN1_ETYPE_OCTET_STRING, 36, "\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A",
- 38, "\x04\x24\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A"}
+ 14, "\x0c\x0c\xce\x91\xcf\x84\xcf\x84\xce\xb9\xce\xba\xce\xae"},
+ {ASN1_ETYPE_TELETEX_STRING, 15,
+ "\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e",
+ 17,
+ "\x14\x0f\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e"},
+ {ASN1_ETYPE_OCTET_STRING, 36,
+ "\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A",
+ 38,
+ "\x04\x24\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A"}
};
int
@@ -54,7 +60,7 @@ main (int argc, char *argv[])
int ret;
unsigned char tl[ASN1_MAX_TL_SIZE];
unsigned int tl_len, der_len, str_len;
- const unsigned char* str;
+ const unsigned char *str;
unsigned int i;
/* Dummy test */
@@ -62,35 +68,43 @@ main (int argc, char *argv[])
for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
{
/* Encode */
- tl_len = sizeof(tl);
- ret = asn1_encode_simple_der(tv[i].etype, tv[i].str, tv[i].str_len,
- tl, &tl_len);
+ tl_len = sizeof (tl);
+ ret = asn1_encode_simple_der (tv[i].etype, tv[i].str, tv[i].str_len,
+ tl, &tl_len);
if (ret != ASN1_SUCCESS)
- {
- fprintf(stderr, "Encoding error in %u: %s\n", i, asn1_strerror(ret));
- return 1;
- }
- der_len = tl_len+tv[i].str_len;
-
- if (der_len != tv[i].der_len || memcmp(tl, tv[i].der, tl_len) != 0)
- {
- fprintf(stderr, "DER encoding differs in %u! (size: %u, expected: %u)\n", i, der_len, tv[i].der_len);
- return 1;
- }
+ {
+ fprintf (stderr, "Encoding error in %u: %s\n", i,
+ asn1_strerror (ret));
+ return 1;
+ }
+ der_len = tl_len + tv[i].str_len;
+
+ if (der_len != tv[i].der_len || memcmp (tl, tv[i].der, tl_len) != 0)
+ {
+ fprintf (stderr,
+ "DER encoding differs in %u! (size: %u, expected: %u)\n",
+ i, der_len, tv[i].der_len);
+ return 1;
+ }
/* decoding */
- ret = asn1_decode_simple_der(tv[i].etype, tv[i].der, tv[i].der_len, &str, &str_len);
+ ret =
+ asn1_decode_simple_der (tv[i].etype, tv[i].der, tv[i].der_len, &str,
+ &str_len);
if (ret != ASN1_SUCCESS)
- {
- fprintf(stderr, "Decoding error in %u: %s\n", i, asn1_strerror(ret));
- return 1;
- }
+ {
+ fprintf (stderr, "Decoding error in %u: %s\n", i,
+ asn1_strerror (ret));
+ return 1;
+ }
- if (str_len != tv[i].str_len || memcmp(str, tv[i].str, str_len) != 0)
- {
- fprintf(stderr, "DER decoded data differ in %u! (size: %u, expected: %u)\n", i, der_len, tv[i].str_len);
- return 1;
- }
+ if (str_len != tv[i].str_len || memcmp (str, tv[i].str, str_len) != 0)
+ {
+ fprintf (stderr,
+ "DER decoded data differ in %u! (size: %u, expected: %u)\n",
+ i, der_len, tv[i].str_len);
+ return 1;
+ }
}
diff --git a/tests/Test_tree.c b/tests/Test_tree.c
index bcd3cbe..4702fa1 100644
--- a/tests/Test_tree.c
+++ b/tests/Test_tree.c
@@ -95,30 +95,37 @@ test_type test_array[] = {
{ACT_WRITE, "validity", 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "issuer", "rdnSequence", 0, ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
- {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.3", 0, ASN1_SUCCESS, __LINE__},
+ {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.3", 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_WRITE, "issuer.rdnSequence.?LAST.value",
"\x0c\x18\x71\x75\x61\x73\x61\x72\x2e\x6c\x61\x73\x2e\x69\x63\x2e\x75\x6e\x69\x63\x61\x6d\x70\x2e\x62\x72",
26, ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
- {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.7", 0, ASN1_SUCCESS, __LINE__},
+ {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.7", 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_WRITE, "issuer.rdnSequence.?LAST.value",
"\x0c\x08\x43\x61\x6d\x70\x69\x6e\x61\x73", 10, ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
- {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.6", 0, ASN1_SUCCESS, __LINE__},
+ {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.6", 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_WRITE, "issuer.rdnSequence.?LAST.value",
"\x13\x06\x42\x72\x61\x73\x69\x6c", 8, ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
- {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.10", 0, ASN1_SUCCESS, __LINE__},
+ {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.10", 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_WRITE, "issuer.rdnSequence.?LAST.value", "\x0c\x02\x49\x43", 4,
ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
- {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.11", 0, ASN1_SUCCESS, __LINE__},
+ {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.11", 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_WRITE, "issuer.rdnSequence.?LAST.value", "\x0c\x03\x4c\x41\x53", 5,
ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
- {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.8", 0, ASN1_SUCCESS, __LINE__},
+ {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.8", 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_WRITE, "issuer.rdnSequence.?LAST.value",
- "\x0c\x09\x53\x61\x6f\x20\x50\x61\x75\x6c\x6f", 11, ASN1_SUCCESS, __LINE__},
+ "\x0c\x09\x53\x61\x6f\x20\x50\x61\x75\x6c\x6f", 11, ASN1_SUCCESS,
+ __LINE__},
{ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "issuer.rdnSequence.?LAST.type", "1.2.840.113549.1.9.1", 0,
ASN1_SUCCESS, __LINE__},
@@ -134,12 +141,16 @@ test_type test_array[] = {
{ACT_CREATE, "TEST_TREE.CertTemplate", 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
- {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?1", "", 0, ASN1_SUCCESS, __LINE__},
+ {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?1", "", 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_DELETE_ELEMENT, "issuer.rdnSequence.?1", "", 0,
ASN1_ELEMENT_NOT_FOUND, __LINE__},
- {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?3", "", 0, ASN1_SUCCESS, __LINE__},
- {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?5", "", 0, ASN1_SUCCESS, __LINE__},
- {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?7", "", 0, ASN1_SUCCESS, __LINE__},
+ {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?3", "", 0, ASN1_SUCCESS,
+ __LINE__},
+ {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?5", "", 0, ASN1_SUCCESS,
+ __LINE__},
+ {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?7", "", 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
{ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
@@ -162,7 +173,8 @@ test_type test_array[] = {
{ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
/* Test: Indefinite Length */
- {ACT_CREATE, "TEST_TREE.IndefiniteLengthTest", 0, 0, ASN1_SUCCESS, __LINE__},
+ {ACT_CREATE, "TEST_TREE.IndefiniteLengthTest", 0, 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_WRITE, "int1", "1", 0, ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "seq1.int", "2", 0, ASN1_SUCCESS, __LINE__},
{ACT_WRITE, "set1", "NEW", 0, ASN1_SUCCESS, __LINE__},
@@ -175,7 +187,8 @@ test_type test_array[] = {
"\x30\x18\xa1\x80\x02\x01\x02\x00\x00\x31\x80\x06\x03\x2a\x03\x04\x06\x03\x2a\x05\x06\x00\x00\x02\x01\x01",
0, 26, ASN1_SUCCESS, __LINE__},
{ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
- {ACT_CREATE, "TEST_TREE.IndefiniteLengthTest", 0, 0, ASN1_SUCCESS, __LINE__},
+ {ACT_CREATE, "TEST_TREE.IndefiniteLengthTest", 0, 0, ASN1_SUCCESS,
+ __LINE__},
{ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_DECODING_START_END, "seq1", "START", 2, ASN1_SUCCESS, __LINE__},
{ACT_DECODING_START_END, "seq1", "END", 8, ASN1_SUCCESS, __LINE__},
@@ -251,8 +264,10 @@ test_type test_array[] = {
/* Test: READ TAG and CLASS */
{ACT_CREATE, "TEST_TREE.SequenceTestTag", 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_READ_TAG_CLASS, "int", "", 0, ASN1_ELEMENT_NOT_FOUND, __LINE__},
- {ACT_READ_TAG_CLASS, "int1", "TAG", ASN1_TAG_INTEGER, ASN1_SUCCESS, __LINE__},
- {ACT_READ_TAG_CLASS, "int1", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS, __LINE__},
+ {ACT_READ_TAG_CLASS, "int1", "TAG", ASN1_TAG_INTEGER, ASN1_SUCCESS,
+ __LINE__},
+ {ACT_READ_TAG_CLASS, "int1", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS,
+ __LINE__},
{ACT_READ_TAG_CLASS, "int2", "TAG", 3, ASN1_SUCCESS, __LINE__},
{ACT_READ_TAG_CLASS, "int2", "CLASS", ASN1_CLASS_CONTEXT_SPECIFIC,
ASN1_SUCCESS, __LINE__},
@@ -260,9 +275,11 @@ test_type test_array[] = {
{ACT_READ_TAG_CLASS, "str1", "CLASS", ASN1_CLASS_CONTEXT_SPECIFIC,
ASN1_SUCCESS, __LINE__},
{ACT_READ_TAG_CLASS, "str2", "TAG", 28, ASN1_SUCCESS, __LINE__},
- {ACT_READ_TAG_CLASS, "str2", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS, __LINE__},
+ {ACT_READ_TAG_CLASS, "str2", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS,
+ __LINE__},
{ACT_READ_TAG_CLASS, "str3", "TAG", 28, ASN1_SUCCESS, __LINE__},
- {ACT_READ_TAG_CLASS, "str3", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS, __LINE__},
+ {ACT_READ_TAG_CLASS, "str3", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS,
+ __LINE__},
{ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
{ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
@@ -277,7 +294,8 @@ test_type test_array[] = {
{ACT_READ, "id", "2.5.29.2", 9, ASN1_SUCCESS, __LINE__},
{ACT_READ_LENGTH, "id", NULL, 9, ASN1_MEM_ERROR, __LINE__},
{ACT_WRITE, "any1", "\x02\x01\x05", 3, ASN1_SUCCESS, __LINE__},
- {ACT_READ_DEFINITIONS, "TEST_TREE.id-anyTest", "2.5.29.1", 9, ASN1_SUCCESS, __LINE__},
+ {ACT_READ_DEFINITIONS, "TEST_TREE.id-anyTest", "2.5.29.1", 9, ASN1_SUCCESS,
+ __LINE__},
{ACT_ENCODING_LENGTH, "", 0, 20, ASN1_MEM_ERROR, __LINE__},
{ACT_ENCODING, "", 0, 19, ASN1_MEM_ERROR, __LINE__},
{ACT_ENCODING, "", 0, 200, ASN1_SUCCESS, __LINE__},
@@ -448,7 +466,7 @@ main (int argc, char *argv[])
int start, end, verbose = 0;
const char *str_p = NULL;
const char *treefile = getenv ("ASN1TREE");
-
+
if (argc > 1)
verbose = 1;
@@ -582,20 +600,21 @@ main (int argc, char *argv[])
case ACT_VISIT:
if (verbose)
{
- asn1_print_structure (out, asn1_element, test->par1, test->par3);
- fprintf (out, "\n");
- }
+ asn1_print_structure (out, asn1_element, test->par1,
+ test->par3);
+ fprintf (out, "\n");
+ }
result = ASN1_SUCCESS;
break;
case ACT_PRINT_DER:
if (verbose)
{
- printf ("DER encoding len:%i\n", der_len);
- printf ("DER encoding: ");
- for (k = 0; k < der_len; k++)
- printf ("%02x ", der[k]);
+ printf ("DER encoding len:%i\n", der_len);
+ printf ("DER encoding: ");
+ for (k = 0; k < der_len; k++)
+ printf ("%02x ", der[k]);
printf ("\n\n");
- }
+ }
result = ASN1_SUCCESS;
break;
case ACT_SET_DER:
@@ -634,7 +653,7 @@ main (int argc, char *argv[])
printf (" Error expected: %s\n",
asn1_strerror (test->errorNumber));
printf (" Error detected: %s\n\n", asn1_strerror (result));
- error();
+ error ();
}
break;
case ACT_DECODING_ELEMENT:
@@ -648,7 +667,7 @@ main (int argc, char *argv[])
asn1_strerror (test->errorNumber));
printf (" Error detected: %s\n", asn1_strerror (result));
printf (" Error description : %s\n\n", errorDescription);
- error();
+ error ();
}
break;
case ACT_NUMBER_OF_ELEMENTS:
@@ -662,7 +681,7 @@ main (int argc, char *argv[])
asn1_strerror (test->errorNumber), test->par3);
printf (" Error detected: %s - %d\n\n", asn1_strerror (result),
valueLen);
- error();
+ error ();
}
break;
case ACT_ENCODING_LENGTH:
@@ -675,7 +694,7 @@ main (int argc, char *argv[])
asn1_strerror (test->errorNumber), test->par3);
printf (" Error detected: %s - %d\n\n", asn1_strerror (result),
der_len);
- error();
+ error ();
}
break;
case ACT_OID_2_STRUCTURE:
@@ -690,7 +709,7 @@ main (int argc, char *argv[])
printf (" Error expected: %s - %s\n",
asn1_strerror (test->errorNumber), test->par2);
printf (" Value detected: %s\n\n", str_p);
- error();
+ error ();
}
break;
case ACT_DECODING_START_END:
@@ -707,7 +726,7 @@ main (int argc, char *argv[])
test->par3);
printf (" Error detected: %s - %d - %d\n\n",
asn1_strerror (result), start, end);
- error();
+ error ();
}
break;
@@ -725,7 +744,7 @@ main (int argc, char *argv[])
test->par3);
printf (" Error detected: %s - %d - %d\n\n",
asn1_strerror (result), tag, class);
- error();
+ error ();
}
break;
@@ -768,7 +787,7 @@ main (int argc, char *argv[])
printf ("%02x", value[k]);
printf ("\n\n");
- error();
+ error ();
}
break;