x_algor.c revision 194206
1141240Snjl/* x_algor.c */ 2141240Snjl/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3141240Snjl * project 2000. 4141240Snjl */ 5141240Snjl/* ==================================================================== 6141240Snjl * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 7141240Snjl * 8141240Snjl * Redistribution and use in source and binary forms, with or without 9141240Snjl * modification, are permitted provided that the following conditions 10141240Snjl * are met: 11141240Snjl * 12141240Snjl * 1. Redistributions of source code must retain the above copyright 13141240Snjl * notice, this list of conditions and the following disclaimer. 14141240Snjl * 15141240Snjl * 2. Redistributions in binary form must reproduce the above copyright 16141240Snjl * notice, this list of conditions and the following disclaimer in 17141240Snjl * the documentation and/or other materials provided with the 18141240Snjl * distribution. 19141240Snjl * 20141240Snjl * 3. All advertising materials mentioning features or use of this 21141240Snjl * software must display the following acknowledgment: 22141240Snjl * "This product includes software developed by the OpenSSL Project 23141240Snjl * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 24141240Snjl * 25141240Snjl * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26141240Snjl * endorse or promote products derived from this software without 27141240Snjl * prior written permission. For written permission, please contact 28141240Snjl * licensing@OpenSSL.org. 29141240Snjl * 30141240Snjl * 5. Products derived from this software may not be called "OpenSSL" 31141240Snjl * nor may "OpenSSL" appear in their names without prior written 32141240Snjl * permission of the OpenSSL Project. 33141240Snjl * 34141240Snjl * 6. Redistributions of any form whatsoever must retain the following 35141240Snjl * acknowledgment: 36141240Snjl * "This product includes software developed by the OpenSSL Project 37141240Snjl * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 38141240Snjl * 39141240Snjl * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40141240Snjl * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41141240Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42141240Snjl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43141814Snjl * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44141240Snjl * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45141240Snjl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46141240Snjl * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47141240Snjl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48141240Snjl * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49141240Snjl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50141240Snjl * OF THE POSSIBILITY OF SUCH DAMAGE. 51141240Snjl * ==================================================================== 52141240Snjl * 53141240Snjl * This product includes cryptographic software written by Eric Young 54142395Snjl * (eay@cryptsoft.com). This product includes software written by Tim 55141240Snjl * Hudson (tjh@cryptsoft.com). 56142395Snjl * 57141240Snjl */ 58141240Snjl 59141240Snjl#include <stddef.h> 60141923Snjl#include <openssl/x509.h> 61141923Snjl#include <openssl/asn1.h> 62141923Snjl#include <openssl/asn1t.h> 63141923Snjl 64141413SnjlASN1_SEQUENCE(X509_ALGOR) = { 65141945Snjl ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT), 66141240Snjl ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY) 67141240Snjl} ASN1_SEQUENCE_END(X509_ALGOR) 68141240Snjl 69141240SnjlASN1_ITEM_TEMPLATE(X509_ALGORS) = 70141240Snjl ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR) 71141240SnjlASN1_ITEM_TEMPLATE_END(X509_ALGORS) 72141240Snjl 73141240SnjlIMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR) 74141240SnjlIMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_ALGORS, X509_ALGORS, X509_ALGORS) 75141240SnjlIMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR) 76141240Snjl 77141240SnjlIMPLEMENT_STACK_OF(X509_ALGOR) 78141240SnjlIMPLEMENT_ASN1_SET_OF(X509_ALGOR) 79141240Snjl 80141240Snjlint X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) 81141240Snjl { 82141240Snjl if (!alg) 83141240Snjl return 0; 84141240Snjl if (ptype != V_ASN1_UNDEF) 85141240Snjl { 86141413Snjl if (alg->parameter == NULL) 87141240Snjl alg->parameter = ASN1_TYPE_new(); 88141413Snjl if (alg->parameter == NULL) 89141413Snjl return 0; 90141413Snjl } 91141413Snjl if (alg) 92141240Snjl { 93141240Snjl if (alg->algorithm) 94142114Snjl ASN1_OBJECT_free(alg->algorithm); 95141240Snjl alg->algorithm = aobj; 96141240Snjl } 97141240Snjl if (ptype == 0) 98141240Snjl return 1; 99141240Snjl if (ptype == V_ASN1_UNDEF) 100141240Snjl { 101141240Snjl if (alg->parameter) 102141240Snjl { 103141240Snjl ASN1_TYPE_free(alg->parameter); 104141240Snjl alg->parameter = NULL; 105141240Snjl } 106141240Snjl } 107141240Snjl else 108141240Snjl ASN1_TYPE_set(alg->parameter, ptype, pval); 109141240Snjl return 1; 110141240Snjl } 111141240Snjl 112142590Snjlvoid X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, 113141240Snjl X509_ALGOR *algor) 114142590Snjl { 115142590Snjl if (paobj) 116142590Snjl *paobj = algor->algorithm; 117142590Snjl if (pptype) 118142590Snjl { 119142590Snjl if (algor->parameter == NULL) 120141240Snjl { 121141240Snjl *pptype = V_ASN1_UNDEF; 122141240Snjl return; 123141240Snjl } 124141240Snjl else 125141240Snjl *pptype = algor->parameter->type; 126141240Snjl if (ppval) 127141240Snjl *ppval = algor->parameter->value.ptr; 128141240Snjl } 129141240Snjl } 130141240Snjl 131141240Snjl