2 * Copyright (c) 2003 - 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
37 #include "heim_asn1.h"
39 #include <vis-extras.h>
44 encode_heim_any(unsigned char *p, size_t len,
45 const heim_any *data, size_t *size)
47 return der_put_octet_string (p, len, data, size);
51 decode_heim_any(const unsigned char *p, size_t len,
52 heim_any *data, size_t *size)
54 size_t len_len, length, l;
60 memset(data, 0, sizeof(*data));
62 e = der_get_tag (p, len, &thisclass, &thistype, &thistag, &l);
66 e = der_get_length(p + l, len - l, &length, &len_len);
68 if (length == ASN1_INDEFINITE) {
69 if (len < len_len + l)
71 length = len - (len_len + l);
73 if (len < length + len_len + l)
77 data->data = malloc(length + len_len + l);
78 if (data->data == NULL)
80 data->length = length + len_len + l;
81 memcpy(data->data, p, length + len_len + l);
84 *size = length + len_len + l;
90 free_heim_any(heim_any *data)
92 der_free_octet_string(data);
96 print_heim_any(const heim_any *data, int flags)
99 char *s = der_print_octet_string(data, 0);
104 r = rk_strasvis(&s2, s, VIS_CSTYLE|VIS_TAB|VIS_NL, "\"");
108 r = asprintf(&s, "\"%s\"", s2);
114 length_heim_any(const heim_any *data)
120 copy_heim_any(const heim_any *from, heim_any *to)
122 return der_copy_octet_string(from, to);
126 encode_HEIM_ANY(unsigned char *p, size_t len,
127 const heim_any *data, size_t *size)
129 return encode_heim_any(p, len, data, size);
133 decode_HEIM_ANY(const unsigned char *p, size_t len,
134 heim_any *data, size_t *size)
136 return decode_heim_any(p, len, data, size);
140 free_HEIM_ANY(heim_any *data)
142 der_free_octet_string(data);
146 print_HEIM_ANY(const heim_any *data, int flags)
149 char *s = der_print_octet_string(data, 0);
154 r = rk_strasvis(&s2, s, VIS_CSTYLE|VIS_TAB|VIS_NL, "\"");
158 r = asprintf(&s, "\"%s\"", s2);
164 length_HEIM_ANY(const heim_any *data)
170 copy_HEIM_ANY(const heim_any *from, heim_any *to)
172 return der_copy_octet_string(from, to);
176 encode_heim_any_set(unsigned char *p, size_t len,
177 const heim_any_set *data, size_t *size)
179 return der_put_octet_string (p, len, data, size);
183 decode_heim_any_set(const unsigned char *p, size_t len,
184 heim_any_set *data, size_t *size)
186 return der_get_octet_string(p, len, data, size);
190 free_heim_any_set(heim_any_set *data)
192 der_free_octet_string(data);
196 print_heim_any_set(const heim_any_set *data, int flags)
199 char *s = der_print_octet_string(data, 0);
204 r = rk_strasvis(&s2, s, VIS_CSTYLE|VIS_TAB|VIS_NL, "\"");
208 r = asprintf(&s, "\"%s\"", s2);
214 length_heim_any_set(const heim_any *data)
220 copy_heim_any_set(const heim_any_set *from, heim_any_set *to)
222 return der_copy_octet_string(from, to);
226 heim_any_cmp(const heim_any_set *p, const heim_any_set *q)
228 return der_heim_octet_string_cmp(p, q);
232 encode_HEIM_ANY_SET(unsigned char *p, size_t len,
233 const heim_any_set *data, size_t *size)
235 return encode_heim_any_set(p, len, data, size);
239 decode_HEIM_ANY_SET(const unsigned char *p, size_t len,
240 heim_any_set *data, size_t *size)
242 return decode_heim_any_set(p, len, data, size);
246 free_HEIM_ANY_SET(heim_any_set *data)
248 der_free_octet_string(data);
252 print_HEIM_ANY_SET(const heim_any_set *data, int flags)
255 char *s = der_print_octet_string(data, 0);
260 r = rk_strasvis(&s2, s, VIS_CSTYLE|VIS_TAB|VIS_NL, "\"");
264 r = asprintf(&s, "\"%s\"", s2);
270 length_HEIM_ANY_SET(const heim_any *data)
276 copy_HEIM_ANY_SET(const heim_any_set *from, heim_any_set *to)
278 return der_copy_octet_string(from, to);
282 HEIM_ANY_cmp(const heim_any_set *p, const heim_any_set *q)
284 return der_heim_octet_string_cmp(p, q);