Exemple #1
0
static int
cmp_universal_string (void *a, void *b)
{
    heim_universal_string *oa = (heim_universal_string *)a;
    heim_universal_string *ob = (heim_universal_string *)b;

    return der_heim_universal_string_cmp(oa, ob);
}
Exemple #2
0
int
_hx509_name_ds_cmp(const DirectoryString *ds1, const DirectoryString *ds2)
{
    int c;

    c = ds1->element - ds2->element;
    if (c)
	return c;

    switch(ds1->element) {
    case choice_DirectoryString_ia5String:
	c = strcmp(ds1->u.ia5String, ds2->u.ia5String);
	break;
    case choice_DirectoryString_teletexString:
	c = der_heim_octet_string_cmp(&ds1->u.teletexString,
				  &ds2->u.teletexString);
	break;
    case choice_DirectoryString_printableString: {
	const unsigned char *s1 = (unsigned char*)ds1->u.printableString;
	const unsigned char *s2 = (unsigned char*)ds2->u.printableString;
	prune_space(&s1); prune_space(&s2);
	while (*s1 && *s2) {
	    if (toupper(*s1) != toupper(*s2)) {
		c = toupper(*s1) - toupper(*s2);
		break;
	    }
	    if (*s1 == ' ') { prune_space(&s1); prune_space(&s2); }
	    else { s1++; s2++; }
	}	    
	prune_space(&s1); prune_space(&s2);
	c = *s1 - *s2;
	break;
    }
    case choice_DirectoryString_utf8String:
	c = strcmp(ds1->u.utf8String, ds2->u.utf8String);
	break;
    case choice_DirectoryString_universalString:
	c = der_heim_universal_string_cmp(&ds1->u.universalString,
					  &ds2->u.universalString);
	break;
    case choice_DirectoryString_bmpString:
	c = der_heim_bmp_string_cmp(&ds1->u.bmpString,
				    &ds2->u.bmpString);
	break;
    default:
	c = 1;
	break;
    }
    return c;
}
Exemple #3
0
static int
test_misc_cmp(void)
{
    int ret;

    /* diffrent lengths are diffrent */
    {
	const heim_octet_string os1 = { 1, "a" } , os2 = { 0, NULL };
	ret = der_heim_octet_string_cmp(&os1, &os2);
	if (ret == 0)
	    return 1;
    }
    /* diffrent data are diffrent */
    {
	const heim_octet_string os1 = { 1, "a" } , os2 = { 1, "b" };
	ret = der_heim_octet_string_cmp(&os1, &os2);
	if (ret == 0)
	    return 1;
    }
    /* diffrent lengths are diffrent */
    {
	const heim_bit_string bs1 = { 8, "a" } , bs2 = { 7, "a" };
	ret = der_heim_bit_string_cmp(&bs1, &bs2);
	if (ret == 0)
	    return 1;
    }
    /* diffrent data are diffrent */
    {
	const heim_bit_string bs1 = { 7, "\x0f" } , bs2 = { 7, "\x02" };
	ret = der_heim_bit_string_cmp(&bs1, &bs2);
	if (ret == 0)
	    return 1;
    }
    /* diffrent lengths are diffrent */
    {
	uint16_t data = 1;
	heim_bmp_string bs1 = { 1, NULL } , bs2 = { 0, NULL };
	bs1.data = &data;
	ret = der_heim_bmp_string_cmp(&bs1, &bs2);
	if (ret == 0)
	    return 1;
    }
    /* diffrent lengths are diffrent */
    {
	uint32_t data;
	heim_universal_string us1 = { 1, NULL } , us2 = { 0, NULL };
	us1.data = &data;
	ret = der_heim_universal_string_cmp(&us1, &us2);
	if (ret == 0)
	    return 1;
    }
    /* same */
    {
	uint32_t data = (uint32_t)'a';
	heim_universal_string us1 = { 1, NULL } , us2 = { 1, NULL };
	us1.data = &data;
	us2.data = &data;
	ret = der_heim_universal_string_cmp(&us1, &us2);
	if (ret != 0)
	    return 1;
    }

    return 0;
}