nsseq.c revision 55714
168349Sobrien/* nsseq.c */
268349Sobrien/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3328875Seadler * project 1999.
468349Sobrien */
568349Sobrien/* ====================================================================
668349Sobrien * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
768349Sobrien *
8226048Sobrien * Redistribution and use in source and binary forms, with or without
9328875Seadler * modification, are permitted provided that the following conditions
10226048Sobrien * are met:
11186690Sobrien *
12226048Sobrien * 1. Redistributions of source code must retain the above copyright
13186690Sobrien *    notice, this list of conditions and the following disclaimer.
14226048Sobrien *
15186690Sobrien * 2. Redistributions in binary form must reproduce the above copyright
16226048Sobrien *    notice, this list of conditions and the following disclaimer in
17186690Sobrien *    the documentation and/or other materials provided with the
1868349Sobrien *    distribution.
19159764Sobrien *
20159764Sobrien * 3. All advertising materials mentioning features or use of this
21159764Sobrien *    software must display the following acknowledgment:
22226048Sobrien *    "This product includes software developed by the OpenSSL Project
23226048Sobrien *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24226048Sobrien *
25226048Sobrien * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26169962Sobrien *    endorse or promote products derived from this software without
27300899Sdelphij *    prior written permission. For written permission, please contact
28300899Sdelphij *    licensing@OpenSSL.org.
29300899Sdelphij *
30300899Sdelphij * 5. Products derived from this software may not be called "OpenSSL"
31300899Sdelphij *    nor may "OpenSSL" appear in their names without prior written
3268349Sobrien *    permission of the OpenSSL Project.
3368349Sobrien *
3468349Sobrien * 6. Redistributions of any form whatsoever must retain the following
3568349Sobrien *    acknowledgment:
3668349Sobrien *    "This product includes software developed by the OpenSSL Project
3768349Sobrien *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
3868349Sobrien *
3968349Sobrien * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
4068349Sobrien * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4168349Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4268349Sobrien * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
4368349Sobrien * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44226048Sobrien * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4568349Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46226048Sobrien * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4768349Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48234250Sobrien * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49226048Sobrien * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50226048Sobrien * OF THE POSSIBILITY OF SUCH DAMAGE.
51267843Sdelphij * ====================================================================
52226048Sobrien *
53226048Sobrien * This product includes cryptographic software written by Eric Young
54226048Sobrien * (eay@cryptsoft.com).  This product includes software written by Tim
55226048Sobrien * Hudson (tjh@cryptsoft.com).
56159764Sobrien *
57226048Sobrien */
58226048Sobrien
59159764Sobrien#include <stdio.h>
60226048Sobrien#include <stdlib.h>
61226048Sobrien#include <openssl/asn1_mac.h>
62186690Sobrien#include <openssl/err.h>
63267843Sdelphij#include <openssl/x509.h>
64226048Sobrien#include <openssl/objects.h>
65226048Sobrien
66226048Sobrien/* Netscape certificate sequence structure */
67226048Sobrien
68226048Sobrienint i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp)
69226048Sobrien{
70226048Sobrien	int v = 0;
71226048Sobrien	M_ASN1_I2D_vars(a);
72226048Sobrien	M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT);
73226048Sobrien	M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
74226048Sobrien					     V_ASN1_SEQUENCE,v);
75186690Sobrien
76186690Sobrien	M_ASN1_I2D_seq_total();
77186690Sobrien
78226048Sobrien	M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT);
79226048Sobrien	M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
80226048Sobrien					     V_ASN1_SEQUENCE,v);
81226048Sobrien
82226048Sobrien	M_ASN1_I2D_finish();
83186690Sobrien}
84186690Sobrien
85226048SobrienNETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void)
86186690Sobrien{
87226048Sobrien	NETSCAPE_CERT_SEQUENCE *ret=NULL;
88226048Sobrien	ASN1_CTX c;
89226048Sobrien	M_ASN1_New_Malloc(ret, NETSCAPE_CERT_SEQUENCE);
90226048Sobrien	/* Note hardcoded object type */
91267843Sdelphij	ret->type = OBJ_nid2obj(NID_netscape_cert_sequence);
92226048Sobrien	ret->certs = NULL;
93226048Sobrien	return (ret);
94226048Sobrien	M_ASN1_New_Error(ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW);
95186690Sobrien}
96186690Sobrien
97226048SobrienNETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a,
98226048Sobrien	     unsigned char **pp, long length)
99226048Sobrien{
100226048Sobrien	M_ASN1_D2I_vars(a,NETSCAPE_CERT_SEQUENCE *,
101226048Sobrien					NETSCAPE_CERT_SEQUENCE_new);
102226048Sobrien	M_ASN1_D2I_Init();
103226048Sobrien	M_ASN1_D2I_start_sequence();
104226048Sobrien	M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT);
105186690Sobrien	M_ASN1_D2I_get_EXP_set_opt_type(X509,ret->certs,d2i_X509,X509_free,0,
106226048Sobrien					V_ASN1_SEQUENCE);
107226048Sobrien	M_ASN1_D2I_Finish(a, NETSCAPE_CERT_SEQUENCE_free,
108226048Sobrien			  ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE);
109226048Sobrien}
110159764Sobrien
111226048Sobrienvoid NETSCAPE_CERT_SEQUENCE_free (NETSCAPE_CERT_SEQUENCE *a)
112226048Sobrien{
113226048Sobrien	if (a == NULL) return;
114226048Sobrien	ASN1_OBJECT_free(a->type);
115226048Sobrien	if(a->certs)
116226048Sobrien	    sk_X509_pop_free(a->certs, X509_free);
117226048Sobrien	Free (a);
118226048Sobrien}
119226048Sobrien