1181643Skmacy/*	$NetBSD: crl.c,v 1.2 2021/08/14 16:14:51 christos Exp $	*/
2181643Skmacy
3181643Skmacy/*
4181643Skmacy *    crl.c
5181643Skmacy *    "CertificateRevokationList" ASN.1 module encode/decode/extracting/matching/free C src.
6181643Skmacy *    This file was generated by modified eSMACC compiler Fri Jan 21 11:25:24 2005
7181643Skmacy *    The generated files are supposed to be compiled as a module for OpenLDAP Software
8181643Skmacy */
9181643Skmacy
10181643Skmacy#include "crl.h"
11181643Skmacy
12181643SkmacyBDecComponentCertificateListTop( void* mem_op, GenBuf* b, void *v, AsnLen* bytesDecoded,int mode) {
13181643Skmacy	AsnTag tag;
14181643Skmacy	AsnLen elmtLen;
15181643Skmacy
16181643Skmacy	tag = BDecTag ( b, bytesDecoded );
17181643Skmacy	elmtLen = BDecLen ( b, bytesDecoded );
18181643Skmacy	if ( elmtLen <= 0 ) return (-1);
19181643Skmacy	if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) {
20181643Skmacy		return (-1);
21181643Skmacy	}
22181643Skmacy
23181643Skmacy	return BDecComponentCertificateList( mem_op, b, tag, elmtLen, ( ComponentCertificateList**)v, (AsnLen*)bytesDecoded, mode );
24181643Skmacy}
25181643Skmacy
26181643Skmacy
27181643Skmacyvoid init_module_CertificateRevokationList() {
28181643Skmacy	InstallOidDecoderMapping( "2.5.4.39", NULL,
29181643Skmacy		GDecComponentCertificateList,
30181643Skmacy		BDecComponentCertificateListTop,
31181643Skmacy		ExtractingComponentCertificateList,
32181643Skmacy		MatchingComponentCertificateList);
33181643Skmacy}
34181643Skmacy
35181643Skmacyint
36181643SkmacyMatchingComponentTBSCertListSeqOfSeq ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
37181643Skmacy	int rc;
38181643Skmacy	MatchingRule* mr;
39181643Skmacy
40181643Skmacy	if ( oid ) {
41181643Skmacy		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
42181643Skmacy		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
43189699Sdfr	}
44189699Sdfr
45186557Skmacy	rc = 1;
46186557Skmacy	rc =	MatchingComponentCertificateSerialNumber ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertListSeqOfSeq*)csi_attr)->userCertificate, (ComponentSyntaxInfo*)&((ComponentTBSCertListSeqOfSeq*)csi_assert)->userCertificate );
47186557Skmacy	if ( rc != LDAP_COMPARE_TRUE )
48189699Sdfr		return rc;
49181643Skmacy	rc =	MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertListSeqOfSeq*)csi_attr)->revocationDate, (ComponentSyntaxInfo*)((ComponentTBSCertListSeqOfSeq*)csi_assert)->revocationDate );
50185605Skmacy	if ( rc != LDAP_COMPARE_TRUE )
51185605Skmacy		return rc;
52181643Skmacy	if(COMPONENTNOT_NULL( ((ComponentTBSCertListSeqOfSeq*)csi_attr)->crlEntryExtensions ) ) {
53181643Skmacy	rc =	MatchingComponentExtensions ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertListSeqOfSeq*)csi_attr)->crlEntryExtensions, (ComponentSyntaxInfo*)((ComponentTBSCertListSeqOfSeq*)csi_assert)->crlEntryExtensions );
54181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
55181643Skmacy		return rc;
56181643Skmacy	}
57185605Skmacy	return LDAP_COMPARE_TRUE;
58185605Skmacy}  /* BMatchingComponentTBSCertListSeqOfSeq */
59181643Skmacy
60181643Skmacyvoid*
61181643SkmacyExtractingComponentTBSCertListSeqOfSeq ( void* mem_op, ComponentReference* cr, ComponentTBSCertListSeqOfSeq *comp )
62181643Skmacy{
63185605Skmacy
64185605Skmacy	if ( ( comp->userCertificate.identifier.bv_val && strncmp(comp->userCertificate.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->userCertificate.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
65185605Skmacy		if ( cr->cr_curr->ci_next == NULL )
66185605Skmacy		return &comp->userCertificate;
67185605Skmacy		else
68181643Skmacy		return NULL;
69181643Skmacy	}
70181643Skmacy	if ( ( comp->revocationDate->identifier.bv_val && strncmp(comp->revocationDate->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->revocationDate->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
71181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
72181643Skmacy			return comp->revocationDate;
73181643Skmacy		else {
74181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
75181643Skmacy			return 	ExtractingComponentTime ( mem_op, cr, comp->revocationDate );
76181643Skmacy		}
77181643Skmacy	}
78181643Skmacy	if ( ( comp->crlEntryExtensions->identifier.bv_val && strncmp(comp->crlEntryExtensions->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->crlEntryExtensions->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
79181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
80181643Skmacy			return comp->crlEntryExtensions;
81181643Skmacy		else {
82181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
83181643Skmacy			return 	ExtractingComponentExtensions ( mem_op, cr, comp->crlEntryExtensions );
84181643Skmacy		}
85181643Skmacy	}
86181643Skmacy	return NULL;
87181643Skmacy}  /* ExtractingComponentTBSCertListSeqOfSeq */
88181643Skmacy
89181643Skmacyint
90181643SkmacyBDecComponentTBSCertListSeqOfSeq PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
91181643Skmacyvoid* mem_op _AND_
92181643SkmacyGenBuf * b _AND_
93181643SkmacyAsnTag tagId0 _AND_
94181643SkmacyAsnLen elmtLen0 _AND_
95181643SkmacyComponentTBSCertListSeqOfSeq **v _AND_
96181643SkmacyAsnLen *bytesDecoded _AND_
97181643Skmacyint mode)
98181643Skmacy{
99181643Skmacy	int seqDone = FALSE;
100181643Skmacy	AsnLen totalElmtsLen1 = 0;
101181643Skmacy	AsnLen elmtLen1;
102181643Skmacy	AsnTag tagId1;
103181643Skmacy	int mandatoryElmtCount1 = 0;
104181643Skmacy	AsnLen totalElmtsLen2 = 0;
105181643Skmacy	AsnLen elmtLen2;
106181643Skmacy	AsnTag tagId2;
107181643Skmacy	int old_mode = mode;
108181643Skmacy	int rc;
109189699Sdfr	ComponentTBSCertListSeqOfSeq *k, *t, c_temp;
110181643Skmacy
111181643Skmacy
112181643Skmacy	if ( !(mode & DEC_ALLOC_MODE_1) ) {
113181643Skmacy		memset(&c_temp,0,sizeof(c_temp));
114181643Skmacy		 k = &c_temp;
115181643Skmacy	} else
116181643Skmacy		 k = t = *v;
117181643Skmacy	mode = DEC_ALLOC_MODE_2;
118181643Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1 );
119181643Skmacy
120181643Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))))
121181643Skmacy    {
122181643Skmacy    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
123181643Skmacy	rc = BDecComponentCertificateSerialNumber (mem_op, b, tagId1, elmtLen1, (&k->userCertificate), &totalElmtsLen1, mode);
124181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
125181643Skmacy		(&k->userCertificate)->identifier.bv_val = (&k->userCertificate)->id_buf;
126181643Skmacy		(&k->userCertificate)->identifier.bv_len = strlen("userCertificate");
127181643Skmacy		strcpy( (&k->userCertificate)->identifier.bv_val, "userCertificate");
128181643Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1);
129181643Skmacy    }
130181643Skmacy    else
131181643Skmacy        return -1;
132181643Skmacy
133181643Skmacy
134181643Skmacy
135181805Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) ||
136181805Skmacy(tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) ||
137181643Skmacy     (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))||
138181643Skmacy    (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE))))
139181643Skmacy    {
140181643Skmacy        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
141185605Skmacy	rc = BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->revocationDate), &totalElmtsLen1, mode);
142185605Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
143185605Skmacy		(k->revocationDate)->identifier.bv_val = (k->revocationDate)->id_buf;
144185605Skmacy		(k->revocationDate)->identifier.bv_len = strlen("revocationDate");
145185605Skmacy		strcpy( (k->revocationDate)->identifier.bv_val, "revocationDate");
146185605Skmacy    if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
147185605Skmacy        seqDone = TRUE;
148185605Skmacy    else
149185605Skmacy    {
150185605Skmacy        tagId1 = BDecTag (b, &totalElmtsLen1 );
151185605Skmacy
152185605Skmacy         if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
153185605Skmacy        {
154185605Skmacy            BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
155185605Skmacy            seqDone = TRUE;
156185605Skmacy        }
157185605Skmacy    }
158185605Skmacy    }
159185605Skmacy    else
160185605Skmacy        return -1;
161185605Skmacy
162185605Skmacy
163185605Skmacy
164185605Skmacy    if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
165185605Skmacy    {
166185605Skmacy    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
167185605Skmacy	rc = BDecComponentExtensions (mem_op, b, tagId1, elmtLen1, (&k->crlEntryExtensions), &totalElmtsLen1, mode);
168185605Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
169185605Skmacy		(k->crlEntryExtensions)->identifier.bv_val = (k->crlEntryExtensions)->id_buf;
170185605Skmacy		(k->crlEntryExtensions)->identifier.bv_len = strlen("crlEntryExtensions");
171185605Skmacy		strcpy( (k->crlEntryExtensions)->identifier.bv_val, "crlEntryExtensions");
172185605Skmacy        seqDone = TRUE;
173185605Skmacy        if (elmtLen0 == INDEFINITE_LEN)
174185605Skmacy            BDecEoc (b, &totalElmtsLen1 );
175185605Skmacy        else if (totalElmtsLen1 != elmtLen0)
176185605Skmacy        return -1;
177185605Skmacy
178185605Skmacy    }
179185605Skmacy
180185605Skmacy
181185605Skmacy    if (!seqDone)
182185605Skmacy        return -1;
183185605Skmacy
184185605Skmacy	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
185185605Skmacy	*v = t = (ComponentTBSCertListSeqOfSeq*) CompAlloc( mem_op, sizeof(ComponentTBSCertListSeqOfSeq) );
186185605Skmacy	if ( !t ) return -1;
187185605Skmacy	*t = *k;
188185605Skmacy	}
189185605Skmacy	t->syntax = (Syntax*)NULL;
190185605Skmacy	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
191185605Skmacy	if ( !t->comp_desc ) {
192185605Skmacy		free ( t );
193185605Skmacy		return -1;
194185605Skmacy	}
195185605Skmacy	t->comp_desc->cd_ldap_encoder = (encoder_func*)NULL;
196185605Skmacy	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
197185605Skmacy	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
198185605Skmacy	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertListSeqOfSeq ;
199185605Skmacy	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertListSeqOfSeq ;
200185605Skmacy	t->comp_desc->cd_free = (comp_free_func*)NULL;
201185605Skmacy	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertListSeqOfSeq;
202185605Skmacy	t->comp_desc->cd_type = ASN_COMPOSITE;
203185605Skmacy	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
204185605Skmacy	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertListSeqOfSeq;
205185605Skmacy    (*bytesDecoded) += totalElmtsLen1;
206185605Skmacy	return LDAP_SUCCESS;
207185605Skmacy}  /* BDecTBSCertListSeqOfSeq*/
208181643Skmacy
209185605Skmacyint
210185605SkmacyGDecComponentTBSCertListSeqOfSeq PARAMS (( mem_op,b, v, bytesDecoded, mode),
211185605Skmacyvoid* mem_op _AND_
212181643SkmacyGenBuf * b _AND_
213181643SkmacyComponentTBSCertListSeqOfSeq **v _AND_
214185605SkmacyAsnLen *bytesDecoded _AND_
215185605Skmacyint mode)
216186557Skmacy{
217185605Skmacy	char* peek_head,*peek_head2;
218182082Skmacy	int i, strLen,strLen2, rc, old_mode = mode;
219181643Skmacy	ComponentTBSCertListSeqOfSeq *k,*t, c_temp;
220185605Skmacy
221181643Skmacy
222181643Skmacy	if ( !(mode & DEC_ALLOC_MODE_1) ) {
223181643Skmacy		memset(&c_temp,0,sizeof(c_temp));
224185605Skmacy		 k = &c_temp;
225185605Skmacy	} else
226185605Skmacy		 k = t = *v;
227181643Skmacy	mode = DEC_ALLOC_MODE_2;
228181643Skmacy	*bytesDecoded = 0;
229186557Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
230181643Skmacy		Asn1Error("Error during Reading { in encoded data");
231181643Skmacy		return LDAP_PROTOCOL_ERROR;
232181643Skmacy	}
233181643Skmacy	if(*peek_head != '{'){
234186557Skmacy		Asn1Error("Missing { in encoded data");
235181643Skmacy		return LDAP_PROTOCOL_ERROR;
236181643Skmacy	}
237181643Skmacy
238181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
239181643Skmacy		Asn1Error("Error during Reading identifier");
240181643Skmacy		return LDAP_PROTOCOL_ERROR;
241181643Skmacy	}
242181643Skmacy	if ( strncmp( peek_head, "userCertificate", strlen("userCertificate") ) == 0 ) {
243181643Skmacy		rc = 	GDecComponentCertificateSerialNumber (mem_op, b, (&k->userCertificate), bytesDecoded, mode);
244181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
245181643Skmacy	(&k->userCertificate)->identifier.bv_val = peek_head;
246181643Skmacy	(&k->userCertificate)->identifier.bv_len = strLen;
247181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
248181643Skmacy		Asn1Error("Error during Reading , ");
249181643Skmacy		return LDAP_PROTOCOL_ERROR;
250181643Skmacy	}
251181643Skmacy	if(*peek_head != ','){
252181643Skmacy		Asn1Error("Missing , in encoding");
253181643Skmacy		return LDAP_PROTOCOL_ERROR;
254181643Skmacy	}
255181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
256181643Skmacy	  Asn1Error("Error during Reading identifier");
257181643Skmacy		return LDAP_PROTOCOL_ERROR;
258181643Skmacy	}
259181643Skmacy	}
260181643Skmacy	if ( strncmp( peek_head, "revocationDate", strlen("revocationDate") ) == 0 ) {
261181643Skmacy		rc = 	GDecComponentTime (mem_op, b, (&k->revocationDate), bytesDecoded, mode);
262181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
263181643Skmacy	( k->revocationDate)->identifier.bv_val = peek_head;
264181643Skmacy	( k->revocationDate)->identifier.bv_len = strLen;
265181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
266181643Skmacy		Asn1Error("Error during Reading , ");
267181643Skmacy		return LDAP_PROTOCOL_ERROR;
268181643Skmacy	}
269181643Skmacy	if(*peek_head != ','){
270181643Skmacy		Asn1Error("Missing , in encoding");
271181643Skmacy		return LDAP_PROTOCOL_ERROR;
272181643Skmacy	}
273181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
274181643Skmacy	  Asn1Error("Error during Reading identifier");
275181643Skmacy		return LDAP_PROTOCOL_ERROR;
276181643Skmacy	}
277181643Skmacy	}
278181643Skmacy	if ( strncmp( peek_head, "crlEntryExtensions", strlen("crlEntryExtensions") ) == 0 ) {
279181643Skmacy		rc = 	GDecComponentExtensions (mem_op, b, (&k->crlEntryExtensions), bytesDecoded, mode);
280181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
281181643Skmacy	( k->crlEntryExtensions)->identifier.bv_val = peek_head;
282181643Skmacy	( k->crlEntryExtensions)->identifier.bv_len = strLen;
283181643Skmacy	}
284181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
285181643Skmacy		Asn1Error("Error during Reading } in encoding");
286181643Skmacy		return LDAP_PROTOCOL_ERROR;
287181643Skmacy	}
288181643Skmacy	if(*peek_head != '}'){
289181643Skmacy		Asn1Error("Missing } in encoding");
290181643Skmacy		return LDAP_PROTOCOL_ERROR;
291181643Skmacy	}
292181643Skmacy	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
293181643Skmacy	*v = t = (ComponentTBSCertListSeqOfSeq*) CompAlloc( mem_op, sizeof(ComponentTBSCertListSeqOfSeq) );
294181643Skmacy	if ( !t ) return -1;
295181643Skmacy	*t = *k;
296181643Skmacy	}
297181643Skmacy	t->syntax = (Syntax*)NULL;
298181643Skmacy	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
299181643Skmacy	if ( !t->comp_desc ) {
300181643Skmacy		free ( t );
301181643Skmacy		return -1;
302181643Skmacy	}
303181643Skmacy	t->comp_desc->cd_ldap_encoder = (encoder_func*)NULL;
304185605Skmacy	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
305185605Skmacy	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
306185605Skmacy	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertListSeqOfSeq ;
307181643Skmacy	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertListSeqOfSeq ;
308185605Skmacy	t->comp_desc->cd_free = (comp_free_func*)NULL;
309185605Skmacy	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertListSeqOfSeq;
310185605Skmacy	t->comp_desc->cd_type = ASN_COMPOSITE;
311185605Skmacy	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
312185605Skmacy	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertListSeqOfSeq;
313181643Skmacy	return LDAP_SUCCESS;
314185605Skmacy}  /* GDecTBSCertListSeqOfSeq*/
315185605Skmacy
316185605Skmacy
317185605Skmacyint
318185605SkmacyMatchingComponentTBSCertListSeqOf ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
319185605Skmacy	int rc;
320185605Skmacy	MatchingRule* mr;
321185605Skmacy	void* component1, *component2;
322185605Skmacy	AsnList *v1, *v2, t_list;
323185605Skmacy
324181643Skmacy
325189699Sdfr	if ( oid ) {
326181643Skmacy		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
327185605Skmacy		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
328181643Skmacy	}
329181643Skmacy
330189699Sdfr	v1 = &((ComponentTBSCertListSeqOf*)csi_attr)->comp_list;
331186557Skmacy	v2 = &((ComponentTBSCertListSeqOf*)csi_assert)->comp_list;
332189699Sdfr	FOR_EACH_LIST_PAIR_ELMT(component1, component2, v1, v2)
333189699Sdfr	{
334181805Skmacy		if( MatchingComponentTBSCertListSeqOfSeq(oid, (ComponentSyntaxInfo*)component1, (ComponentSyntaxInfo*)component2) == LDAP_COMPARE_FALSE) {
335189699Sdfr			return LDAP_COMPARE_FALSE;
336181643Skmacy		}
337181643Skmacy	} /* end of for */
338185605Skmacy
339185605Skmacy	AsnListFirst( v1 );
340185605Skmacy	AsnListFirst( v2 );
341185605Skmacy	if( (!component1 && component2) || (component1 && !component2))
342185605Skmacy		return LDAP_COMPARE_FALSE;
343181643Skmacy	else
344181643Skmacy		return LDAP_COMPARE_TRUE;
345181643Skmacy}  /* BMatchingComponentTBSCertListSeqOfContent */
346181643Skmacy
347181643Skmacyvoid*
348181643SkmacyExtractingComponentTBSCertListSeqOf ( void* mem_op, ComponentReference* cr, ComponentTBSCertListSeqOf *comp )
349181643Skmacy{
350181643Skmacy	int count = 0;
351181643Skmacy	int total;
352181643Skmacy	AsnList *v = &comp->comp_list;
353181643Skmacy	ComponentInt *k;
354181643Skmacy	ComponentTBSCertListSeqOfSeq *component;
355181643Skmacy
356181643Skmacy
357181643Skmacy	switch ( cr->cr_curr->ci_type ) {
358181643Skmacy	case LDAP_COMPREF_FROM_BEGINNING :
359181643Skmacy		count = cr->cr_curr->ci_val.ci_from_beginning;
360181643Skmacy		FOR_EACH_LIST_ELMT( component , v ) {
361181643Skmacy			if( --count == 0 ) {
362185605Skmacy				if( cr->cr_curr->ci_next == NULL )
363181643Skmacy					return component;
364189699Sdfr				else {
365189699Sdfr					cr->cr_curr = cr->cr_curr->ci_next;
366189699Sdfr					return 	ExtractingComponentTBSCertListSeqOfSeq ( mem_op, cr, component );
367181643Skmacy				}
368185605Skmacy			}
369181643Skmacy		}
370181643Skmacy		break;
371185605Skmacy	case LDAP_COMPREF_FROM_END :
372189699Sdfr		total = AsnListCount ( v );
373189699Sdfr		count = cr->cr_curr->ci_val.ci_from_end;
374189699Sdfr		count = total + count +1;
375189699Sdfr		FOR_EACH_LIST_ELMT ( component, v ) {
376189699Sdfr			if( --count == 0 ) {
377189699Sdfr				if( cr->cr_curr->ci_next == NULL )
378189699Sdfr					return component;
379189699Sdfr				else {
380189699Sdfr					cr->cr_curr = cr->cr_curr->ci_next;
381189699Sdfr					return 	ExtractingComponentTBSCertListSeqOfSeq ( mem_op, cr, component );
382189699Sdfr				}
383189699Sdfr			}
384189699Sdfr		}
385185605Skmacy		break;
386181643Skmacy	case LDAP_COMPREF_ALL :
387185605Skmacy		return comp;
388181643Skmacy	case LDAP_COMPREF_COUNT :
389181643Skmacy		k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt));
390189699Sdfr		k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
391181643Skmacy		k->comp_desc->cd_tag = (-1);
392181643Skmacy		k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
393181643Skmacy		k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
394186557Skmacy		k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL;
395181643Skmacy		k->comp_desc->cd_type = ASN_BASIC;
396181643Skmacy		k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
397189699Sdfr		k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
398181643Skmacy		k->value = AsnListCount(v);
399181643Skmacy		return k;
400181643Skmacy	default :
401185605Skmacy		return NULL;
402185605Skmacy	}
403181643Skmacy}  /* ExtractingComponentTBSCertListSeqOf */
404181643Skmacy
405181643Skmacyint
406181643SkmacyBDecComponentTBSCertListSeqOf PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
407181643Skmacyvoid* mem_op _AND_
408181643SkmacyGenBuf * b _AND_
409181643SkmacyAsnTag tagId0 _AND_
410181643SkmacyAsnLen elmtLen0 _AND_
411181643SkmacyComponentTBSCertListSeqOf **v _AND_
412181643SkmacyAsnLen *bytesDecoded _AND_
413181643Skmacyint mode)
414181643Skmacy{
415181643Skmacy	int seqDone = FALSE;
416181643Skmacy	AsnLen totalElmtsLen1 = 0;
417181643Skmacy	AsnLen elmtLen1;
418181643Skmacy	AsnTag tagId1;
419181643Skmacy	int mandatoryElmtCount1 = 0;
420185605Skmacy	int old_mode = mode;
421181643Skmacy	int rc;
422181643Skmacy	ComponentTBSCertListSeqOf *k, *t, c_temp;
423181643Skmacy
424181643Skmacy
425181643Skmacy	if ( !(mode & DEC_ALLOC_MODE_1) ) {
426185605Skmacy		memset(&c_temp,0,sizeof(c_temp));
427181643Skmacy		 k = &c_temp;
428181643Skmacy	} else
429181643Skmacy		 k = t = *v;
430181643Skmacy	mode = DEC_ALLOC_MODE_2;
431181643Skmacy	AsnListInit(&k->comp_list,sizeof(ComponentTBSCertListSeqOfSeq));
432185605Skmacy    for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);)
433185605Skmacy    {
434185605Skmacy        ComponentTBSCertListSeqOfSeq **tmpVar;
435185605Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1 );
436185605Skmacy
437185605Skmacy    if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
438189699Sdfr    {
439181643Skmacy        BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
440181643Skmacy        break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/
441186557Skmacy    }
442181643Skmacy    if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
443181643Skmacy    {
444181643Skmacy        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
445181643Skmacy    tmpVar = (ComponentTBSCertListSeqOfSeq**) CompAsnListAppend (mem_op,&k->comp_list);
446185605Skmacy	rc = BDecComponentTBSCertListSeqOfSeq (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode);
447181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
448181643Skmacy    }  /* end of tag check if */
449181643Skmacy    else  /* wrong tag */
450181643Skmacy    {
451181643Skmacy         Asn1Error ("Unexpected Tag\n");
452181643Skmacy         return -1;
453181643Skmacy    }
454181643Skmacy    } /* end of for */
455181643Skmacy
456181643Skmacy	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
457181643Skmacy	*v = t = (ComponentTBSCertListSeqOf*) CompAlloc( mem_op, sizeof(ComponentTBSCertListSeqOf) );
458181643Skmacy	if ( !t ) return -1;
459181643Skmacy	*t = *k;
460181643Skmacy	}
461185605Skmacy	t->syntax = (Syntax*)NULL;
462181643Skmacy	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
463181643Skmacy	if ( !t->comp_desc ) {
464186557Skmacy		free ( t );
465181643Skmacy		return -1;
466181643Skmacy	}
467181643Skmacy	t->comp_desc->cd_ldap_encoder = (encoder_func*)NULL;
468181643Skmacy	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
469181643Skmacy	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
470181643Skmacy	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertListSeqOf ;
471181643Skmacy	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertListSeqOf ;
472181643Skmacy	t->comp_desc->cd_free = (comp_free_func*)NULL;
473181643Skmacy	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertListSeqOf;
474181643Skmacy	t->comp_desc->cd_type = ASN_COMPOSITE;
475181643Skmacy	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
476189699Sdfr	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertListSeqOf;
477189699Sdfr    (*bytesDecoded) += totalElmtsLen1;
478186557Skmacy	return LDAP_SUCCESS;
479181643Skmacy}  /* BDecTBSCertListSeqOfContent */
480181643Skmacy
481181643Skmacyint
482181643SkmacyGDecComponentTBSCertListSeqOf PARAMS (( mem_op,b, v, bytesDecoded, mode),
483181643Skmacyvoid* mem_op _AND_
484186557SkmacyGenBuf * b _AND_
485189699SdfrComponentTBSCertListSeqOf **v _AND_
486189699SdfrAsnLen *bytesDecoded _AND_
487186557Skmacyint mode)
488186557Skmacy{
489189699Sdfr	char* peek_head,*peek_head2;
490181643Skmacy	int i, strLen,strLen2, rc, old_mode = mode;
491181643Skmacy	ComponentTBSCertListSeqOf *k,*t, c_temp;
492181643Skmacy
493186557Skmacy
494181643Skmacy	int ElmtsLen1;
495181643Skmacy	if ( !(mode & DEC_ALLOC_MODE_1) ) {
496186557Skmacy		memset(&c_temp,0,sizeof(c_temp));
497181643Skmacy		 k = &c_temp;
498181643Skmacy	} else
499181643Skmacy		 k = t = *v;
500181643Skmacy	mode = DEC_ALLOC_MODE_2;
501181643Skmacy	AsnListInit( &k->comp_list, sizeof( ComponentTBSCertListSeqOfSeq ) );
502181643Skmacy	*bytesDecoded = 0;
503185605Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){
504185605Skmacy		Asn1Error("Error during Reading { in encoding");
505181643Skmacy		return LDAP_PROTOCOL_ERROR;
506185605Skmacy	}
507181643Skmacy	if(*peek_head != '{'){
508189699Sdfr		Asn1Error("Missing { in encoded data");
509181643Skmacy		return LDAP_PROTOCOL_ERROR;
510181643Skmacy	}
511181643Skmacy
512181643Skmacy	for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++)
513181643Skmacy	{
514181643Skmacy		ComponentTBSCertListSeqOfSeq **tmpVar;
515181643Skmacy		if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){
516183375Skmacy			Asn1Error("Error during Reading{ in encoding");
517183375Skmacy			return LDAP_PROTOCOL_ERROR;
518181643Skmacy		}
519181643Skmacy		if(*peek_head == '}') break;
520181643Skmacy		if( !(*peek_head == '{' || *peek_head ==',') ) {
521185605Skmacy			return LDAP_PROTOCOL_ERROR;
522181643Skmacy		}
523181643Skmacy		tmpVar = (ComponentTBSCertListSeqOfSeq**) CompAsnListAppend (mem_op, &k->comp_list);
524181643Skmacy		if ( tmpVar == NULL ) {
525181643Skmacy			Asn1Error("Error during Reading{ in encoding");
526181643Skmacy			return LDAP_PROTOCOL_ERROR;
527181643Skmacy		}
528181643Skmacy		rc = 	GDecComponentTBSCertListSeqOfSeq (mem_op, b, tmpVar, bytesDecoded, mode);
529181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
530181643Skmacy	} /* end of for */
531181643Skmacy
532181643Skmacy	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
533181643Skmacy	*v = t = (ComponentTBSCertListSeqOf*) CompAlloc( mem_op, sizeof(ComponentTBSCertListSeqOf) );
534181643Skmacy	if ( !t ) return -1;
535181643Skmacy	*t = *k;
536181643Skmacy	}
537181643Skmacy	t->syntax = (Syntax*)NULL;
538181643Skmacy	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
539181643Skmacy	if ( !t->comp_desc ) {
540181643Skmacy		free ( t );
541181643Skmacy		return -1;
542181643Skmacy	}
543181643Skmacy	t->comp_desc->cd_ldap_encoder = (encoder_func*)NULL;
544181643Skmacy	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
545181643Skmacy	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
546181643Skmacy	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertListSeqOf ;
547181643Skmacy	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertListSeqOf ;
548181643Skmacy	t->comp_desc->cd_free = (comp_free_func*)NULL;
549181643Skmacy	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertListSeqOf;
550181643Skmacy	t->comp_desc->cd_type = ASN_COMPOSITE;
551181643Skmacy	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
552185605Skmacy	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertListSeqOf;
553181643Skmacy	return LDAP_SUCCESS;
554181643Skmacy}  /* GDecTBSCertListSeqOfContent */
555181643Skmacy
556181643Skmacyint
557181643SkmacyMatchingComponentTBSCertList ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
558181643Skmacy	int rc;
559181643Skmacy	MatchingRule* mr;
560181643Skmacy
561181643Skmacy	if ( oid ) {
562185605Skmacy		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
563181643Skmacy		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
564185605Skmacy	}
565181643Skmacy
566181643Skmacy	rc = 1;
567181643Skmacy	if(COMPONENTNOT_NULL( ((ComponentTBSCertList*)csi_attr)->version ) ) {
568181643Skmacy	rc =	MatchingComponentVersion ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_attr)->version, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_assert)->version );
569181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
570185605Skmacy		return rc;
571185605Skmacy	}
572185605Skmacy	rc =	MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_attr)->signature, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_assert)->signature );
573181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
574181643Skmacy		return rc;
575185605Skmacy	rc =	MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_attr)->issuer, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_assert)->issuer );
576181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
577181643Skmacy		return rc;
578181643Skmacy	rc =	MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_attr)->thisUpdate, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_assert)->thisUpdate );
579181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
580181643Skmacy		return rc;
581185605Skmacy	if(COMPONENTNOT_NULL( ((ComponentTBSCertList*)csi_attr)->nextUpdate ) ) {
582185605Skmacy	rc =	MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_attr)->nextUpdate, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_assert)->nextUpdate );
583185605Skmacy	if ( rc != LDAP_COMPARE_TRUE )
584185605Skmacy		return rc;
585185605Skmacy	}
586181643Skmacy	rc =	MatchingComponentTBSCertListSeqOf ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_attr)->revokedCertificates, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_assert)->revokedCertificates );
587185605Skmacy	if ( rc != LDAP_COMPARE_TRUE )
588181643Skmacy		return rc;
589185605Skmacy	if(COMPONENTNOT_NULL( ((ComponentTBSCertList*)csi_attr)->crlExtensions ) ) {
590185605Skmacy	rc =	MatchingComponentExtensions ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_attr)->crlExtensions, (ComponentSyntaxInfo*)((ComponentTBSCertList*)csi_assert)->crlExtensions );
591181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
592181643Skmacy		return rc;
593181643Skmacy	}
594181643Skmacy	return LDAP_COMPARE_TRUE;
595181643Skmacy}  /* BMatchingComponentTBSCertList */
596181914Skmacy
597181914Skmacyvoid*
598181643SkmacyExtractingComponentTBSCertList ( void* mem_op, ComponentReference* cr, ComponentTBSCertList *comp )
599181643Skmacy{
600181643Skmacy
601181643Skmacy	if ( ( comp->version->identifier.bv_val && strncmp(comp->version->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->version->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
602181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
603181643Skmacy			return comp->version;
604181643Skmacy		else {
605181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
606181643Skmacy			return 	ExtractingComponentVersion ( mem_op, cr, comp->version );
607181643Skmacy		}
608181643Skmacy	}
609185605Skmacy	if ( ( comp->signature->identifier.bv_val && strncmp(comp->signature->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signature->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
610185605Skmacy		if ( cr->cr_curr->ci_next == NULL )
611181643Skmacy			return comp->signature;
612185605Skmacy		else {
613181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
614185605Skmacy			return 	ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signature );
615181643Skmacy		}
616181643Skmacy	}
617181643Skmacy	if ( ( comp->issuer->identifier.bv_val && strncmp(comp->issuer->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->issuer->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
618181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
619181643Skmacy			return comp->issuer;
620181643Skmacy		else {
621181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
622185605Skmacy			return 	ExtractingComponentName ( mem_op, cr, comp->issuer );
623181643Skmacy		}
624181643Skmacy	}
625181643Skmacy	if ( ( comp->thisUpdate->identifier.bv_val && strncmp(comp->thisUpdate->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->thisUpdate->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
626185605Skmacy		if ( cr->cr_curr->ci_next == NULL )
627185605Skmacy			return comp->thisUpdate;
628181643Skmacy		else {
629185605Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
630181643Skmacy			return 	ExtractingComponentTime ( mem_op, cr, comp->thisUpdate );
631185605Skmacy		}
632181643Skmacy	}
633181643Skmacy	if ( ( comp->nextUpdate->identifier.bv_val && strncmp(comp->nextUpdate->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->nextUpdate->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
634181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
635181643Skmacy			return comp->nextUpdate;
636181643Skmacy		else {
637181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
638181643Skmacy			return 	ExtractingComponentTime ( mem_op, cr, comp->nextUpdate );
639181643Skmacy		}
640181643Skmacy	}
641181643Skmacy	if ( ( comp->revokedCertificates->identifier.bv_val && strncmp(comp->revokedCertificates->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->revokedCertificates->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
642181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
643181643Skmacy			return comp->revokedCertificates;
644181643Skmacy		else {
645181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
646181643Skmacy			return 	ExtractingComponentTBSCertListSeqOf ( mem_op, cr, comp->revokedCertificates );
647181643Skmacy		}
648181643Skmacy	}
649181643Skmacy	if ( ( comp->crlExtensions->identifier.bv_val && strncmp(comp->crlExtensions->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->crlExtensions->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
650181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
651181643Skmacy			return comp->crlExtensions;
652181643Skmacy		else {
653181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
654181643Skmacy			return 	ExtractingComponentExtensions ( mem_op, cr, comp->crlExtensions );
655181643Skmacy		}
656181643Skmacy	}
657181643Skmacy	return NULL;
658181643Skmacy}  /* ExtractingComponentTBSCertList */
659181643Skmacy
660181643Skmacyint
661181643SkmacyBDecComponentTBSCertList PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
662181643Skmacyvoid* mem_op _AND_
663181643SkmacyGenBuf * b _AND_
664181643SkmacyAsnTag tagId0 _AND_
665181643SkmacyAsnLen elmtLen0 _AND_
666181643SkmacyComponentTBSCertList **v _AND_
667181643SkmacyAsnLen *bytesDecoded _AND_
668181643Skmacyint mode)
669181643Skmacy{
670181643Skmacy	int seqDone = FALSE;
671181643Skmacy	AsnLen totalElmtsLen1 = 0;
672181643Skmacy	AsnLen elmtLen1;
673181643Skmacy	AsnTag tagId1;
674181643Skmacy	int mandatoryElmtCount1 = 0;
675181643Skmacy	AsnLen totalElmtsLen2 = 0;
676181643Skmacy	AsnLen elmtLen2;
677181643Skmacy	AsnTag tagId2;
678181643Skmacy	int old_mode = mode;
679181643Skmacy	int rc;
680181643Skmacy	ComponentTBSCertList *k, *t, c_temp;
681181643Skmacy
682181643Skmacy
683181643Skmacy	if ( !(mode & DEC_ALLOC_MODE_1) ) {
684181643Skmacy		memset(&c_temp,0,sizeof(c_temp));
685181643Skmacy		 k = &c_temp;
686181643Skmacy	} else
687181643Skmacy		 k = t = *v;
688181643Skmacy	mode = DEC_ALLOC_MODE_2;
689181643Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1 );
690181643Skmacy
691181643Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))))
692181643Skmacy    {
693181643Skmacy    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
694181643Skmacy	rc = BDecComponentVersion (mem_op, b, tagId1, elmtLen1, (&k->version), &totalElmtsLen1, DEC_ALLOC_MODE_0 );
695181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
696181643Skmacy		(k->version)->identifier.bv_val = (k->version)->id_buf;
697181643Skmacy		(k->version)->identifier.bv_len = strlen("version");
698181643Skmacy		strcpy( (k->version)->identifier.bv_val, "version");
699181643Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1);
700181643Skmacy    }
701181643Skmacy
702181643Skmacy
703181643Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
704181643Skmacy    {
705181643Skmacy    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
706181643Skmacy	rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode);
707181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
708181643Skmacy		(k->signature)->identifier.bv_val = (k->signature)->id_buf;
709181643Skmacy		(k->signature)->identifier.bv_len = strlen("signature");
710181643Skmacy		strcpy( (k->signature)->identifier.bv_val, "signature");
711181643Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1);
712181643Skmacy    }
713181643Skmacy    else
714181643Skmacy        return -1;
715181643Skmacy
716181643Skmacy
717181643Skmacy
718181643Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
719181643Skmacy    {
720181643Skmacy        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
721189699Sdfr	rc = BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->issuer), &totalElmtsLen1, mode);
722181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
723181643Skmacy		(k->issuer)->identifier.bv_val = (k->issuer)->id_buf;
724181643Skmacy		(k->issuer)->identifier.bv_len = strlen("issuer");
725181643Skmacy		strcpy( (k->issuer)->identifier.bv_val, "issuer");
726181643Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1);
727181643Skmacy    }
728181643Skmacy    else
729181643Skmacy        return -1;
730181643Skmacy
731181643Skmacy
732181643Skmacy
733181643Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) ||
734181643Skmacy(tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) ||
735181643Skmacy     (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))||
736181643Skmacy    (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE))))
737181643Skmacy    {
738181643Skmacy        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
739181643Skmacy	rc = BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->thisUpdate), &totalElmtsLen1, mode);
740181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
741181643Skmacy		(k->thisUpdate)->identifier.bv_val = (k->thisUpdate)->id_buf;
742185605Skmacy		(k->thisUpdate)->identifier.bv_len = strlen("thisUpdate");
743185605Skmacy		strcpy( (k->thisUpdate)->identifier.bv_val, "thisUpdate");
744185605Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1);
745181643Skmacy    }
746181643Skmacy    else
747181643Skmacy        return -1;
748181643Skmacy
749181643Skmacy
750181643Skmacy
751181643Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) ||
752181643Skmacy(tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) ||
753181643Skmacy     (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))||
754181643Skmacy    (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE))))
755181643Skmacy    {
756181643Skmacy        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
757181643Skmacy	rc = BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->nextUpdate), &totalElmtsLen1, mode);
758181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
759181643Skmacy		(k->nextUpdate)->identifier.bv_val = (k->nextUpdate)->id_buf;
760181643Skmacy		(k->nextUpdate)->identifier.bv_len = strlen("nextUpdate");
761181643Skmacy		strcpy( (k->nextUpdate)->identifier.bv_val, "nextUpdate");
762181643Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1);
763181643Skmacy    }
764181643Skmacy
765181643Skmacy
766181643Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
767181643Skmacy    {
768181643Skmacy    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
769181643Skmacy	rc = BDecComponentTBSCertListSeqOf (mem_op, b, tagId1, elmtLen1, (&k->revokedCertificates), &totalElmtsLen1, mode);
770181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
771181643Skmacy		(k->revokedCertificates)->identifier.bv_val = (k->revokedCertificates)->id_buf;
772181643Skmacy		(k->revokedCertificates)->identifier.bv_len = strlen("revokedCertificates");
773181643Skmacy		strcpy( (k->revokedCertificates)->identifier.bv_val, "revokedCertificates");
774181643Skmacy    if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
775181643Skmacy        seqDone = TRUE;
776181643Skmacy    else
777181805Skmacy    {
778181643Skmacy        tagId1 = BDecTag (b, &totalElmtsLen1 );
779181643Skmacy
780181805Skmacy         if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
781181643Skmacy        {
782181643Skmacy            BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
783181643Skmacy            seqDone = TRUE;
784181643Skmacy        }
785181643Skmacy    }
786181643Skmacy    }
787181643Skmacy    else
788181643Skmacy        return -1;
789181643Skmacy
790181643Skmacy
791181643Skmacy
792181643Skmacy    if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, CONS, 0))))
793181643Skmacy    {
794181643Skmacy    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
795181643Skmacy        tagId2 = BDecTag (b, &totalElmtsLen1 );
796181643Skmacy
797181643Skmacy    if (tagId2 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
798181643Skmacy    {
799181643Skmacy         Asn1Error ("Unexpected Tag\n");
800181643Skmacy         return -1;
801181643Skmacy    }
802181643Skmacy
803181643Skmacy    elmtLen2 = BDecLen (b, &totalElmtsLen1 );
804181643Skmacy	rc = BDecComponentExtensions (mem_op, b, tagId2, elmtLen2, (&k->crlExtensions), &totalElmtsLen1, mode);
805181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
806181643Skmacy		(k->crlExtensions)->identifier.bv_val = (k->crlExtensions)->id_buf;
807181643Skmacy		(k->crlExtensions)->identifier.bv_len = strlen("crlExtensions");
808181643Skmacy		strcpy( (k->crlExtensions)->identifier.bv_val, "crlExtensions");
809181643Skmacy	if (elmtLen1 == INDEFINITE_LEN)
810181643Skmacy        BDecEoc (b, &totalElmtsLen1 );
811181643Skmacy        seqDone = TRUE;
812181643Skmacy        if (elmtLen0 == INDEFINITE_LEN)
813181643Skmacy            BDecEoc (b, &totalElmtsLen1 );
814181643Skmacy        else if (totalElmtsLen1 != elmtLen0)
815181643Skmacy        return -1;
816181643Skmacy
817181643Skmacy    }
818181643Skmacy
819181643Skmacy
820181643Skmacy    if (!seqDone)
821181643Skmacy        return -1;
822181643Skmacy
823181643Skmacy	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
824181643Skmacy	*v = t = (ComponentTBSCertList*) CompAlloc( mem_op, sizeof(ComponentTBSCertList) );
825181643Skmacy	if ( !t ) return -1;
826181643Skmacy	*t = *k;
827181643Skmacy	}
828181643Skmacy	t->syntax = (Syntax*)NULL;
829181643Skmacy	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
830181643Skmacy	if ( !t->comp_desc ) {
831181643Skmacy		free ( t );
832181643Skmacy		return -1;
833181643Skmacy	}
834181643Skmacy	t->comp_desc->cd_ldap_encoder = (encoder_func*)NULL;
835181643Skmacy	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
836181643Skmacy	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
837181643Skmacy	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertList ;
838181643Skmacy	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertList ;
839181643Skmacy	t->comp_desc->cd_free = (comp_free_func*)NULL;
840181643Skmacy	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertList;
841181643Skmacy	t->comp_desc->cd_type = ASN_COMPOSITE;
842181643Skmacy	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
843185605Skmacy	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertList;
844181643Skmacy    (*bytesDecoded) += totalElmtsLen1;
845181643Skmacy	return LDAP_SUCCESS;
846181643Skmacy}  /* BDecTBSCertList*/
847181643Skmacy
848181643Skmacyint
849181643SkmacyGDecComponentTBSCertList PARAMS (( mem_op,b, v, bytesDecoded, mode),
850181643Skmacyvoid* mem_op _AND_
851181643SkmacyGenBuf * b _AND_
852181643SkmacyComponentTBSCertList **v _AND_
853181643SkmacyAsnLen *bytesDecoded _AND_
854181643Skmacyint mode)
855181643Skmacy{
856181643Skmacy	char* peek_head,*peek_head2;
857181643Skmacy	int i, strLen,strLen2, rc, old_mode = mode;
858181643Skmacy	ComponentTBSCertList *k,*t, c_temp;
859181643Skmacy
860181643Skmacy
861181643Skmacy	if ( !(mode & DEC_ALLOC_MODE_1) ) {
862181643Skmacy		memset(&c_temp,0,sizeof(c_temp));
863181643Skmacy		 k = &c_temp;
864181643Skmacy	} else
865181643Skmacy		 k = t = *v;
866181643Skmacy	mode = DEC_ALLOC_MODE_2;
867181643Skmacy	*bytesDecoded = 0;
868181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
869181643Skmacy		Asn1Error("Error during Reading { in encoded data");
870181643Skmacy		return LDAP_PROTOCOL_ERROR;
871181643Skmacy	}
872181643Skmacy	if(*peek_head != '{'){
873181643Skmacy		Asn1Error("Missing { in encoded data");
874181643Skmacy		return LDAP_PROTOCOL_ERROR;
875181643Skmacy	}
876181643Skmacy
877181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
878181643Skmacy		Asn1Error("Error during Reading identifier");
879181643Skmacy		return LDAP_PROTOCOL_ERROR;
880181643Skmacy	}
881181643Skmacy	if ( strncmp( peek_head, "version", strlen("version") ) == 0 ) {
882181643Skmacy		rc = 	GDecComponentVersion (mem_op, b, (&k->version), bytesDecoded, DEC_ALLOC_MODE_0 );
883181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
884181643Skmacy	( k->version)->identifier.bv_val = peek_head;
885181643Skmacy	( k->version)->identifier.bv_len = strLen;
886181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
887181643Skmacy		Asn1Error("Error during Reading , ");
888181643Skmacy		return LDAP_PROTOCOL_ERROR;
889181643Skmacy	}
890181643Skmacy	if(*peek_head != ','){
891181643Skmacy		Asn1Error("Missing , in encoding");
892181643Skmacy		return LDAP_PROTOCOL_ERROR;
893181643Skmacy	}
894181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
895181643Skmacy	  Asn1Error("Error during Reading identifier");
896181643Skmacy		return LDAP_PROTOCOL_ERROR;
897181643Skmacy	}
898181643Skmacy	}
899181643Skmacy	if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) {
900181643Skmacy		rc = 	GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signature), bytesDecoded, mode);
901181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
902181643Skmacy	( k->signature)->identifier.bv_val = peek_head;
903181643Skmacy	( k->signature)->identifier.bv_len = strLen;
904181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
905181643Skmacy		Asn1Error("Error during Reading , ");
906181643Skmacy		return LDAP_PROTOCOL_ERROR;
907181643Skmacy	}
908181643Skmacy	if(*peek_head != ','){
909181643Skmacy		Asn1Error("Missing , in encoding");
910181643Skmacy		return LDAP_PROTOCOL_ERROR;
911181643Skmacy	}
912181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
913181643Skmacy	  Asn1Error("Error during Reading identifier");
914181643Skmacy		return LDAP_PROTOCOL_ERROR;
915181643Skmacy	}
916181643Skmacy	}
917181643Skmacy	if ( strncmp( peek_head, "issuer", strlen("issuer") ) == 0 ) {
918181643Skmacy		rc = 	GDecComponentName (mem_op, b, (&k->issuer), bytesDecoded, mode);
919181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
920181643Skmacy	( k->issuer)->identifier.bv_val = peek_head;
921181643Skmacy	( k->issuer)->identifier.bv_len = strLen;
922181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
923181643Skmacy		Asn1Error("Error during Reading , ");
924181643Skmacy		return LDAP_PROTOCOL_ERROR;
925181643Skmacy	}
926181643Skmacy	if(*peek_head != ','){
927181643Skmacy		Asn1Error("Missing , in encoding");
928181643Skmacy		return LDAP_PROTOCOL_ERROR;
929181643Skmacy	}
930181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
931181643Skmacy	  Asn1Error("Error during Reading identifier");
932181643Skmacy		return LDAP_PROTOCOL_ERROR;
933181643Skmacy	}
934181643Skmacy	}
935181643Skmacy	if ( strncmp( peek_head, "thisUpdate", strlen("thisUpdate") ) == 0 ) {
936181643Skmacy		rc = 	GDecComponentTime (mem_op, b, (&k->thisUpdate), bytesDecoded, mode);
937181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
938181643Skmacy	( k->thisUpdate)->identifier.bv_val = peek_head;
939181643Skmacy	( k->thisUpdate)->identifier.bv_len = strLen;
940181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
941181643Skmacy		Asn1Error("Error during Reading , ");
942181643Skmacy		return LDAP_PROTOCOL_ERROR;
943181643Skmacy	}
944181643Skmacy	if(*peek_head != ','){
945181643Skmacy		Asn1Error("Missing , in encoding");
946181643Skmacy		return LDAP_PROTOCOL_ERROR;
947181643Skmacy	}
948181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
949181643Skmacy	  Asn1Error("Error during Reading identifier");
950181643Skmacy		return LDAP_PROTOCOL_ERROR;
951181643Skmacy	}
952181643Skmacy	}
953181643Skmacy	if ( strncmp( peek_head, "nextUpdate", strlen("nextUpdate") ) == 0 ) {
954181643Skmacy		rc = 	GDecComponentTime (mem_op, b, (&k->nextUpdate), bytesDecoded, mode);
955181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
956181643Skmacy	( k->nextUpdate)->identifier.bv_val = peek_head;
957181643Skmacy	( k->nextUpdate)->identifier.bv_len = strLen;
958181805Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
959181643Skmacy		Asn1Error("Error during Reading , ");
960181643Skmacy		return LDAP_PROTOCOL_ERROR;
961181643Skmacy	}
962181643Skmacy	if(*peek_head != ','){
963181643Skmacy		Asn1Error("Missing , in encoding");
964181643Skmacy		return LDAP_PROTOCOL_ERROR;
965181643Skmacy	}
966181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
967181643Skmacy	  Asn1Error("Error during Reading identifier");
968181643Skmacy		return LDAP_PROTOCOL_ERROR;
969181643Skmacy	}
970181643Skmacy	}
971181643Skmacy	if ( strncmp( peek_head, "revokedCertificates", strlen("revokedCertificates") ) == 0 ) {
972181643Skmacy		rc = 	GDecComponentTBSCertListSeqOf (mem_op, b, (&k->revokedCertificates), bytesDecoded, mode);
973181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
974181643Skmacy	( k->revokedCertificates)->identifier.bv_val = peek_head;
975181643Skmacy	( k->revokedCertificates)->identifier.bv_len = strLen;
976181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
977181643Skmacy		Asn1Error("Error during Reading , ");
978181643Skmacy		return LDAP_PROTOCOL_ERROR;
979181643Skmacy	}
980181643Skmacy	if(*peek_head != ','){
981181643Skmacy		Asn1Error("Missing , in encoding");
982181643Skmacy		return LDAP_PROTOCOL_ERROR;
983181643Skmacy	}
984181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
985181643Skmacy	  Asn1Error("Error during Reading identifier");
986181643Skmacy		return LDAP_PROTOCOL_ERROR;
987181643Skmacy	}
988181643Skmacy	}
989181643Skmacy	if ( strncmp( peek_head, "crlExtensions", strlen("crlExtensions") ) == 0 ) {
990181643Skmacy		rc = 	GDecComponentExtensions (mem_op, b, (&k->crlExtensions), bytesDecoded, mode);
991181643Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
992181643Skmacy	( k->crlExtensions)->identifier.bv_val = peek_head;
993181643Skmacy	( k->crlExtensions)->identifier.bv_len = strLen;
994181643Skmacy	}
995181643Skmacy	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
996181643Skmacy		Asn1Error("Error during Reading } in encoding");
997181643Skmacy		return LDAP_PROTOCOL_ERROR;
998181643Skmacy	}
999181643Skmacy	if(*peek_head != '}'){
1000181643Skmacy		Asn1Error("Missing } in encoding");
1001181643Skmacy		return LDAP_PROTOCOL_ERROR;
1002181643Skmacy	}
1003181643Skmacy	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1004181643Skmacy	*v = t = (ComponentTBSCertList*) CompAlloc( mem_op, sizeof(ComponentTBSCertList) );
1005181643Skmacy	if ( !t ) return -1;
1006183375Skmacy	*t = *k;
1007181643Skmacy	}
1008181643Skmacy	t->syntax = (Syntax*)NULL;
1009181643Skmacy	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1010181643Skmacy	if ( !t->comp_desc ) {
1011181643Skmacy		free ( t );
1012186557Skmacy		return -1;
1013181643Skmacy	}
1014181643Skmacy	t->comp_desc->cd_ldap_encoder = (encoder_func*)NULL;
1015181643Skmacy	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
1016181643Skmacy	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
1017181643Skmacy	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertList ;
1018181643Skmacy	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertList ;
1019181643Skmacy	t->comp_desc->cd_free = (comp_free_func*)NULL;
1020181643Skmacy	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertList;
1021181643Skmacy	t->comp_desc->cd_type = ASN_COMPOSITE;
1022181643Skmacy	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1023183375Skmacy	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertList;
1024181643Skmacy	return LDAP_SUCCESS;
1025181643Skmacy}  /* GDecTBSCertList*/
1026181643Skmacy
1027181643Skmacy
1028181643Skmacyint
1029181643SkmacyMatchingComponentCertificateList ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
1030181643Skmacy	int rc;
1031181643Skmacy	MatchingRule* mr;
1032181643Skmacy
1033189699Sdfr	if ( oid ) {
1034189699Sdfr		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
1035189699Sdfr		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
1036181643Skmacy	}
1037181643Skmacy
1038181643Skmacy	rc = 1;
1039181643Skmacy	rc =	MatchingComponentTBSCertList ( oid, (ComponentSyntaxInfo*)((ComponentCertificateList*)csi_attr)->tbsCertList, (ComponentSyntaxInfo*)((ComponentCertificateList*)csi_assert)->tbsCertList );
1040181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
1041181643Skmacy		return rc;
1042181643Skmacy	rc =	MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentCertificateList*)csi_attr)->signatureAlgorithm, (ComponentSyntaxInfo*)((ComponentCertificateList*)csi_assert)->signatureAlgorithm );
1043181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
1044181643Skmacy		return rc;
1045181643Skmacy	rc =	MatchingComponentBits ( oid, (ComponentSyntaxInfo*)&((ComponentCertificateList*)csi_attr)->signature, (ComponentSyntaxInfo*)&((ComponentCertificateList*)csi_assert)->signature );
1046181643Skmacy	if ( rc != LDAP_COMPARE_TRUE )
1047181643Skmacy		return rc;
1048181643Skmacy	return LDAP_COMPARE_TRUE;
1049181643Skmacy}  /* BMatchingComponentCertificateList */
1050181643Skmacy
1051181643Skmacyvoid*
1052181643SkmacyExtractingComponentCertificateList ( void* mem_op, ComponentReference* cr, ComponentCertificateList *comp )
1053181643Skmacy{
1054181643Skmacy
1055181643Skmacy	if ( ( comp->tbsCertList->identifier.bv_val && strncmp(comp->tbsCertList->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->tbsCertList->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
1056181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
1057181643Skmacy			return comp->tbsCertList;
1058181643Skmacy		else {
1059181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
1060181643Skmacy			return 	ExtractingComponentTBSCertList ( mem_op, cr, comp->tbsCertList );
1061181643Skmacy		}
1062181643Skmacy	}
1063181643Skmacy	if ( ( comp->signatureAlgorithm->identifier.bv_val && strncmp(comp->signatureAlgorithm->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signatureAlgorithm->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
1064181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
1065181643Skmacy			return comp->signatureAlgorithm;
1066185605Skmacy		else {
1067181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
1068181643Skmacy			return 	ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signatureAlgorithm );
1069181643Skmacy		}
1070181643Skmacy	}
1071181643Skmacy	if ( ( comp->signature.identifier.bv_val && strncmp(comp->signature.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signature.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
1072181643Skmacy		if ( cr->cr_curr->ci_next == NULL )
1073181643Skmacy		return &comp->signature;
1074181643Skmacy	else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
1075181643Skmacy			cr->cr_curr = cr->cr_curr->ci_next;
1076181643Skmacy		return &comp->signature;
1077185605Skmacy	 } else {
1078181643Skmacy		return NULL;
1079181643Skmacy		}
1080181643Skmacy	}
1081181643Skmacy	return NULL;
1082181643Skmacy}  /* ExtractingComponentCertificateList */
1083181643Skmacy
1084181643Skmacyint
1085181643SkmacyBDecComponentCertificateList PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
1086181643Skmacyvoid* mem_op _AND_
1087181643SkmacyGenBuf * b _AND_
1088181643SkmacyAsnTag tagId0 _AND_
1089181643SkmacyAsnLen elmtLen0 _AND_
1090181643SkmacyComponentCertificateList **v _AND_
1091181643SkmacyAsnLen *bytesDecoded _AND_
1092181643Skmacyint mode)
1093185605Skmacy{
1094185605Skmacy	int seqDone = FALSE;
1095185605Skmacy	AsnLen totalElmtsLen1 = 0;
1096185605Skmacy	AsnLen elmtLen1;
1097185605Skmacy	AsnTag tagId1;
1098185605Skmacy	int mandatoryElmtCount1 = 0;
1099185605Skmacy	int old_mode = mode;
1100189699Sdfr	int rc;
1101185605Skmacy	ComponentCertificateList *k, *t, c_temp;
1102185605Skmacy
1103185605Skmacy
1104185605Skmacy	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1105181643Skmacy		memset(&c_temp,0,sizeof(c_temp));
1106185605Skmacy		 k = &c_temp;
1107185605Skmacy	} else
1108181643Skmacy		 k = t = *v;
1109185605Skmacy	mode = DEC_ALLOC_MODE_2;
1110185605Skmacy    tagId1 = BDecTag (b, &totalElmtsLen1 );
1111185605Skmacy
1112185605Skmacy    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
1113185605Skmacy    {
1114185605Skmacy    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1115185605Skmacy	rc = BDecComponentTBSCertList (mem_op, b, tagId1, elmtLen1, (&k->tbsCertList), &totalElmtsLen1, mode);
1116185605Skmacy		if ( rc != LDAP_SUCCESS ) return rc;
1117181643Skmacy		(k->tbsCertList)->identifier.bv_val = (k->tbsCertList)->id_buf;
1118181643Skmacy		(k->tbsCertList)->identifier.bv_len = strlen("tbsCertList");
1119181643Skmacy		strcpy( (k->tbsCertList)->identifier.bv_val, "tbsCertList");
1120    tagId1 = BDecTag (b, &totalElmtsLen1);
1121    }
1122    else
1123        return -1;
1124
1125
1126
1127    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
1128    {
1129    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1130	rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signatureAlgorithm), &totalElmtsLen1, mode);
1131		if ( rc != LDAP_SUCCESS ) return rc;
1132		(k->signatureAlgorithm)->identifier.bv_val = (k->signatureAlgorithm)->id_buf;
1133		(k->signatureAlgorithm)->identifier.bv_len = strlen("signatureAlgorithm");
1134		strcpy( (k->signatureAlgorithm)->identifier.bv_val, "signatureAlgorithm");
1135    tagId1 = BDecTag (b, &totalElmtsLen1);
1136    }
1137    else
1138        return -1;
1139
1140
1141
1142    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE)) ||
1143(tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE))))
1144    {
1145    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1146	rc = BDecComponentBits (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode);
1147		if ( rc != LDAP_SUCCESS ) return rc;
1148		(&k->signature)->identifier.bv_val = (&k->signature)->id_buf;
1149		(&k->signature)->identifier.bv_len = strlen("signature");
1150		strcpy( (&k->signature)->identifier.bv_val, "signature");
1151        seqDone = TRUE;
1152        if (elmtLen0 == INDEFINITE_LEN)
1153            BDecEoc (b, &totalElmtsLen1 );
1154        else if (totalElmtsLen1 != elmtLen0)
1155        return -1;
1156
1157    }
1158    else
1159        return -1;
1160
1161
1162
1163    if (!seqDone)
1164        return -1;
1165
1166	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1167	*v = t = (ComponentCertificateList*) CompAlloc( mem_op, sizeof(ComponentCertificateList) );
1168	if ( !t ) return -1;
1169	*t = *k;
1170	}
1171	t->syntax = (Syntax*)NULL;
1172	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1173	if ( !t->comp_desc ) {
1174		free ( t );
1175		return -1;
1176	}
1177	t->comp_desc->cd_ldap_encoder = (encoder_func*)NULL;
1178	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
1179	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
1180	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificateList ;
1181	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificateList ;
1182	t->comp_desc->cd_free = (comp_free_func*)NULL;
1183	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificateList;
1184	t->comp_desc->cd_type = ASN_COMPOSITE;
1185	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1186	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificateList;
1187    (*bytesDecoded) += totalElmtsLen1;
1188	return LDAP_SUCCESS;
1189}  /* BDecCertificateList*/
1190
1191int
1192GDecComponentCertificateList PARAMS (( mem_op,b, v, bytesDecoded, mode),
1193void* mem_op _AND_
1194GenBuf * b _AND_
1195ComponentCertificateList **v _AND_
1196AsnLen *bytesDecoded _AND_
1197int mode)
1198{
1199	char* peek_head,*peek_head2;
1200	int i, strLen,strLen2, rc, old_mode = mode;
1201	ComponentCertificateList *k,*t, c_temp;
1202
1203
1204	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1205		memset(&c_temp,0,sizeof(c_temp));
1206		 k = &c_temp;
1207	} else
1208		 k = t = *v;
1209	mode = DEC_ALLOC_MODE_2;
1210	*bytesDecoded = 0;
1211	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1212		Asn1Error("Error during Reading { in encoded data");
1213		return LDAP_PROTOCOL_ERROR;
1214	}
1215	if(*peek_head != '{'){
1216		Asn1Error("Missing { in encoded data");
1217		return LDAP_PROTOCOL_ERROR;
1218	}
1219
1220	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1221		Asn1Error("Error during Reading identifier");
1222		return LDAP_PROTOCOL_ERROR;
1223	}
1224	if ( strncmp( peek_head, "tbsCertList", strlen("tbsCertList") ) == 0 ) {
1225		rc = 	GDecComponentTBSCertList (mem_op, b, (&k->tbsCertList), bytesDecoded, mode);
1226		if ( rc != LDAP_SUCCESS ) return rc;
1227	( k->tbsCertList)->identifier.bv_val = peek_head;
1228	( k->tbsCertList)->identifier.bv_len = strLen;
1229	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1230		Asn1Error("Error during Reading , ");
1231		return LDAP_PROTOCOL_ERROR;
1232	}
1233	if(*peek_head != ','){
1234		Asn1Error("Missing , in encoding");
1235		return LDAP_PROTOCOL_ERROR;
1236	}
1237	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1238	  Asn1Error("Error during Reading identifier");
1239		return LDAP_PROTOCOL_ERROR;
1240	}
1241	}
1242	if ( strncmp( peek_head, "signatureAlgorithm", strlen("signatureAlgorithm") ) == 0 ) {
1243		rc = 	GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signatureAlgorithm), bytesDecoded, mode);
1244		if ( rc != LDAP_SUCCESS ) return rc;
1245	( k->signatureAlgorithm)->identifier.bv_val = peek_head;
1246	( k->signatureAlgorithm)->identifier.bv_len = strLen;
1247	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1248		Asn1Error("Error during Reading , ");
1249		return LDAP_PROTOCOL_ERROR;
1250	}
1251	if(*peek_head != ','){
1252		Asn1Error("Missing , in encoding");
1253		return LDAP_PROTOCOL_ERROR;
1254	}
1255	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1256	  Asn1Error("Error during Reading identifier");
1257		return LDAP_PROTOCOL_ERROR;
1258	}
1259	}
1260	if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) {
1261		rc = 	GDecComponentBits (mem_op, b, (&k->signature), bytesDecoded, mode);
1262		if ( rc != LDAP_SUCCESS ) return rc;
1263	(&k->signature)->identifier.bv_val = peek_head;
1264	(&k->signature)->identifier.bv_len = strLen;
1265	}
1266	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
1267		Asn1Error("Error during Reading } in encoding");
1268		return LDAP_PROTOCOL_ERROR;
1269	}
1270	if(*peek_head != '}'){
1271		Asn1Error("Missing } in encoding");
1272		return LDAP_PROTOCOL_ERROR;
1273	}
1274	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1275	*v = t = (ComponentCertificateList*) CompAlloc( mem_op, sizeof(ComponentCertificateList) );
1276	if ( !t ) return -1;
1277	*t = *k;
1278	}
1279	t->syntax = (Syntax*)NULL;
1280	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1281	if ( !t->comp_desc ) {
1282		free ( t );
1283		return -1;
1284	}
1285	t->comp_desc->cd_ldap_encoder = (encoder_func*)NULL;
1286	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
1287	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
1288	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificateList ;
1289	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificateList ;
1290	t->comp_desc->cd_free = (comp_free_func*)NULL;
1291	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificateList;
1292	t->comp_desc->cd_type = ASN_COMPOSITE;
1293	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1294	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificateList;
1295	return LDAP_SUCCESS;
1296}  /* GDecCertificateList*/
1297