nsseq.c revision 68651
11844Swollman/* nsseq.c */
250476Speter/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
31844Swollman * project 1999.
41638Srgrimes */
594940Sru/* ====================================================================
61638Srgrimes * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
742915Sjdp *
842915Sjdp * Redistribution and use in source and binary forms, with or without
942915Sjdp * modification, are permitted provided that the following conditions
1042915Sjdp * are met:
11139106Sru *
1242915Sjdp * 1. Redistributions of source code must retain the above copyright
1342915Sjdp *    notice, this list of conditions and the following disclaimer.
1442915Sjdp *
15129024Sdes * 2. Redistributions in binary form must reproduce the above copyright
16129024Sdes *    notice, this list of conditions and the following disclaimer in
1729141Speter *    the documentation and/or other materials provided with the
18129024Sdes *    distribution.
19129024Sdes *
20129024Sdes * 3. All advertising materials mentioning features or use of this
21125119Sru *    software must display the following acknowledgment:
22100332Sru *    "This product includes software developed by the OpenSSL Project
23100332Sru *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
2442915Sjdp *
2542915Sjdp * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2629141Speter *    endorse or promote products derived from this software without
27119607Sru *    prior written permission. For written permission, please contact
28117034Sgordon *    licensing@OpenSSL.org.
29119607Sru *
30117034Sgordon * 5. Products derived from this software may not be called "OpenSSL"
31162210Simp *    nor may "OpenSSL" appear in their names without prior written
32162210Simp *    permission of the OpenSSL Project.
33162293Sobrien *
34162210Simp * 6. Redistributions of any form whatsoever must retain the following
35162210Simp *    acknowledgment:
36206082Snetchild *    "This product includes software developed by the OpenSSL Project
37206082Snetchild *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38206082Snetchild *
39206082Snetchild * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40206082Snetchild * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
412827Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
422827Sjkh * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43179184Sjb * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44179184Sjb * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45179184Sjb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
462827Sjkh * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47179184Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
482827Sjkh * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
492827Sjkh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
501638Srgrimes * OF THE POSSIBILITY OF SUCH DAMAGE.
512827Sjkh * ====================================================================
521638Srgrimes *
5318529Sbde * This product includes cryptographic software written by Eric Young
5418529Sbde * (eay@cryptsoft.com).  This product includes software written by Tim
551638Srgrimes * Hudson (tjh@cryptsoft.com).
5642450Sjdp *
571638Srgrimes */
58117173Sru
591638Srgrimes#include <stdio.h>
6096512Sru#include <stdlib.h>
61211725Simp#include <openssl/asn1_mac.h>
6296512Sru#include <openssl/err.h>
6396512Sru#include <openssl/x509.h>
6496512Sru#include <openssl/objects.h>
6596512Sru
6696512Sru/* Netscape certificate sequence structure */
6796512Sru
68211437Srpauloint i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp)
69126890Strhodes{
70126890Strhodes	int v = 0;
71126890Strhodes	M_ASN1_I2D_vars(a);
72126890Strhodes	M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT);
73126890Strhodes	M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
741638Srgrimes					     V_ASN1_SEQUENCE,v);
75202807Ssepotvin
76210612Srpaulo	M_ASN1_I2D_seq_total();
77210636Srpaulo
78210636Srpaulo	M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT);
791638Srgrimes	M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
8042450Sjdp					     V_ASN1_SEQUENCE,v);
811844Swollman
82210612Srpaulo	M_ASN1_I2D_finish();
83210636Srpaulo}
84210636Srpaulo
851844SwollmanNETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void)
8636673Sdt{
87202807Ssepotvin	NETSCAPE_CERT_SEQUENCE *ret=NULL;
881844Swollman	ASN1_CTX c;
8942450Sjdp	M_ASN1_New_Malloc(ret, NETSCAPE_CERT_SEQUENCE);
901844Swollman	/* Note hardcoded object type */
911844Swollman	ret->type = OBJ_nid2obj(NID_netscape_cert_sequence);
921844Swollman	ret->certs = NULL;
93127027Strhodes	return (ret);
94210612Srpaulo	M_ASN1_New_Error(ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW);
95210636Srpaulo}
96210636Srpaulo
971844SwollmanNETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a,
9842450Sjdp	     unsigned char **pp, long length)
991844Swollman{
100210612Srpaulo	M_ASN1_D2I_vars(a,NETSCAPE_CERT_SEQUENCE *,
101210636Srpaulo					NETSCAPE_CERT_SEQUENCE_new);
102210636Srpaulo	M_ASN1_D2I_Init();
1031844Swollman	M_ASN1_D2I_start_sequence();
10436054Sbde	M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT);
10536054Sbde	M_ASN1_D2I_get_EXP_set_opt_type(X509,ret->certs,d2i_X509,X509_free,0,
106210612Srpaulo					V_ASN1_SEQUENCE);
107210636Srpaulo	M_ASN1_D2I_Finish(a, NETSCAPE_CERT_SEQUENCE_free,
108210636Srpaulo			  ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE);
10936054Sbde}
11042450Sjdp
11136054Sbdevoid NETSCAPE_CERT_SEQUENCE_free (NETSCAPE_CERT_SEQUENCE *a)
112210612Srpaulo{
113210636Srpaulo	if (a == NULL) return;
114210636Srpaulo	ASN1_OBJECT_free(a->type);
11536054Sbde	if(a->certs)
116117173Sru	    sk_X509_pop_free(a->certs, X509_free);
117117159Sru	OPENSSL_free (a);
118210612Srpaulo}
119210636Srpaulo