asn1: Fix some of the primitive comparators

The comparators for BIT STRING and unconstrained INTEGER need help too.
This commit is contained in:
Nicolas Williams
2021-02-24 22:11:41 -06:00
parent 6747e16283
commit dbb8882971

View File

@@ -36,20 +36,44 @@
int int
der_heim_oid_cmp(const heim_oid *p, const heim_oid *q) der_heim_oid_cmp(const heim_oid *p, const heim_oid *q)
{ {
if (p->length != q->length) int c;
return (int)(p->length - q->length);
return memcmp(p->components, if (p->length == q->length)
q->components, return memcmp(p->components,
p->length * sizeof(*p->components)); q->components,
p->length * sizeof(*p->components));
if (p->length < q->length) {
c = memcmp(p->components,
q->components,
p->length * sizeof(*p->components));
if (c == 0)
return -1;
return c;
}
c = memcmp(p->components,
q->components,
q->length * sizeof(*p->components));
if (c == 0)
return 1;
return c;
} }
int int
der_heim_octet_string_cmp(const heim_octet_string *p, der_heim_octet_string_cmp(const heim_octet_string *p,
const heim_octet_string *q) const heim_octet_string *q)
{ {
if (p->length != q->length) int c;
return (int)(p->length - q->length);
return memcmp(p->data, q->data, p->length); if (p->length == q->length)
return memcmp(p->data, q->data, p->length);
if (p->length < q->length) {
if ((c = memcmp(p->data, q->data, p->length)) == 0)
return -1;
return c;
}
if ((c = memcmp(p->data, q->data, q->length)) == 0)
return 1;
return c;
} }
int int
@@ -102,16 +126,34 @@ der_heim_integer_cmp(const heim_integer *p,
int int
der_heim_bmp_string_cmp(const heim_bmp_string *p, const heim_bmp_string *q) der_heim_bmp_string_cmp(const heim_bmp_string *p, const heim_bmp_string *q)
{ {
if (p->length != q->length) int c;
return (int)(p->length - q->length);
return memcmp(p->data, q->data, q->length * sizeof(q->data[0])); if (p->length == q->length)
return memcmp(p->data, q->data, p->length * sizeof(q->data[0]));
if (p->length < q->length) {
if ((c = memcmp(p->data, q->data, p->length * sizeof(q->data[0]))) == 0)
return -1;
return c;
}
if ((c = memcmp(p->data, q->data, q->length * sizeof(q->data[0]))) == 0)
return 1;
return c;
} }
int int
der_heim_universal_string_cmp(const heim_universal_string *p, der_heim_universal_string_cmp(const heim_universal_string *p,
const heim_universal_string *q) const heim_universal_string *q)
{ {
if (p->length != q->length) int c;
return (int)(p->length - q->length);
return memcmp(p->data, q->data, q->length * sizeof(q->data[0])); if (p->length == q->length)
return memcmp(p->data, q->data, p->length * sizeof(q->data[0]));
if (p->length < q->length) {
if ((c = memcmp(p->data, q->data, p->length * sizeof(q->data[0]))) == 0)
return -1;
return c;
}
if ((c = memcmp(p->data, q->data, q->length * sizeof(q->data[0]))) == 0)
return 1;
return c;
} }