a_type.c revision 194206
1492SN/A/* crypto/asn1/a_type.c */ 21345Sihse/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3492SN/A * All rights reserved. 4492SN/A * 5492SN/A * This package is an SSL implementation written 6492SN/A * by Eric Young (eay@cryptsoft.com). 7492SN/A * The implementation was written so as to conform with Netscapes SSL. 8492SN/A * 9492SN/A * This library is free for commercial and non-commercial use as long as 10492SN/A * the following conditions are aheared to. The following conditions 11492SN/A * apply to all code found in this distribution, be it the RC4, RSA, 12492SN/A * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13492SN/A * included with this distribution is covered by the same copyright terms 14492SN/A * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15492SN/A * 16492SN/A * Copyright remains Eric Young's, and as such any Copyright notices in 17492SN/A * the code are not to be removed. 18492SN/A * If this package is used in a product, Eric Young should be given attribution 19492SN/A * as the author of the parts of the library used. 20492SN/A * This can be in the form of a textual message at program startup or 21492SN/A * in documentation (online or textual) provided with the package. 22492SN/A * 23492SN/A * Redistribution and use in source and binary forms, with or without 24492SN/A * modification, are permitted provided that the following conditions 25492SN/A * are met: 261120Schegar * 1. Redistributions of source code must retain the copyright 271120Schegar * notice, this list of conditions and the following disclaimer. 281120Schegar * 2. Redistributions in binary form must reproduce the above copyright 291120Schegar * notice, this list of conditions and the following disclaimer in the 301120Schegar * documentation and/or other materials provided with the distribution. 311120Schegar * 3. All advertising materials mentioning features or use of this software 32492SN/A * must display the following acknowledgement: 33492SN/A * "This product includes cryptographic software written by 34492SN/A * Eric Young (eay@cryptsoft.com)" 35492SN/A * The word 'cryptographic' can be left out if the rouines from the library 361120Schegar * being used are not cryptographic related :-). 371120Schegar * 4. If you include any Windows specific code (or a derivative thereof) from 38837SN/A * the apps directory (application code) you must include an acknowledgement: 39910Sihse * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 401131Serikj * 41492SN/A * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 421120Schegar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 431236Sihse * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 441120Schegar * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 451120Schegar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 461120Schegar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47968Sihse * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48968Sihse * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49492SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 501120Schegar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 511120Schegar * SUCH DAMAGE. 521120Schegar * 531120Schegar * The licence and distribution terms for any publically available version or 541120Schegar * derivative of this code cannot be changed. i.e. this code cannot simply be 551120Schegar * copied and put under another distribution licence 561120Schegar * [including the GNU Public Licence.] 571120Schegar */ 581120Schegar 591120Schegar#include <stdio.h> 601120Schegar#include "cryptlib.h" 611120Schegar#include <openssl/asn1t.h> 621120Schegar#include <openssl/objects.h> 631120Schegar 641223Schegarint ASN1_TYPE_get(ASN1_TYPE *a) 651223Schegar { 661223Schegar if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) 671120Schegar return(a->type); 681120Schegar else 691120Schegar return(0); 701120Schegar } 711223Schegar 721120Schegarvoid ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) 731120Schegar { 741120Schegar if (a->value.ptr != NULL) 751120Schegar { 761223Schegar ASN1_TYPE **tmp_a = &a; 771120Schegar ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); 781120Schegar } 791223Schegar a->type=type; 801223Schegar a->value.ptr=value; 811120Schegar } 821120Schegar 831120Schegarint ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) 841120Schegar { 851120Schegar if (!value || (type == V_ASN1_BOOLEAN)) 861120Schegar { 87492SN/A void *p = (void *)value; 881120Schegar ASN1_TYPE_set(a, type, p); 891120Schegar } 901120Schegar else if (type == V_ASN1_OBJECT) 911223Schegar { 92492SN/A ASN1_OBJECT *odup; 931120Schegar odup = OBJ_dup(value); 941120Schegar if (!odup) 951223Schegar return 0; 961223Schegar ASN1_TYPE_set(a, type, odup); 971223Schegar } 981223Schegar else 991223Schegar { 1001223Schegar ASN1_STRING *sdup; 101492SN/A sdup = ASN1_STRING_dup((ASN1_STRING *)value); 1021223Schegar if (!sdup) 1031223Schegar return 0; 1041223Schegar ASN1_TYPE_set(a, type, sdup); 105557SN/A } 1061120Schegar return 1; 1071120Schegar } 1081120Schegar 1091120SchegarIMPLEMENT_STACK_OF(ASN1_TYPE) 1101223SchegarIMPLEMENT_ASN1_SET_OF(ASN1_TYPE) 1111223Schegar