quiet warnings
[heimdal.git] / lib / asn1 / extra.c
bloba18797ec259433a013cfe58eda5573e4edf2185f
1 /*
2 * Copyright (c) 2003 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
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
10 * are met:
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
33 * SUCH DAMAGE.
36 #include "der_locl.h"
37 #include "heim_asn1.h"
39 RCSID("$Id$");
41 int
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);
48 int
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;
53 Der_class thisclass;
54 Der_type thistype;
55 unsigned int thistag;
56 int e;
58 memset(data, 0, sizeof(*data));
60 e = der_get_tag (p, len, &thisclass, &thistype, &thistag, &l);
61 if (e) return e;
62 if (l > len)
63 return ASN1_OVERFLOW;
64 e = der_get_length(p + l, len - l, &length, &len_len);
65 if (e) return e;
66 if (length == ASN1_INDEFINITE) {
67 if (len < len_len + l)
68 return ASN1_OVERFLOW;
69 length = len - (len_len + l);
70 } else {
71 if (len < length + len_len + l)
72 return ASN1_OVERFLOW;
75 data->data = malloc(length + len_len + l);
76 if (data->data == NULL)
77 return ENOMEM;
78 data->length = length + len_len + l;
79 memcpy(data->data, p, length + len_len + l);
81 if (size)
82 *size = length + len_len + l;
84 return 0;
87 void
88 free_heim_any(heim_any *data)
90 der_free_octet_string(data);
93 size_t
94 length_heim_any(const heim_any *data)
96 return data->length;
99 int
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);
119 void
120 free_heim_any_set(heim_any_set *data)
122 der_free_octet_string(data);
125 size_t
126 length_heim_any_set(const heim_any *data)
128 return data->length;
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);