2 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
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
41 _heim_len_unsigned (unsigned val
)
48 last_val_gt_128
= (val
>= 128);
59 _heim_len_int (int val
)
86 len_oid (const heim_oid
*oid
)
91 for (n
= 2; n
< oid
->length
; ++n
) {
92 unsigned u
= oid
->components
[n
];
103 der_length_len (size_t len
)
118 der_length_tag(unsigned int tag
)
132 der_length_integer (const int *data
)
134 return _heim_len_int (*data
);
138 der_length_unsigned (const unsigned *data
)
140 return _heim_len_unsigned(*data
);
144 der_length_enumerated (const unsigned *data
)
146 return _heim_len_int (*data
);
150 der_length_general_string (const heim_general_string
*data
)
152 return strlen(*data
);
156 der_length_utf8string (const heim_utf8_string
*data
)
158 return strlen(*data
);
162 der_length_printable_string (const heim_printable_string
*data
)
164 return strlen(*data
);
168 der_length_ia5_string (const heim_ia5_string
*data
)
170 return strlen(*data
);
174 der_length_bmp_string (const heim_bmp_string
*data
)
176 return data
->length
* 2;
180 der_length_universal_string (const heim_universal_string
*data
)
182 return data
->length
* 4;
186 der_length_visible_string (const heim_visible_string
*data
)
188 return strlen(*data
);
192 der_length_octet_string (const heim_octet_string
*k
)
198 der_length_heim_integer (const heim_integer
*k
)
203 return k
->length
+ (((~(((unsigned char *)k
->data
)[0])) & 0x80) ? 0 : 1);
205 return k
->length
+ ((((unsigned char *)k
->data
)[0] & 0x80) ? 1 : 0);
209 der_length_oid (const heim_oid
*k
)
215 der_length_generalized_time (const time_t *t
)
220 _heim_time2generalizedtime (*t
, &k
, 1);
227 der_length_utctime (const time_t *t
)
232 _heim_time2generalizedtime (*t
, &k
, 0);
239 der_length_boolean (const int *k
)
245 der_length_bit_string (const heim_bit_string
*k
)
247 return (k
->length
+ 7) / 8 + 1;