/* ASN1_SUCCESS otherwise */
/******************************************************/
static int
-_asn1_time_der (unsigned char *str, 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;
- int str_len = _asn1_strlen (str);
max_len = *der_len;
goto error;
}
len2 = max_len;
- err = _asn1_time_der (p->value, der + counter, &len2);
+ err = _asn1_time_der (p->value, p->value_len, der + counter, &len2);
if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR)
goto error;
tlen = strlen (temp);
if (tlen > 0)
- _asn1_set_value (p, temp, tlen + 1);
+ _asn1_set_value (p, temp, tlen);
counter += len2;
move = RIGHT;
break;
default:
return ASN1_VALUE_NOT_FOUND;
}
- _asn1_set_value (node, value, _asn1_strlen (value) + 1);
+ _asn1_set_value (node, value, _asn1_strlen (value));
}
break;
case ASN1_ETYPE_GENERALIZED_TIME:
if (value)
- _asn1_set_value (node, value, _asn1_strlen (value) + 1);
+ _asn1_set_value (node, value, _asn1_strlen (value));
break;
case ASN1_ETYPE_OCTET_STRING:
case ASN1_ETYPE_GENERALSTRING:
_asn1_strcpy(ptr, data); \
}
+#define PUT_AS_STR_VALUE( ptr, ptr_size, data, data_size) \
+ *len = data_size + 1; \
+ if (ptr_size < *len) { \
+ return ASN1_MEM_ERROR; \
+ } else { \
+ /* this strcpy is checked */ \
+ memcpy(ptr, data, data_size); \
+ ptr[data_size] = 0; \
+ }
+
#define ADD_STR_VALUE( ptr, ptr_size, data) \
*len = (int) _asn1_strlen(data) + 1; \
if (ptr_size < (int) _asn1_strlen(ptr)+(*len)) { \
break;
case ASN1_ETYPE_GENERALIZED_TIME:
case ASN1_ETYPE_UTC_TIME:
- PUT_STR_VALUE (value, value_size, node->value);
+ PUT_AS_STR_VALUE (value, value_size, node->value, node->value_len);
break;
case ASN1_ETYPE_OCTET_STRING:
case ASN1_ETYPE_GENERALSTRING:
return type;
}
+/* To convert old types from a static structure */
+inline static unsigned int convert_old_type(unsigned int ntype)
+{
+unsigned int type = ntype & 0xff;
+ if (type == ASN1_ETYPE_TIME)
+ {
+ if (type & CONST_UTC)
+ type = ASN1_ETYPE_UTC_TIME;
+ else
+ type = ASN1_ETYPE_GENERALIZED_TIME;
+
+ return type | ((ntype>>8)<<8);
+ }
+ else
+ return ntype;
+}
#endif /* INT_H */
/* Description: creates a new NODE_ASN element and */
/* puts it in the list pointed by firstElement. */
/* Parameters: */
-/* type: type of the new element (see ASN1_ETYPE_ */
+/* type: type of the new element (see ASN1_ETYPE_ */
/* and CONST_ constants). */
/* Return: pointer to the new element. */
/******************************************************/
listElement->next = firstElement;
firstElement = listElement;
- punt->type = type;
+ punt->type = convert_old_type(type);
return punt;
}
fprintf (out, "%02x", (p->value)[k + len2]);
}
break;
- case ASN1_ETYPE_GENERALIZED_TIME:
- case ASN1_ETYPE_UTC_TIME:
- if (p->value)
- fprintf (out, " value:%s", p->value);
- break;
case ASN1_ETYPE_BOOLEAN:
if (p->value)
{
}
}
break;
- case ASN1_ETYPE_OCTET_STRING:
+ case ASN1_ETYPE_GENERALIZED_TIME:
+ case ASN1_ETYPE_UTC_TIME:
+ if (p->value)
+ {
+ fprintf (out, " value:");
+ for (k = 0; k < p->value_len; k++)
+ fprintf (out, "%c", (p->value)[k]);
+ }
+ 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:
if (p->value)
fprintf (out, " value:");
if (len > 0)
for (k = 0; k < len; k++)
+ fprintf (out, "%c", (p->value)[k + len2]);
+ }
+ break;
+ case ASN1_ETYPE_BMP_STRING:
+ case ASN1_ETYPE_OCTET_STRING:
+ if (p->value)
+ {
+ len2 = -1;
+ len = asn1_get_length_der (p->value, p->value_len, &len2);
+ fprintf (out, " value:");
+ if (len > 0)
+ for (k = 0; k < len; k++)
fprintf (out, "%02x", (p->value)[k + len2]);
}
break;