1 /* $NetBSD: der_cmp.c,v 1.1.1.2 2014/04/24 12:45:28 pettai Exp $ */
4 * Copyright (c) 2003-2005 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 der_heim_oid_cmp(const heim_oid
*p
, const heim_oid
*q
)
41 if (p
->length
!= q
->length
)
42 return p
->length
- q
->length
;
43 return memcmp(p
->components
,
45 p
->length
* sizeof(*p
->components
));
49 der_heim_octet_string_cmp(const heim_octet_string
*p
,
50 const heim_octet_string
*q
)
52 if (p
->length
!= q
->length
)
53 return p
->length
- q
->length
;
54 return memcmp(p
->data
, q
->data
, p
->length
);
58 der_printable_string_cmp(const heim_printable_string
*p
,
59 const heim_printable_string
*q
)
61 return der_heim_octet_string_cmp(p
, q
);
65 der_ia5_string_cmp(const heim_ia5_string
*p
,
66 const heim_ia5_string
*q
)
68 return der_heim_octet_string_cmp(p
, q
);
72 der_heim_bit_string_cmp(const heim_bit_string
*p
,
73 const heim_bit_string
*q
)
76 if (p
->length
!= q
->length
)
77 return p
->length
- q
->length
;
78 i
= memcmp(p
->data
, q
->data
, p
->length
/ 8);
81 if ((p
->length
% 8) == 0)
84 r1
= ((unsigned char *)p
->data
)[i
];
85 r2
= ((unsigned char *)q
->data
)[i
];
86 i
= 8 - (p
->length
% 8);
93 der_heim_integer_cmp(const heim_integer
*p
,
94 const heim_integer
*q
)
96 if (p
->negative
!= q
->negative
)
97 return q
->negative
- p
->negative
;
98 if (p
->length
!= q
->length
)
99 return p
->length
- q
->length
;
100 return memcmp(p
->data
, q
->data
, p
->length
);
104 der_heim_bmp_string_cmp(const heim_bmp_string
*p
, const heim_bmp_string
*q
)
106 if (p
->length
!= q
->length
)
107 return p
->length
- q
->length
;
108 return memcmp(p
->data
, q
->data
, q
->length
* sizeof(q
->data
[0]));
112 der_heim_universal_string_cmp(const heim_universal_string
*p
,
113 const heim_universal_string
*q
)
115 if (p
->length
!= q
->length
)
116 return p
->length
- q
->length
;
117 return memcmp(p
->data
, q
->data
, q
->length
* sizeof(q
->data
[0]));