{
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--)
* 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;
/* 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;
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 */
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);
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;
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
if (ans >= INT_MAX || INT_ADD_OVERFLOW (sum, (*len)))
return -2;
sum += *len;
-
+
if (sum > der_len)
return -4;
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;
}
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;
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;
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);
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;
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);
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);
_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);
while (1)
{
if (p == NULL)
- return ASN1_DER_ERROR;
+ return ASN1_DER_ERROR;
ris = ASN1_SUCCESS;
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)
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,
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,
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);
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;
* 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;
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;
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)
_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:
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);
}
/**
* 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;
*
* 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;
}
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);
dest[str_size] = 0;
return str_size;
}
- else return 0;
+ else
+ return 0;
}
}
* 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)
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 */
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 */
/* 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;
*/
#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>
{
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;
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);
/* 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);
/* 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
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;
}
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;
}
asn1_node
_asn1_set_name (asn1_node node, const char *name)
{
-unsigned int nsize;
+ unsigned int nsize;
if (node == NULL)
return node;
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;
}
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;
}
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)
{
_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);
{
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)
_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;
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;
}
}
_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;
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)
}
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);
{
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)
{
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)
{
case ASN1_ETYPE_DEFINITIONS:
fprintf (out, "type:DEFINITIONS");
break;
- CASE_HANDLED_ETYPES:
+ CASE_HANDLED_ETYPES:
fprintf (out, "%s", _asn1_tags[type].desc);
break;
default:
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;
#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);
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:
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)
if (inputFile == NULL)
{
fprintf (stderr, "asn1Coding: file '%s' not found\n",
- inputFileAssignmentName);
+ inputFileAssignmentName);
free (inputFileAsnName);
free (inputFileAssignmentName);
exit (1);
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)
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);
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);
#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)
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);
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:
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)
if (der == NULL)
{
fprintf (stderr, "asn1Decoding: could not read '%s'\n",
- inputFileDerName);
+ inputFileDerName);
asn1_delete_structure (&definitions);
free (inputFileAsnName);
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);
free (der);
exit (1);
}
-
+
asn1_delete_structure (&definitions);
free (der);
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);
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;
}
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;
}
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);
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:
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));
}
static void
value2human (unsigned long bytes, double secs, double *data, double *speed,
- char *metric)
+ char *metric)
{
if (bytes > 1000 && bytes < 1000 * 1000)
{
}
}
-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
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;
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);
#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
{
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)));
}
printf ("\n\n/****************************************/\n");
printf ("/* Test sequence : coding-decoding */\n");
printf ("/****************************************/\n\n");
- }
+ }
/* Check version */
if (asn1_check_version ("0.3.3") == NULL)
asn1_delete_structure (&asn1_element);
- if (verbose) printf ("Success\n");
+ if (verbose)
+ printf ("Success\n");
exit (0);
}
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);
#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;
if (l == -2L)
{
- if (verbose) puts ("OK: asn1_get_length_der bignum");
+ if (verbose)
+ puts ("OK: asn1_get_length_der bignum");
}
else
{
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,
/* 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;
}
/* 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) */
{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"},
{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, ""},
test_type *test;
int errorCounter = 0, testCounter = 0;
int verbose = 0;
-
+
if (argc > 1)
verbose = 1;
asn1_strerror (test->errorNumber), test->errorDescription);
printf (" Error detected: %s - %s\n\n", asn1_strerror (result),
errorDescription);
- exit(1);
+ exit (1);
}
test++;
};
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
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 */
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;
+ }
}
{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__},
{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__},
{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__},
"\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__},
/* 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__},
{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__},
{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__},
int start, end, verbose = 0;
const char *str_p = NULL;
const char *treefile = getenv ("ASN1TREE");
-
+
if (argc > 1)
verbose = 1;
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:
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:
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:
asn1_strerror (test->errorNumber), test->par3);
printf (" Error detected: %s - %d\n\n", asn1_strerror (result),
valueLen);
- error();
+ error ();
}
break;
case ACT_ENCODING_LENGTH:
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:
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:
test->par3);
printf (" Error detected: %s - %d - %d\n\n",
asn1_strerror (result), start, end);
- error();
+ error ();
}
break;
test->par3);
printf (" Error detected: %s - %d - %d\n\n",
asn1_strerror (result), tag, class);
- error();
+ error ();
}
break;
printf ("%02x", value[k]);
printf ("\n\n");
- error();
+ error ();
}
break;