/*1* Copyright (c) 2003-2005 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "der_locl.h"3435int36der_heim_oid_cmp(const heim_oid *p, const heim_oid *q)37{38if (p->length != q->length)39return p->length - q->length;40return memcmp(p->components,41q->components,42p->length * sizeof(*p->components));43}4445int46der_heim_octet_string_cmp(const heim_octet_string *p,47const heim_octet_string *q)48{49if (p->length != q->length)50return p->length - q->length;51return memcmp(p->data, q->data, p->length);52}5354int55der_printable_string_cmp(const heim_printable_string *p,56const heim_printable_string *q)57{58return der_heim_octet_string_cmp(p, q);59}6061int62der_ia5_string_cmp(const heim_ia5_string *p,63const heim_ia5_string *q)64{65return der_heim_octet_string_cmp(p, q);66}6768int69der_heim_bit_string_cmp(const heim_bit_string *p,70const heim_bit_string *q)71{72int i, r1, r2;73if (p->length != q->length)74return p->length - q->length;75i = memcmp(p->data, q->data, p->length / 8);76if (i)77return i;78if ((p->length % 8) == 0)79return 0;80i = (p->length / 8);81r1 = ((unsigned char *)p->data)[i];82r2 = ((unsigned char *)q->data)[i];83i = 8 - (p->length % 8);84r1 = r1 >> i;85r2 = r2 >> i;86return r1 - r2;87}8889int90der_heim_integer_cmp(const heim_integer *p,91const heim_integer *q)92{93if (p->negative != q->negative)94return q->negative - p->negative;95if (p->length != q->length)96return p->length - q->length;97return memcmp(p->data, q->data, p->length);98}99100int101der_heim_bmp_string_cmp(const heim_bmp_string *p, const heim_bmp_string *q)102{103if (p->length != q->length)104return p->length - q->length;105return memcmp(p->data, q->data, q->length * sizeof(q->data[0]));106}107108int109der_heim_universal_string_cmp(const heim_universal_string *p,110const heim_universal_string *q)111{112if (p->length != q->length)113return p->length - q->length;114return memcmp(p->data, q->data, q->length * sizeof(q->data[0]));115}116117118