xref: /onnv-gate/usr/src/common/openssl/crypto/asn1/tasn_new.c (revision 2139:6243c3338933)
10Sstevel@tonic-gate /* tasn_new.c */
20Sstevel@tonic-gate /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
30Sstevel@tonic-gate  * project 2000.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate /* ====================================================================
6*2139Sjp161948  * Copyright (c) 2000-2004 The OpenSSL Project.  All rights reserved.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
90Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
100Sstevel@tonic-gate  * are met:
110Sstevel@tonic-gate  *
120Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
130Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
140Sstevel@tonic-gate  *
150Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
160Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in
170Sstevel@tonic-gate  *    the documentation and/or other materials provided with the
180Sstevel@tonic-gate  *    distribution.
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this
210Sstevel@tonic-gate  *    software must display the following acknowledgment:
220Sstevel@tonic-gate  *    "This product includes software developed by the OpenSSL Project
230Sstevel@tonic-gate  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
260Sstevel@tonic-gate  *    endorse or promote products derived from this software without
270Sstevel@tonic-gate  *    prior written permission. For written permission, please contact
280Sstevel@tonic-gate  *    licensing@OpenSSL.org.
290Sstevel@tonic-gate  *
300Sstevel@tonic-gate  * 5. Products derived from this software may not be called "OpenSSL"
310Sstevel@tonic-gate  *    nor may "OpenSSL" appear in their names without prior written
320Sstevel@tonic-gate  *    permission of the OpenSSL Project.
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * 6. Redistributions of any form whatsoever must retain the following
350Sstevel@tonic-gate  *    acknowledgment:
360Sstevel@tonic-gate  *    "This product includes software developed by the OpenSSL Project
370Sstevel@tonic-gate  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
380Sstevel@tonic-gate  *
390Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
400Sstevel@tonic-gate  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
410Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
420Sstevel@tonic-gate  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
430Sstevel@tonic-gate  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
440Sstevel@tonic-gate  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
450Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
460Sstevel@tonic-gate  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
470Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
480Sstevel@tonic-gate  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
490Sstevel@tonic-gate  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
500Sstevel@tonic-gate  * OF THE POSSIBILITY OF SUCH DAMAGE.
510Sstevel@tonic-gate  * ====================================================================
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  * This product includes cryptographic software written by Eric Young
540Sstevel@tonic-gate  * (eay@cryptsoft.com).  This product includes software written by Tim
550Sstevel@tonic-gate  * Hudson (tjh@cryptsoft.com).
560Sstevel@tonic-gate  *
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 
600Sstevel@tonic-gate #include <stddef.h>
610Sstevel@tonic-gate #include <openssl/asn1.h>
620Sstevel@tonic-gate #include <openssl/objects.h>
630Sstevel@tonic-gate #include <openssl/err.h>
640Sstevel@tonic-gate #include <openssl/asn1t.h>
650Sstevel@tonic-gate #include <string.h>
660Sstevel@tonic-gate 
67*2139Sjp161948 static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
68*2139Sjp161948 								int combine);
690Sstevel@tonic-gate static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
700Sstevel@tonic-gate static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
710Sstevel@tonic-gate void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
720Sstevel@tonic-gate 
ASN1_item_new(const ASN1_ITEM * it)730Sstevel@tonic-gate ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
74*2139Sjp161948 	{
750Sstevel@tonic-gate 	ASN1_VALUE *ret = NULL;
76*2139Sjp161948 	if (ASN1_item_ex_new(&ret, it) > 0)
77*2139Sjp161948 		return ret;
780Sstevel@tonic-gate 	return NULL;
79*2139Sjp161948 	}
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /* Allocate an ASN1 structure */
820Sstevel@tonic-gate 
ASN1_item_ex_new(ASN1_VALUE ** pval,const ASN1_ITEM * it)830Sstevel@tonic-gate int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
84*2139Sjp161948 	{
850Sstevel@tonic-gate 	return asn1_item_ex_combine_new(pval, it, 0);
86*2139Sjp161948 	}
870Sstevel@tonic-gate 
asn1_item_ex_combine_new(ASN1_VALUE ** pval,const ASN1_ITEM * it,int combine)88*2139Sjp161948 static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
89*2139Sjp161948 								int combine)
90*2139Sjp161948 	{
910Sstevel@tonic-gate 	const ASN1_TEMPLATE *tt = NULL;
920Sstevel@tonic-gate 	const ASN1_COMPAT_FUNCS *cf;
930Sstevel@tonic-gate 	const ASN1_EXTERN_FUNCS *ef;
940Sstevel@tonic-gate 	const ASN1_AUX *aux = it->funcs;
950Sstevel@tonic-gate 	ASN1_aux_cb *asn1_cb;
960Sstevel@tonic-gate 	ASN1_VALUE **pseqval;
970Sstevel@tonic-gate 	int i;
98*2139Sjp161948 	if (aux && aux->asn1_cb)
99*2139Sjp161948 		asn1_cb = aux->asn1_cb;
100*2139Sjp161948 	else
101*2139Sjp161948 		asn1_cb = 0;
1020Sstevel@tonic-gate 
103*2139Sjp161948 	if (!combine) *pval = NULL;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate #ifdef CRYPTO_MDEBUG
106*2139Sjp161948 	if (it->sname)
107*2139Sjp161948 		CRYPTO_push_info(it->sname);
1080Sstevel@tonic-gate #endif
1090Sstevel@tonic-gate 
110*2139Sjp161948 	switch(it->itype)
111*2139Sjp161948 		{
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 		case ASN1_ITYPE_EXTERN:
1140Sstevel@tonic-gate 		ef = it->funcs;
115*2139Sjp161948 		if (ef && ef->asn1_ex_new)
116*2139Sjp161948 			{
117*2139Sjp161948 			if (!ef->asn1_ex_new(pval, it))
118*2139Sjp161948 				goto memerr;
119*2139Sjp161948 			}
120*2139Sjp161948 		break;
121*2139Sjp161948 
122*2139Sjp161948 		case ASN1_ITYPE_COMPAT:
123*2139Sjp161948 		cf = it->funcs;
124*2139Sjp161948 		if (cf && cf->asn1_new) {
125*2139Sjp161948 			*pval = cf->asn1_new();
126*2139Sjp161948 			if (!*pval)
1270Sstevel@tonic-gate 				goto memerr;
1280Sstevel@tonic-gate 		}
1290Sstevel@tonic-gate 		break;
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 		case ASN1_ITYPE_PRIMITIVE:
132*2139Sjp161948 		if (it->templates)
133*2139Sjp161948 			{
134*2139Sjp161948 			if (!ASN1_template_new(pval, it->templates))
1350Sstevel@tonic-gate 				goto memerr;
136*2139Sjp161948 			}
137*2139Sjp161948 		else if (!ASN1_primitive_new(pval, it))
1380Sstevel@tonic-gate 				goto memerr;
1390Sstevel@tonic-gate 		break;
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 		case ASN1_ITYPE_MSTRING:
142*2139Sjp161948 		if (!ASN1_primitive_new(pval, it))
1430Sstevel@tonic-gate 				goto memerr;
1440Sstevel@tonic-gate 		break;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 		case ASN1_ITYPE_CHOICE:
147*2139Sjp161948 		if (asn1_cb)
148*2139Sjp161948 			{
1490Sstevel@tonic-gate 			i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
150*2139Sjp161948 			if (!i)
151*2139Sjp161948 				goto auxerr;
152*2139Sjp161948 			if (i==2)
153*2139Sjp161948 				{
1540Sstevel@tonic-gate #ifdef CRYPTO_MDEBUG
155*2139Sjp161948 				if (it->sname)
156*2139Sjp161948 					CRYPTO_pop_info();
1570Sstevel@tonic-gate #endif
1580Sstevel@tonic-gate 				return 1;
159*2139Sjp161948 				}
1600Sstevel@tonic-gate 			}
161*2139Sjp161948 		if (!combine)
162*2139Sjp161948 			{
1630Sstevel@tonic-gate 			*pval = OPENSSL_malloc(it->size);
164*2139Sjp161948 			if (!*pval)
165*2139Sjp161948 				goto memerr;
1660Sstevel@tonic-gate 			memset(*pval, 0, it->size);
167*2139Sjp161948 			}
1680Sstevel@tonic-gate 		asn1_set_choice_selector(pval, -1, it);
169*2139Sjp161948 		if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
1700Sstevel@tonic-gate 				goto auxerr;
1710Sstevel@tonic-gate 		break;
1720Sstevel@tonic-gate 
173*2139Sjp161948 		case ASN1_ITYPE_NDEF_SEQUENCE:
1740Sstevel@tonic-gate 		case ASN1_ITYPE_SEQUENCE:
175*2139Sjp161948 		if (asn1_cb)
176*2139Sjp161948 			{
1770Sstevel@tonic-gate 			i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
178*2139Sjp161948 			if (!i)
179*2139Sjp161948 				goto auxerr;
180*2139Sjp161948 			if (i==2)
181*2139Sjp161948 				{
1820Sstevel@tonic-gate #ifdef CRYPTO_MDEBUG
183*2139Sjp161948 				if (it->sname)
184*2139Sjp161948 					CRYPTO_pop_info();
1850Sstevel@tonic-gate #endif
1860Sstevel@tonic-gate 				return 1;
187*2139Sjp161948 				}
1880Sstevel@tonic-gate 			}
189*2139Sjp161948 		if (!combine)
190*2139Sjp161948 			{
1910Sstevel@tonic-gate 			*pval = OPENSSL_malloc(it->size);
192*2139Sjp161948 			if (!*pval)
193*2139Sjp161948 				goto memerr;
1940Sstevel@tonic-gate 			memset(*pval, 0, it->size);
1950Sstevel@tonic-gate 			asn1_do_lock(pval, 0, it);
1960Sstevel@tonic-gate 			asn1_enc_init(pval, it);
197*2139Sjp161948 			}
198*2139Sjp161948 		for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
199*2139Sjp161948 			{
2000Sstevel@tonic-gate 			pseqval = asn1_get_field_ptr(pval, tt);
201*2139Sjp161948 			if (!ASN1_template_new(pseqval, tt))
202*2139Sjp161948 				goto memerr;
203*2139Sjp161948 			}
204*2139Sjp161948 		if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
2050Sstevel@tonic-gate 				goto auxerr;
2060Sstevel@tonic-gate 		break;
2070Sstevel@tonic-gate 	}
2080Sstevel@tonic-gate #ifdef CRYPTO_MDEBUG
209*2139Sjp161948 	if (it->sname) CRYPTO_pop_info();
2100Sstevel@tonic-gate #endif
2110Sstevel@tonic-gate 	return 1;
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	memerr:
214*2139Sjp161948 	ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE);
2150Sstevel@tonic-gate #ifdef CRYPTO_MDEBUG
216*2139Sjp161948 	if (it->sname) CRYPTO_pop_info();
2170Sstevel@tonic-gate #endif
2180Sstevel@tonic-gate 	return 0;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	auxerr:
221*2139Sjp161948 	ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR);
2220Sstevel@tonic-gate 	ASN1_item_ex_free(pval, it);
2230Sstevel@tonic-gate #ifdef CRYPTO_MDEBUG
224*2139Sjp161948 	if (it->sname) CRYPTO_pop_info();
2250Sstevel@tonic-gate #endif
2260Sstevel@tonic-gate 	return 0;
2270Sstevel@tonic-gate 
228*2139Sjp161948 	}
2290Sstevel@tonic-gate 
asn1_item_clear(ASN1_VALUE ** pval,const ASN1_ITEM * it)2300Sstevel@tonic-gate static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
231*2139Sjp161948 	{
2320Sstevel@tonic-gate 	const ASN1_EXTERN_FUNCS *ef;
2330Sstevel@tonic-gate 
234*2139Sjp161948 	switch(it->itype)
235*2139Sjp161948 		{
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 		case ASN1_ITYPE_EXTERN:
2380Sstevel@tonic-gate 		ef = it->funcs;
239*2139Sjp161948 		if (ef && ef->asn1_ex_clear)
2400Sstevel@tonic-gate 			ef->asn1_ex_clear(pval, it);
2410Sstevel@tonic-gate 		else *pval = NULL;
2420Sstevel@tonic-gate 		break;
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 		case ASN1_ITYPE_PRIMITIVE:
246*2139Sjp161948 		if (it->templates)
2470Sstevel@tonic-gate 			asn1_template_clear(pval, it->templates);
2480Sstevel@tonic-gate 		else
2490Sstevel@tonic-gate 			asn1_primitive_clear(pval, it);
2500Sstevel@tonic-gate 		break;
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 		case ASN1_ITYPE_MSTRING:
2530Sstevel@tonic-gate 		asn1_primitive_clear(pval, it);
2540Sstevel@tonic-gate 		break;
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate 		case ASN1_ITYPE_COMPAT:
2570Sstevel@tonic-gate 		case ASN1_ITYPE_CHOICE:
2580Sstevel@tonic-gate 		case ASN1_ITYPE_SEQUENCE:
259*2139Sjp161948 		case ASN1_ITYPE_NDEF_SEQUENCE:
2600Sstevel@tonic-gate 		*pval = NULL;
2610Sstevel@tonic-gate 		break;
262*2139Sjp161948 		}
2630Sstevel@tonic-gate 	}
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 
ASN1_template_new(ASN1_VALUE ** pval,const ASN1_TEMPLATE * tt)2660Sstevel@tonic-gate int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
267*2139Sjp161948 	{
2680Sstevel@tonic-gate 	const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
2690Sstevel@tonic-gate 	int ret;
270*2139Sjp161948 	if (tt->flags & ASN1_TFLG_OPTIONAL)
271*2139Sjp161948 		{
2720Sstevel@tonic-gate 		asn1_template_clear(pval, tt);
2730Sstevel@tonic-gate 		return 1;
274*2139Sjp161948 		}
2750Sstevel@tonic-gate 	/* If ANY DEFINED BY nothing to do */
2760Sstevel@tonic-gate 
277*2139Sjp161948 	if (tt->flags & ASN1_TFLG_ADB_MASK)
278*2139Sjp161948 		{
2790Sstevel@tonic-gate 		*pval = NULL;
2800Sstevel@tonic-gate 		return 1;
281*2139Sjp161948 		}
2820Sstevel@tonic-gate #ifdef CRYPTO_MDEBUG
283*2139Sjp161948 	if (tt->field_name)
284*2139Sjp161948 		CRYPTO_push_info(tt->field_name);
2850Sstevel@tonic-gate #endif
2860Sstevel@tonic-gate 	/* If SET OF or SEQUENCE OF, its a STACK */
287*2139Sjp161948 	if (tt->flags & ASN1_TFLG_SK_MASK)
288*2139Sjp161948 		{
2890Sstevel@tonic-gate 		STACK_OF(ASN1_VALUE) *skval;
2900Sstevel@tonic-gate 		skval = sk_ASN1_VALUE_new_null();
291*2139Sjp161948 		if (!skval)
292*2139Sjp161948 			{
2930Sstevel@tonic-gate 			ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
2940Sstevel@tonic-gate 			ret = 0;
2950Sstevel@tonic-gate 			goto done;
296*2139Sjp161948 			}
2970Sstevel@tonic-gate 		*pval = (ASN1_VALUE *)skval;
2980Sstevel@tonic-gate 		ret = 1;
2990Sstevel@tonic-gate 		goto done;
300*2139Sjp161948 		}
3010Sstevel@tonic-gate 	/* Otherwise pass it back to the item routine */
3020Sstevel@tonic-gate 	ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
3030Sstevel@tonic-gate 	done:
3040Sstevel@tonic-gate #ifdef CRYPTO_MDEBUG
305*2139Sjp161948 	if (it->sname)
306*2139Sjp161948 		CRYPTO_pop_info();
3070Sstevel@tonic-gate #endif
3080Sstevel@tonic-gate 	return ret;
309*2139Sjp161948 	}
3100Sstevel@tonic-gate 
asn1_template_clear(ASN1_VALUE ** pval,const ASN1_TEMPLATE * tt)3110Sstevel@tonic-gate static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
312*2139Sjp161948 	{
3130Sstevel@tonic-gate 	/* If ADB or STACK just NULL the field */
314*2139Sjp161948 	if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
3150Sstevel@tonic-gate 		*pval = NULL;
3160Sstevel@tonic-gate 	else
3170Sstevel@tonic-gate 		asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
318*2139Sjp161948 	}
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 
321*2139Sjp161948 /* NB: could probably combine most of the real XXX_new() behaviour and junk
322*2139Sjp161948  * all the old functions.
3230Sstevel@tonic-gate  */
3240Sstevel@tonic-gate 
ASN1_primitive_new(ASN1_VALUE ** pval,const ASN1_ITEM * it)3250Sstevel@tonic-gate int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
326*2139Sjp161948 	{
3270Sstevel@tonic-gate 	ASN1_TYPE *typ;
3280Sstevel@tonic-gate 	int utype;
329*2139Sjp161948 
330*2139Sjp161948 	if (it && it->funcs)
331*2139Sjp161948 		{
332*2139Sjp161948 		const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
333*2139Sjp161948 		if (pf->prim_new)
334*2139Sjp161948 			return pf->prim_new(pval, it);
335*2139Sjp161948 		}
336*2139Sjp161948 
337*2139Sjp161948 	if (!it || (it->itype == ASN1_ITYPE_MSTRING))
338*2139Sjp161948 		utype = -1;
339*2139Sjp161948 	else
340*2139Sjp161948 		utype = it->utype;
341*2139Sjp161948 	switch(utype)
342*2139Sjp161948 		{
3430Sstevel@tonic-gate 		case V_ASN1_OBJECT:
3440Sstevel@tonic-gate 		*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
3450Sstevel@tonic-gate 		return 1;
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 		case V_ASN1_BOOLEAN:
3480Sstevel@tonic-gate 		if (it)
3490Sstevel@tonic-gate 			*(ASN1_BOOLEAN *)pval = it->size;
3500Sstevel@tonic-gate 		else
3510Sstevel@tonic-gate 			*(ASN1_BOOLEAN *)pval = -1;
3520Sstevel@tonic-gate 		return 1;
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate 		case V_ASN1_NULL:
3550Sstevel@tonic-gate 		*pval = (ASN1_VALUE *)1;
3560Sstevel@tonic-gate 		return 1;
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 		case V_ASN1_ANY:
3590Sstevel@tonic-gate 		typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
360*2139Sjp161948 		if (!typ)
361*2139Sjp161948 			return 0;
3620Sstevel@tonic-gate 		typ->value.ptr = NULL;
3630Sstevel@tonic-gate 		typ->type = -1;
3640Sstevel@tonic-gate 		*pval = (ASN1_VALUE *)typ;
3650Sstevel@tonic-gate 		break;
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate 		default:
3680Sstevel@tonic-gate 		*pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
3690Sstevel@tonic-gate 		break;
370*2139Sjp161948 		}
371*2139Sjp161948 	if (*pval)
372*2139Sjp161948 		return 1;
373*2139Sjp161948 	return 0;
3740Sstevel@tonic-gate 	}
3750Sstevel@tonic-gate 
asn1_primitive_clear(ASN1_VALUE ** pval,const ASN1_ITEM * it)3760Sstevel@tonic-gate void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
377*2139Sjp161948 	{
3780Sstevel@tonic-gate 	int utype;
379*2139Sjp161948 	if (it && it->funcs)
380*2139Sjp161948 		{
381*2139Sjp161948 		const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
382*2139Sjp161948 		if (pf->prim_clear)
3830Sstevel@tonic-gate 			pf->prim_clear(pval, it);
3840Sstevel@tonic-gate 		else
3850Sstevel@tonic-gate 			*pval = NULL;
3860Sstevel@tonic-gate 		return;
387*2139Sjp161948 		}
388*2139Sjp161948 	if (!it || (it->itype == ASN1_ITYPE_MSTRING))
389*2139Sjp161948 		utype = -1;
390*2139Sjp161948 	else
391*2139Sjp161948 		utype = it->utype;
392*2139Sjp161948 	if (utype == V_ASN1_BOOLEAN)
3930Sstevel@tonic-gate 		*(ASN1_BOOLEAN *)pval = it->size;
3940Sstevel@tonic-gate 	else *pval = NULL;
395*2139Sjp161948 	}
396