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"
43 encode_heim_any(unsigned char *p
, size_t len
,
44 const heim_any
*data
, size_t *size
)
46 return der_put_octet_string (p
, len
, data
, size
);
50 decode_heim_any(const unsigned char *p
, size_t len
,
51 heim_any
*data
, size_t *size
)
53 size_t len_len
, length
, l
;
59 memset(data
, 0, sizeof(*data
));
61 e
= der_get_tag (p
, len
, &thisclass
, &thistype
, &thistag
, &l
);
65 e
= der_get_length(p
+ l
, len
- l
, &length
, &len_len
);
67 if (length
== ASN1_INDEFINITE
) {
68 if (len
< len_len
+ l
)
70 length
= len
- (len_len
+ l
);
72 if (len
< length
+ len_len
+ l
)
76 data
->data
= malloc(length
+ len_len
+ l
);
77 if (data
->data
== NULL
)
79 data
->length
= length
+ len_len
+ l
;
80 memcpy(data
->data
, p
, length
+ len_len
+ l
);
83 *size
= length
+ len_len
+ l
;
89 free_heim_any(heim_any
*data
)
91 der_free_octet_string(data
);
95 print_heim_any(const heim_any
*data
, int flags
)
98 char *s
= der_print_octet_string(data
, 0);
103 r
= rk_strasvis(&s2
, s
, VIS_CSTYLE
|VIS_TAB
|VIS_NL
, "\"");
107 r
= asprintf(&s
, "\"%s\"", s2
);
113 length_heim_any(const heim_any
*data
)
119 copy_heim_any(const heim_any
*from
, heim_any
*to
)
121 return der_copy_octet_string(from
, to
);
125 encode_HEIM_ANY(unsigned char *p
, size_t len
,
126 const heim_any
*data
, size_t *size
)
128 return encode_heim_any(p
, len
, data
, size
);
132 decode_HEIM_ANY(const unsigned char *p
, size_t len
,
133 heim_any
*data
, size_t *size
)
135 return decode_heim_any(p
, len
, data
, size
);
139 free_HEIM_ANY(heim_any
*data
)
141 der_free_octet_string(data
);
145 print_HEIM_ANY(const heim_any
*data
, int flags
)
148 char *s
= der_print_octet_string(data
, 0);
153 r
= rk_strasvis(&s2
, s
, VIS_CSTYLE
|VIS_TAB
|VIS_NL
, "\"");
157 r
= asprintf(&s
, "\"%s\"", s2
);
163 length_HEIM_ANY(const heim_any
*data
)
169 copy_HEIM_ANY(const heim_any
*from
, heim_any
*to
)
171 return der_copy_octet_string(from
, to
);
175 encode_heim_any_set(unsigned char *p
, size_t len
,
176 const heim_any_set
*data
, size_t *size
)
178 return der_put_octet_string (p
, len
, data
, size
);
182 decode_heim_any_set(const unsigned char *p
, size_t len
,
183 heim_any_set
*data
, size_t *size
)
185 return der_get_octet_string(p
, len
, data
, size
);
189 free_heim_any_set(heim_any_set
*data
)
191 der_free_octet_string(data
);
195 print_heim_any_set(const heim_any_set
*data
, int flags
)
198 char *s
= der_print_octet_string(data
, 0);
203 r
= rk_strasvis(&s2
, s
, VIS_CSTYLE
|VIS_TAB
|VIS_NL
, "\"");
207 r
= asprintf(&s
, "\"%s\"", s2
);
213 length_heim_any_set(const heim_any
*data
)
219 copy_heim_any_set(const heim_any_set
*from
, heim_any_set
*to
)
221 return der_copy_octet_string(from
, to
);
225 heim_any_cmp(const heim_any_set
*p
, const heim_any_set
*q
)
227 return der_heim_octet_string_cmp(p
, q
);
231 encode_HEIM_ANY_SET(unsigned char *p
, size_t len
,
232 const heim_any_set
*data
, size_t *size
)
234 return encode_heim_any_set(p
, len
, data
, size
);
238 decode_HEIM_ANY_SET(const unsigned char *p
, size_t len
,
239 heim_any_set
*data
, size_t *size
)
241 return decode_heim_any_set(p
, len
, data
, size
);
245 free_HEIM_ANY_SET(heim_any_set
*data
)
247 der_free_octet_string(data
);
251 print_HEIM_ANY_SET(const heim_any_set
*data
, int flags
)
254 char *s
= der_print_octet_string(data
, 0);
259 r
= rk_strasvis(&s2
, s
, VIS_CSTYLE
|VIS_TAB
|VIS_NL
, "\"");
263 r
= asprintf(&s
, "\"%s\"", s2
);
269 length_HEIM_ANY_SET(const heim_any
*data
)
275 copy_HEIM_ANY_SET(const heim_any_set
*from
, heim_any_set
*to
)
277 return der_copy_octet_string(from
, to
);
281 HEIM_ANY_cmp(const heim_any_set
*p
, const heim_any_set
*q
)
283 return der_heim_octet_string_cmp(p
, q
);