make printablestring and ia5string octetstrings
This commit is contained in:
@@ -20,8 +20,8 @@ typedef struct heim_octet_string {
|
||||
|
||||
typedef char *heim_general_string;
|
||||
typedef char *heim_utf8_string;
|
||||
typedef char *heim_printable_string;
|
||||
typedef char *heim_ia5_string;
|
||||
typedef struct heim_octet_string heim_printable_string;
|
||||
typedef struct heim_octet_string heim_ia5_string;
|
||||
|
||||
typedef struct heim_bmp_string {
|
||||
size_t length;
|
||||
|
@@ -181,11 +181,33 @@ loop (unsigned char *buf, size_t len, int indent)
|
||||
free (str.data);
|
||||
break;
|
||||
}
|
||||
case UT_IA5String :
|
||||
case UT_PrintableString : {
|
||||
heim_printable_string str;
|
||||
unsigned char *s;
|
||||
size_t n;
|
||||
|
||||
memset(&str, 0, sizeof(str));
|
||||
|
||||
ret = der_get_printable_string (buf, length, &str, NULL);
|
||||
if (ret)
|
||||
errx (1, "der_get_general_string: %s",
|
||||
error_message (ret));
|
||||
s = str.data;
|
||||
printf("\"");
|
||||
for (n = 0; n < str.length; n++) {
|
||||
if (isprint((int)s[n]))
|
||||
printf ("%c", s[n]);
|
||||
else
|
||||
printf ("#%02x", s[n]);
|
||||
}
|
||||
printf("\"\n");
|
||||
der_free_printable_string(&str);
|
||||
break;
|
||||
}
|
||||
case UT_GeneralizedTime :
|
||||
case UT_GeneralString :
|
||||
case UT_PrintableString :
|
||||
case UT_VisibleString :
|
||||
case UT_IA5String :
|
||||
case UT_UTF8String : {
|
||||
heim_general_string str;
|
||||
|
||||
|
@@ -352,12 +352,14 @@ test_Name (void)
|
||||
atv1[0].type.length = sizeof(cmp_CN)/sizeof(cmp_CN[0]);
|
||||
atv1[0].type.components = cmp_CN;
|
||||
atv1[0].value.element = choice_DirectoryString_printableString;
|
||||
atv1[0].value.u.printableString = "Love";
|
||||
atv1[0].value.u.printableString.data = "Love";
|
||||
atv1[0].value.u.printableString.length = 4;
|
||||
|
||||
atv1[1].type.length = sizeof(cmp_L)/sizeof(cmp_L[0]);
|
||||
atv1[1].type.components = cmp_L;
|
||||
atv1[1].value.element = choice_DirectoryString_printableString;
|
||||
atv1[1].value.u.printableString = "STOCKHOLM";
|
||||
atv1[1].value.u.printableString.data = "STOCKHOLM";
|
||||
atv1[1].value.u.printableString.length = 9;
|
||||
|
||||
/* n2 */
|
||||
n2.element = choice_Name_rdnSequence;
|
||||
@@ -369,12 +371,14 @@ test_Name (void)
|
||||
atv2[0].type.length = sizeof(cmp_L)/sizeof(cmp_L[0]);
|
||||
atv2[0].type.components = cmp_L;
|
||||
atv2[0].value.element = choice_DirectoryString_printableString;
|
||||
atv2[0].value.u.printableString = "STOCKHOLM";
|
||||
atv2[0].value.u.printableString.data = "STOCKHOLM";
|
||||
atv2[0].value.u.printableString.length = 9;
|
||||
|
||||
atv2[1].type.length = sizeof(cmp_CN)/sizeof(cmp_CN[0]);
|
||||
atv2[1].type.components = cmp_CN;
|
||||
atv2[1].value.element = choice_DirectoryString_printableString;
|
||||
atv2[1].value.u.printableString = "Love";
|
||||
atv2[1].value.u.printableString.data = "Love";
|
||||
atv2[1].value.u.printableString.length = 4;
|
||||
|
||||
/* */
|
||||
tests[0].val = &n1;
|
||||
|
@@ -52,6 +52,20 @@ der_heim_octet_string_cmp(const heim_octet_string *p,
|
||||
return memcmp(p->data, q->data, p->length);
|
||||
}
|
||||
|
||||
int
|
||||
der_printable_string_cmp(const heim_printable_string *p,
|
||||
const heim_printable_string *q)
|
||||
{
|
||||
return der_heim_octet_string_cmp(q, q);
|
||||
}
|
||||
|
||||
int
|
||||
der_ia5_string_cmp(const heim_ia5_string *p,
|
||||
const heim_ia5_string *q)
|
||||
{
|
||||
return der_heim_octet_string_cmp(q, q);
|
||||
}
|
||||
|
||||
int
|
||||
der_heim_bit_string_cmp(const heim_bit_string *p,
|
||||
const heim_bit_string *q)
|
||||
|
@@ -85,14 +85,20 @@ int
|
||||
der_copy_printable_string (const heim_printable_string *from,
|
||||
heim_printable_string *to)
|
||||
{
|
||||
return der_copy_general_string(from, to);
|
||||
to->length = from->length;
|
||||
to->data = malloc(to->length + 1);
|
||||
if(to->data == NULL)
|
||||
return ENOMEM;
|
||||
memcpy(to->data, from->data, to->length);
|
||||
((char *)to->data)[to->length] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
der_copy_ia5_string (const heim_printable_string *from,
|
||||
heim_printable_string *to)
|
||||
der_copy_ia5_string (const heim_ia5_string *from,
|
||||
heim_ia5_string *to)
|
||||
{
|
||||
return der_copy_general_string(from, to);
|
||||
return der_copy_printable_string(from, to);
|
||||
}
|
||||
|
||||
int
|
||||
|
@@ -79,15 +79,13 @@ der_free_utf8string (heim_utf8_string *str)
|
||||
void
|
||||
der_free_printable_string (heim_printable_string *str)
|
||||
{
|
||||
free(*str);
|
||||
*str = NULL;
|
||||
der_free_octet_string(str);
|
||||
}
|
||||
|
||||
void
|
||||
der_free_ia5_string (heim_ia5_string *str)
|
||||
{
|
||||
free(*str);
|
||||
*str = NULL;
|
||||
der_free_octet_string(str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -167,17 +167,24 @@ der_get_utf8string (const unsigned char *p, size_t len,
|
||||
}
|
||||
|
||||
int
|
||||
der_get_printable_string (const unsigned char *p, size_t len,
|
||||
heim_printable_string *str, size_t *size)
|
||||
der_get_printable_string(const unsigned char *p, size_t len,
|
||||
heim_printable_string *str, size_t *size)
|
||||
{
|
||||
return der_get_general_string(p, len, str, size);
|
||||
str->length = len;
|
||||
str->data = malloc(len + 1);
|
||||
if (str->data == NULL)
|
||||
return ENOMEM;
|
||||
memcpy(str->data, p, len);
|
||||
((char *)str->data)[len] = '\0';
|
||||
if(size) *size = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
der_get_ia5_string (const unsigned char *p, size_t len,
|
||||
heim_ia5_string *str, size_t *size)
|
||||
der_get_ia5_string(const unsigned char *p, size_t len,
|
||||
heim_ia5_string *str, size_t *size)
|
||||
{
|
||||
return der_get_general_string(p, len, str, size);
|
||||
return der_get_printable_string(p, len, str, size);
|
||||
}
|
||||
|
||||
int
|
||||
|
@@ -161,13 +161,13 @@ der_length_utf8string (const heim_utf8_string *data)
|
||||
size_t
|
||||
der_length_printable_string (const heim_printable_string *data)
|
||||
{
|
||||
return strlen(*data);
|
||||
return data->length;
|
||||
}
|
||||
|
||||
size_t
|
||||
der_length_ia5_string (const heim_ia5_string *data)
|
||||
{
|
||||
return strlen(*data);
|
||||
return data->length;
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@@ -181,14 +181,14 @@ int
|
||||
der_put_printable_string (unsigned char *p, size_t len,
|
||||
const heim_printable_string *str, size_t *size)
|
||||
{
|
||||
return der_put_general_string(p, len, str, size);
|
||||
return der_put_octet_string(p, len, str, size);
|
||||
}
|
||||
|
||||
int
|
||||
der_put_ia5_string (unsigned char *p, size_t len,
|
||||
const heim_ia5_string *str, size_t *size)
|
||||
{
|
||||
return der_put_general_string(p, len, str, size);
|
||||
return der_put_octet_string(p, len, str, size);
|
||||
}
|
||||
|
||||
int
|
||||
|
@@ -181,10 +181,10 @@ init_generate (const char *filename, const char *base)
|
||||
"typedef char *heim_utf8_string;\n\n"
|
||||
);
|
||||
fprintf (headerfile,
|
||||
"typedef char *heim_printable_string;\n\n"
|
||||
"typedef struct heim_octet_string heim_printable_string;\n\n"
|
||||
);
|
||||
fprintf (headerfile,
|
||||
"typedef char *heim_ia5_string;\n\n"
|
||||
"typedef struct heim_octet_string heim_ia5_string;\n\n"
|
||||
);
|
||||
fprintf (headerfile,
|
||||
"typedef struct heim_bmp_string {\n"
|
||||
|
Reference in New Issue
Block a user