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"
42 encode_heim_any(unsigned char *p
, size_t len
,
43 const heim_any
*data
, size_t *size
)
45 return der_put_octet_string (p
, len
, data
, size
);
49 decode_heim_any(const unsigned char *p
, size_t len
,
50 heim_any
*data
, size_t *size
)
52 size_t len_len
, length
, l
;
58 memset(data
, 0, sizeof(*data
));
60 e
= der_get_tag (p
, len
, &thisclass
, &thistype
, &thistag
, &l
);
64 e
= der_get_length(p
+ l
, len
- l
, &length
, &len_len
);
66 if (length
== ASN1_INDEFINITE
) {
67 if (len
< len_len
+ l
)
69 length
= len
- (len_len
+ l
);
71 if (len
< length
+ len_len
+ l
)
75 data
->data
= malloc(length
+ len_len
+ l
);
76 if (data
->data
== NULL
)
78 data
->length
= length
+ len_len
+ l
;
79 memcpy(data
->data
, p
, length
+ len_len
+ l
);
82 *size
= length
+ len_len
+ l
;
88 free_heim_any(heim_any
*data
)
90 der_free_octet_string(data
);
94 length_heim_any(const heim_any
*data
)
100 copy_heim_any(const heim_any
*from
, heim_any
*to
)
102 return der_copy_octet_string(from
, to
);
106 encode_heim_any_set(unsigned char *p
, size_t len
,
107 const heim_any_set
*data
, size_t *size
)
109 return der_put_octet_string (p
, len
, data
, size
);
113 decode_heim_any_set(const unsigned char *p
, size_t len
,
114 heim_any_set
*data
, size_t *size
)
116 return der_get_octet_string(p
, len
, data
, size
);
120 free_heim_any_set(heim_any_set
*data
)
122 der_free_octet_string(data
);
126 length_heim_any_set(const heim_any
*data
)
132 copy_heim_any_set(const heim_any_set
*from
, heim_any_set
*to
)
134 return der_copy_octet_string(from
, to
);
138 heim_any_cmp(const heim_any_set
*p
, const heim_any_set
*q
)
140 return der_heim_octet_string_cmp(p
, q
);