1/* 2 * Copyright (c) 2011-12 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 * Copyright (c) 2003-2005 Kungliga Tekniska Högskolan 25 * (Royal Institute of Technology, Stockholm, Sweden). 26 * All rights reserved. 27 * 28 * Redistribution and use in source and binary forms, with or without 29 * modification, are permitted provided that the following conditions 30 * are met: 31 * 32 * 1. Redistributions of source code must retain the above copyright 33 * notice, this list of conditions and the following disclaimer. 34 * 35 * 2. Redistributions in binary form must reproduce the above copyright 36 * notice, this list of conditions and the following disclaimer in the 37 * documentation and/or other materials provided with the distribution. 38 * 39 * 3. Neither the name of the Institute nor the names of its contributors 40 * may be used to endorse or promote products derived from this software 41 * without specific prior written permission. 42 * 43 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 46 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 53 * SUCH DAMAGE. 54 */ 55 56#include "asn1-der_locl.h" 57 58int 59der_heim_oid_cmp(const heim_oid *p, const heim_oid *q) 60{ 61 if (p->length != q->length) 62 return p->length - q->length; 63 return memcmp(p->components, 64 q->components, 65 p->length * sizeof(*p->components)); 66} 67 68int 69der_heim_octet_string_cmp(const heim_octet_string *p, 70 const heim_octet_string *q) 71{ 72 if (p->length != q->length) 73 return p->length - q->length; 74 return memcmp(p->data, q->data, p->length); 75} 76 77int 78der_printable_string_cmp(const heim_printable_string *p, 79 const heim_printable_string *q) 80{ 81 return der_heim_octet_string_cmp(p, q); 82} 83 84int 85der_ia5_string_cmp(const heim_ia5_string *p, 86 const heim_ia5_string *q) 87{ 88 return der_heim_octet_string_cmp(p, q); 89} 90 91int 92der_heim_bit_string_cmp(const heim_bit_string *p, 93 const heim_bit_string *q) 94{ 95 int i, r1, r2; 96 if (p->length != q->length) 97 return p->length - q->length; 98 i = memcmp(p->data, q->data, p->length / 8); 99 if (i) 100 return i; 101 if ((p->length % 8) == 0) 102 return 0; 103 i = (p->length / 8); 104 r1 = ((unsigned char *)p->data)[i]; 105 r2 = ((unsigned char *)q->data)[i]; 106 i = 8 - (p->length % 8); 107 r1 = r1 >> i; 108 r2 = r2 >> i; 109 return r1 - r2; 110} 111 112int 113der_heim_integer_cmp(const heim_integer *p, 114 const heim_integer *q) 115{ 116 if (p->negative != q->negative) 117 return q->negative - p->negative; 118 if (p->length != q->length) 119 return p->length - q->length; 120 return memcmp(p->data, q->data, p->length); 121} 122 123int 124der_heim_bmp_string_cmp(const heim_bmp_string *p, const heim_bmp_string *q) 125{ 126 if (p->length != q->length) 127 return p->length - q->length; 128 return memcmp(p->data, q->data, q->length * sizeof(q->data[0])); 129} 130 131int 132der_heim_universal_string_cmp(const heim_universal_string *p, 133 const heim_universal_string *q) 134{ 135 if (p->length != q->length) 136 return p->length - q->length; 137 return memcmp(p->data, q->data, q->length * sizeof(q->data[0])); 138} 139