certificate.c revision 1.1
1/*
2 *    certificate.c
3 *    "AuthenticationFramework" ASN.1 module encode/decode/extracting/matching/free C src.
4 *    This file was generated by modified eSMACC compiler Sat Dec 11 11:22:49 2004
5 *    The generated files are supposed to be compiled as a module for OpenLDAP Software
6 */
7
8#include "certificate.h"
9
10BDecComponentCertificateTop( void* mem_op, GenBuf* b, void **v, AsnLen* bytesDecoded,int mode) {
11	AsnTag tag;
12	AsnLen elmtLen;
13
14	tag = BDecTag ( b, bytesDecoded );
15	elmtLen = BDecLen ( b, bytesDecoded );
16	if ( elmtLen <= 0 ) return (-1);
17	if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) {
18		return (-1);
19	}
20
21	return BDecComponentCertificate( mem_op, b, tag, elmtLen, (ComponentCertificate**)v,(AsnLen*)bytesDecoded, mode );
22}
23
24void init_module_AuthenticationFramework() {
25	/* Register Certificate OID and its decoder */
26	InstallOidDecoderMapping( "2.5.4.36", NULL,
27				GDecComponentCertificate,
28				BDecComponentCertificateTop,
29				ExtractingComponentCertificate,
30				MatchingComponentCertificate );
31	InitAnyAuthenticationFramework();
32}
33
34void InitAnyAuthenticationFramework()
35{
36    AsnOid oid0 ={ 9, "\52\206\110\206\367\15\1\1\4" };
37    AsnOid oid1 ={ 9, "\52\206\110\206\367\15\1\1\1" };
38    AsnOid oid2 ={ 9, "\52\206\110\206\367\15\1\1\5" };
39    AsnOid oid3 ={ 3, "\125\4\3" };
40    AsnOid oid4 ={ 3, "\125\4\6" };
41    AsnOid oid5 ={ 3, "\125\4\7" };
42    AsnOid oid6 ={ 3, "\125\4\10" };
43    AsnOid oid7 ={ 3, "\125\4\12" };
44    AsnOid oid8 ={ 3, "\125\4\13" };
45    AsnOid oid9 ={ 10, "\11\222\46\211\223\362\54\144\1\3" };
46    AsnOid oid10 ={ 9, "\52\206\110\206\367\15\1\11\1" };
47    AsnOid oid11 ={ 3, "\125\35\23" };
48    AsnOid oid12 ={ 9, "\140\206\110\1\206\370\102\1\15" };
49    AsnOid oid13 ={ 3, "\125\35\16" };
50    AsnOid oid14 ={ 3, "\125\35\25" };
51    AsnOid oid15 ={ 3, "\125\35\24" };
52    AsnOid oid17 ={ 3, "\125\35\34" };
53
54
55    InstallAnyByComponentOid (nullOid_ANY_ID, &oid0, sizeof (ComponentNull), (EncodeFcn)BEncAsnNull, (gser_decoder_func*)GDecComponentNull, (ber_tag_decoder_func*)BDecComponentNullTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentNull,(FreeFcn)FreeComponentNull, (PrintFcn)NULL);
56
57    InstallAnyByComponentOid (nullOid2_ANY_ID, &oid1, sizeof (ComponentNull), (EncodeFcn)BEncAsnNull, (gser_decoder_func*)GDecComponentNull, (ber_tag_decoder_func*)BDecComponentNullTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentNull,(FreeFcn)FreeComponentNull, (PrintFcn)NULL);
58
59    InstallAnyByComponentOid (nullOid3_ANY_ID, &oid2, sizeof (ComponentNull), (EncodeFcn)BEncAsnNull, (gser_decoder_func*)GDecComponentNull, (ber_tag_decoder_func*)BDecComponentNullTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentNull,(FreeFcn)FreeComponentNull, (PrintFcn)NULL);
60
61    InstallAnyByComponentOid (printableStringOid_ANY_ID, &oid3, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL);
62
63    InstallAnyByComponentOid (printableStringOid2_ANY_ID, &oid4, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL);
64
65    InstallAnyByComponentOid (printableStringOid3_ANY_ID, &oid5, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL);
66
67    InstallAnyByComponentOid (printableStringOid4_ANY_ID, &oid6, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL);
68
69    InstallAnyByComponentOid (printableStringOid5_ANY_ID, &oid7, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL);
70
71    InstallAnyByComponentOid (printableStringOid6_ANY_ID, &oid8, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL);
72
73    InstallAnyByComponentOid (printableStringOid7_ANY_ID, &oid9, sizeof (ComponentTeletexString), (EncodeFcn)BEncTeletexString, (gser_decoder_func*)GDecComponentTeletexString, (ber_tag_decoder_func*)BDecComponentTeletexStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentTeletexString,(FreeFcn)FreeComponentTeletexString, (PrintFcn)NULL);
74
75    InstallAnyByComponentOid (iA5StringOid_ANY_ID, &oid10, sizeof (ComponentIA5String), (EncodeFcn)BEncIA5String, (gser_decoder_func*)GDecComponentIA5String, (ber_tag_decoder_func*)BDecComponentIA5StringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentIA5String,(FreeFcn)FreeComponentIA5String, (PrintFcn)NULL);
76
77    InstallAnyByComponentOid (octetStringOid_ANY_ID, &oid11, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL);
78
79    InstallAnyByComponentOid (octetStringOid2_ANY_ID, &oid12, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL);
80
81    InstallAnyByComponentOid (octetStringOid3_ANY_ID, &oid13, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL);
82
83    InstallAnyByComponentOid (octetStringOid4_ANY_ID, &oid14, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL);
84
85    InstallAnyByComponentOid (octetStringOid5_ANY_ID, &oid15, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL);
86
87    InstallAnyByComponentOid (octetStringOid7_ANY_ID, &oid17, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL);
88
89}  /* InitAnyAuthenticationFramework */
90
91int
92MatchingComponentAlgorithmIdentifier ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
93	int rc;
94	MatchingRule* mr;
95
96	if ( oid ) {
97		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
98		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
99	}
100
101	rc = 1;
102	rc =	MatchingComponentOid ( oid, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_attr)->algorithm, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_assert)->algorithm );
103	if ( rc != LDAP_COMPARE_TRUE )
104		return rc;
105	rc =	SetAnyTypeByComponentOid ((ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_attr)->parameters, (&((ComponentAlgorithmIdentifier*)csi_attr)->algorithm));
106	rc = MatchingComponentAnyDefinedBy ( oid, (ComponentAny*)&((ComponentAlgorithmIdentifier*)csi_attr)->parameters, (ComponentAny*)&((ComponentAlgorithmIdentifier*)csi_assert)->parameters);
107	if ( rc != LDAP_COMPARE_TRUE )
108		return rc;
109	return LDAP_COMPARE_TRUE;
110}  /* BMatchingComponentAlgorithmIdentifier */
111
112void*
113ExtractingComponentAlgorithmIdentifier ( void* mem_op, ComponentReference* cr, ComponentAlgorithmIdentifier *comp )
114{
115
116	if ( ( comp->algorithm.identifier.bv_val && strncmp(comp->algorithm.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->algorithm.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
117		if ( cr->cr_curr->ci_next == NULL )
118		return &comp->algorithm;
119		else
120		return NULL;
121	}
122	if ( ( comp->parameters.identifier.bv_val && strncmp(comp->parameters.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->parameters.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
123		if ( cr->cr_curr->ci_next == NULL )
124		return &comp->parameters;
125	else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
126			cr->cr_curr = cr->cr_curr->ci_next;
127		return &comp->parameters;
128	 } else {
129		return NULL;
130		}
131	}
132	return NULL;
133}  /* ExtractingComponentAlgorithmIdentifier */
134
135int
136BDecComponentAlgorithmIdentifier PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
137void* mem_op _AND_
138GenBuf * b _AND_
139AsnTag tagId0 _AND_
140AsnLen elmtLen0 _AND_
141ComponentAlgorithmIdentifier **v _AND_
142AsnLen *bytesDecoded _AND_
143int mode)
144{
145	int seqDone = FALSE;
146	AsnLen totalElmtsLen1 = 0;
147	AsnLen elmtLen1;
148	AsnTag tagId1;
149	int mandatoryElmtCount1 = 0;
150	int old_mode = mode;
151	int rc;
152	ComponentAlgorithmIdentifier *k, *t, c_temp;
153
154
155	if ( !(mode & DEC_ALLOC_MODE_1) ) {
156		memset(&c_temp,0,sizeof(c_temp));
157		 k = &c_temp;
158	} else
159		 k = t = *v;
160	mode = DEC_ALLOC_MODE_2;
161    tagId1 = BDecTag (b, &totalElmtsLen1 );
162
163    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE))))
164    {
165    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
166	rc = BDecComponentOid (mem_op, b, tagId1, elmtLen1, (&k->algorithm), &totalElmtsLen1, mode);
167		if ( rc != LDAP_SUCCESS ) return rc;
168		(&k->algorithm)->identifier.bv_val = (&k->algorithm)->id_buf;
169		(&k->algorithm)->identifier.bv_len = strlen("algorithm");
170		strcpy( (&k->algorithm)->identifier.bv_val, "algorithm");
171    if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
172        seqDone = TRUE;
173    else
174    {
175         tagId1 = BufPeekByte (b);
176         if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
177        {
178            BDecEoc (b, &totalElmtsLen1 );
179            seqDone = TRUE;
180        }
181    }
182    }
183    else
184        return -1;
185
186
187
188    if (!seqDone)    {
189	rc = SetAnyTypeByComponentOid ((&k->parameters), (&k->algorithm));
190 	rc = BDecComponentAnyDefinedBy (mem_op,b, (&k->parameters), &totalElmtsLen1, mode );
191		if ( rc != LDAP_SUCCESS ) return rc;
192		(&k->parameters)->identifier.bv_val = (&k->parameters)->id_buf;
193		(&k->parameters)->identifier.bv_len = strlen("parameters");
194		strcpy( (&k->parameters)->identifier.bv_val, "parameters");
195        seqDone = TRUE;
196        if (elmtLen0 == INDEFINITE_LEN)
197            BDecEoc (b, &totalElmtsLen1 );
198        else if (totalElmtsLen1 != elmtLen0)
199        return -1;
200
201    }
202
203
204    if (!seqDone)
205        return -1;
206
207	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
208	*v = t = (ComponentAlgorithmIdentifier*) CompAlloc( mem_op, sizeof(ComponentAlgorithmIdentifier) );
209	if ( !t ) return -1;
210	*t = *k;
211	}
212	t->syntax = (Syntax*)NULL;
213	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
214	if ( !t->comp_desc ) {
215		free ( t );
216		return -1;
217	}
218	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAlgorithmIdentifier ;
219	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAlgorithmIdentifier ;
220	t->comp_desc->cd_free = (comp_free_func*)NULL;
221	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAlgorithmIdentifier;
222	t->comp_desc->cd_type = ASN_COMPOSITE;
223	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
224	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAlgorithmIdentifier;
225    (*bytesDecoded) += totalElmtsLen1;
226	return LDAP_SUCCESS;
227}  /* BDecAlgorithmIdentifier*/
228
229int
230GDecComponentAlgorithmIdentifier PARAMS (( mem_op,b, v, bytesDecoded, mode),
231void* mem_op _AND_
232GenBuf * b _AND_
233ComponentAlgorithmIdentifier **v _AND_
234AsnLen *bytesDecoded _AND_
235int mode)
236{
237	char* peek_head,*peek_head2;
238	int i, strLen,strLen2, rc, old_mode = mode;
239	ComponentAlgorithmIdentifier *k,*t, c_temp;
240
241
242	if ( !(mode & DEC_ALLOC_MODE_1) ) {
243		memset(&c_temp,0,sizeof(c_temp));
244		 k = &c_temp;
245	} else
246		 k = t = *v;
247	mode = DEC_ALLOC_MODE_2;
248	*bytesDecoded = 0;
249	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
250		Asn1Error("Error during Reading { in encoded data");
251		return LDAP_PROTOCOL_ERROR;
252	}
253	if(*peek_head != '{'){
254		Asn1Error("Missing { in encoded data");
255		return LDAP_PROTOCOL_ERROR;
256	}
257
258	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
259		Asn1Error("Error during Reading identifier");
260		return LDAP_PROTOCOL_ERROR;
261	}
262	if ( strncmp( peek_head, "algorithm", strlen("algorithm") ) == 0 ) {
263		rc = 	GDecComponentOid (mem_op, b, (&k->algorithm), bytesDecoded, mode);
264		if ( rc != LDAP_SUCCESS ) return rc;
265	(&k->algorithm)->identifier.bv_val = peek_head;
266	(&k->algorithm)->identifier.bv_len = strLen;
267	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
268		Asn1Error("Error during Reading , ");
269		return LDAP_PROTOCOL_ERROR;
270	}
271	if(*peek_head != ','){
272		Asn1Error("Missing , in encoding");
273		return LDAP_PROTOCOL_ERROR;
274	}
275	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
276	  Asn1Error("Error during Reading identifier");
277		return LDAP_PROTOCOL_ERROR;
278	}
279	}
280	if ( strncmp( peek_head, "parameters", strlen("parameters") ) == 0 ) {
281		rc = 	rc = SetAnyTypeByComponentOid ((&k->parameters), (&k->algorithm));
282	rc = GDecComponentAnyDefinedBy (mem_op, b, (&k->parameters), bytesDecoded, mode );
283		if ( rc != LDAP_SUCCESS ) return rc;
284	(&k->parameters)->identifier.bv_val = peek_head;
285	(&k->parameters)->identifier.bv_len = strLen;
286	}
287	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
288		Asn1Error("Error during Reading } in encoding");
289		return LDAP_PROTOCOL_ERROR;
290	}
291	if(*peek_head != '}'){
292		Asn1Error("Missing } in encoding");
293		return LDAP_PROTOCOL_ERROR;
294	}
295	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
296	*v = t = (ComponentAlgorithmIdentifier*) CompAlloc( mem_op, sizeof(ComponentAlgorithmIdentifier) );
297	if ( !t ) return -1;
298	*t = *k;
299	}
300	t->syntax = (Syntax*)NULL;
301	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
302	if ( !t->comp_desc ) {
303		free ( t );
304		return -1;
305	}
306	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAlgorithmIdentifier ;
307	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAlgorithmIdentifier ;
308	t->comp_desc->cd_free = (comp_free_func*)NULL;
309	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAlgorithmIdentifier;
310	t->comp_desc->cd_type = ASN_COMPOSITE;
311	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
312	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAlgorithmIdentifier;
313	return LDAP_SUCCESS;
314}  /* GDecAlgorithmIdentifier*/
315
316
317int
318MatchingComponentTime ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
319	int rc;
320	MatchingRule* mr;
321	ComponentTime *v1, *v2;
322
323
324	v1 = (ComponentTime*)csi_attr;
325	v2 = (ComponentTime*)csi_assert;
326	if ( oid ) {
327		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
328		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
329	}
330
331	if( (v1->choiceId != v2->choiceId ) )
332		return LDAP_COMPARE_FALSE;
333	switch( v1->choiceId )
334	{
335	   case TIME_UTCTIME :
336		rc = 	MatchingComponentUTCTime ( oid, (ComponentSyntaxInfo*)(v1->a.utcTime), (ComponentSyntaxInfo*)(v2->a.utcTime) );
337		break;
338	   case TIME_GENERALIZEDTIME :
339		rc = 	MatchingComponentGeneralizedTime ( oid, (ComponentSyntaxInfo*)(v1->a.generalizedTime), (ComponentSyntaxInfo*)(v2->a.generalizedTime) );
340		break;
341	default :
342		 return LDAP_PROTOCOL_ERROR;
343	}
344	return rc;
345}  /* BMatchingComponentTimeContent */
346
347void*
348ExtractingComponentTime ( void* mem_op, ComponentReference* cr, ComponentTime *comp )
349{
350
351
352	if( (comp->choiceId) ==  TIME_UTCTIME &&
353		 (( comp->a.utcTime->identifier.bv_val && strncmp(comp->a.utcTime->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) ||
354		 ( strncmp(comp->a.utcTime->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) {
355		if ( cr->cr_curr->ci_next == NULL )
356			return (comp->a.utcTime);
357		else {
358			cr->cr_curr = cr->cr_curr->ci_next;
359			return 	ExtractingComponentUTCTime ( mem_op, cr, (comp->a.utcTime) );
360		};
361	}
362	if( (comp->choiceId) ==  TIME_GENERALIZEDTIME &&
363		 (( comp->a.generalizedTime->identifier.bv_val && strncmp(comp->a.generalizedTime->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) ||
364		 ( strncmp(comp->a.generalizedTime->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) {
365		if ( cr->cr_curr->ci_next == NULL )
366			return (comp->a.generalizedTime);
367		else {
368			cr->cr_curr = cr->cr_curr->ci_next;
369			return 	ExtractingComponentGeneralizedTime ( mem_op, cr, (comp->a.generalizedTime) );
370		};
371	}
372	return NULL;
373}  /* ExtractingComponentTime */
374
375int
376BDecComponentTime PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
377void* mem_op _AND_
378GenBuf * b _AND_
379AsnTag tagId0 _AND_
380AsnLen elmtLen0 _AND_
381ComponentTime **v _AND_
382AsnLen *bytesDecoded _AND_
383int mode)
384{
385	int seqDone = FALSE;
386	AsnLen totalElmtsLen1 = 0;
387	AsnLen elmtLen1;
388	AsnTag tagId1;
389	int mandatoryElmtCount1 = 0;
390	int old_mode = mode;
391	int rc;
392	ComponentTime *k, *t, c_temp;
393
394
395	if ( !(mode & DEC_ALLOC_MODE_1) ) {
396		memset(&c_temp,0,sizeof(c_temp));
397		 k = &c_temp;
398	} else
399		 k = t = *v;
400	mode = DEC_ALLOC_MODE_2;
401    switch (tagId0)
402    {
403       case MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE):
404       case MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE):
405        (k->choiceId) = TIME_UTCTIME;
406	rc = BDecComponentUTCTime (mem_op, b, tagId0, elmtLen0, (&k->a.utcTime), &totalElmtsLen1, DEC_ALLOC_MODE_0 );
407		if ( rc != LDAP_SUCCESS ) return rc;
408		(k->a.utcTime)->identifier.bv_val = (k->a.utcTime)->id_buf;
409		(k->a.utcTime)->identifier.bv_len = strlen("utcTime");
410		strcpy( (k->a.utcTime)->identifier.bv_val, "utcTime");
411    break;
412
413       case MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE):
414       case MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE):
415        (k->choiceId) = TIME_GENERALIZEDTIME;
416	rc = BDecComponentGeneralizedTime (mem_op, b, tagId0, elmtLen0, (&k->a.generalizedTime), &totalElmtsLen1, DEC_ALLOC_MODE_0 );
417		if ( rc != LDAP_SUCCESS ) return rc;
418		(k->a.generalizedTime)->identifier.bv_val = (k->a.generalizedTime)->id_buf;
419		(k->a.generalizedTime)->identifier.bv_len = strlen("generalizedTime");
420		strcpy( (k->a.generalizedTime)->identifier.bv_val, "generalizedTime");
421    break;
422
423    default:
424        Asn1Error ("ERROR - unexpected tag in CHOICE\n");
425        return -1;
426        break;
427    } /* end switch */
428	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
429	*v = t = (ComponentTime*) CompAlloc( mem_op, sizeof(ComponentTime) );
430	if ( !t ) return -1;
431	*t = *k;
432	}
433	t->syntax = (Syntax*)NULL;
434	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
435	if ( !t->comp_desc ) {
436		free ( t );
437		return -1;
438	}
439	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTime ;
440	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTime ;
441	t->comp_desc->cd_free = (comp_free_func*)NULL;
442	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTime;
443	t->comp_desc->cd_type = ASN_COMPOSITE;
444	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
445	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTime;
446    (*bytesDecoded) += totalElmtsLen1;
447	return LDAP_SUCCESS;
448}  /* BDecTimeContent */
449
450int
451GDecComponentTime PARAMS (( mem_op,b, v, bytesDecoded, mode),
452void* mem_op _AND_
453GenBuf * b _AND_
454ComponentTime **v _AND_
455AsnLen *bytesDecoded _AND_
456int mode)
457{
458	char* peek_head,*peek_head2;
459	int i, strLen,strLen2, rc, old_mode = mode;
460	ComponentTime *k,*t, c_temp;
461
462
463	if ( !(mode & DEC_ALLOC_MODE_1) ) {
464		memset(&c_temp,0,sizeof(c_temp));
465		 k = &c_temp;
466	} else
467		 k = t = *v;
468	mode = DEC_ALLOC_MODE_2;
469	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
470		Asn1Error("Error during Reading identifier");
471		return LDAP_PROTOCOL_ERROR;
472	}
473	if( !(strLen2 = LocateNextGSERToken(mem_op,b,&peek_head2,GSER_NO_COPY)) ){
474		Asn1Error("Error during Reading identifier");
475		return LDAP_PROTOCOL_ERROR;
476	}
477	if(*peek_head2 != ':'){
478		Asn1Error("Missing : in encoded data");
479		return LDAP_PROTOCOL_ERROR;
480	}
481	if( strncmp("utcTime",peek_head, strlen("utcTime")) == 0){
482		(k->choiceId) = TIME_UTCTIME;
483		rc = 	GDecComponentUTCTime (mem_op, b, (&k->a.utcTime), bytesDecoded, DEC_ALLOC_MODE_0 );
484		if ( rc != LDAP_SUCCESS ) return rc;
485		(k->a.utcTime)->identifier.bv_val = peek_head;
486		(k->a.utcTime)->identifier.bv_len = strLen;
487	}
488	else if( strncmp("generalizedTime",peek_head,strlen("generalizedTime")) == 0){
489		(k->choiceId) = TIME_GENERALIZEDTIME;
490		rc = 	GDecComponentGeneralizedTime (mem_op, b, (&k->a.generalizedTime), bytesDecoded, DEC_ALLOC_MODE_0 );
491		if ( rc != LDAP_SUCCESS ) return rc;
492		(k->a.generalizedTime)->identifier.bv_val = peek_head;
493		(k->a.generalizedTime)->identifier.bv_len = strLen;
494	}
495	else {
496		Asn1Error("Undefined Identifier");
497		return LDAP_PROTOCOL_ERROR;
498	}
499	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
500	*v = t = (ComponentTime*) CompAlloc( mem_op, sizeof(ComponentTime) );
501	if ( !t ) return -1;
502	*t = *k;
503	}
504	t->syntax = (Syntax*)NULL;
505	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
506	if ( !t->comp_desc ) {
507		free ( t );
508		return -1;
509	}
510	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTime ;
511	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTime ;
512	t->comp_desc->cd_free = (comp_free_func*)NULL;
513	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTime;
514	t->comp_desc->cd_type = ASN_COMPOSITE;
515	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
516	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTime;
517	return LDAP_SUCCESS;
518}  /* GDecTimeContent */
519
520
521int
522MatchingComponentExtension ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
523	int rc;
524	MatchingRule* mr;
525
526	if ( oid ) {
527		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
528		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
529	}
530
531	rc = 1;
532	rc =	MatchingComponentOid ( oid, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_attr)->extnID, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_assert)->extnID );
533	if ( rc != LDAP_COMPARE_TRUE )
534		return rc;
535	rc =	MatchingComponentBool ( oid, (ComponentSyntaxInfo*)((ComponentExtension*)csi_attr)->critical, (ComponentSyntaxInfo*)((ComponentExtension*)csi_assert)->critical );
536	if ( rc != LDAP_COMPARE_TRUE )
537		return rc;
538	rc =	MatchingComponentOcts ( oid, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_attr)->extnValue, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_assert)->extnValue );
539	if ( rc != LDAP_COMPARE_TRUE )
540		return rc;
541	return LDAP_COMPARE_TRUE;
542}  /* BMatchingComponentExtension */
543
544void*
545ExtractingComponentExtension ( void* mem_op, ComponentReference* cr, ComponentExtension *comp )
546{
547
548	if ( ( comp->extnID.identifier.bv_val && strncmp(comp->extnID.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extnID.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
549		if ( cr->cr_curr->ci_next == NULL )
550		return &comp->extnID;
551		else
552		return NULL;
553	}
554	if ( ( comp->critical->identifier.bv_val && strncmp(comp->critical->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->critical->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
555		if ( cr->cr_curr->ci_next == NULL )
556			return comp->critical;
557		else {
558			cr->cr_curr = cr->cr_curr->ci_next;
559			return 	ExtractingComponentBool ( mem_op, cr, comp->critical );
560		}
561	}
562	if ( ( comp->extnValue.identifier.bv_val && strncmp(comp->extnValue.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extnValue.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
563		if ( cr->cr_curr->ci_next == NULL )
564		return &comp->extnValue;
565	else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
566			cr->cr_curr = cr->cr_curr->ci_next;
567		return &comp->extnValue;
568	 } else {
569		return NULL;
570		}
571	}
572	return NULL;
573}  /* ExtractingComponentExtension */
574
575int
576BDecComponentExtension PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
577void* mem_op _AND_
578GenBuf * b _AND_
579AsnTag tagId0 _AND_
580AsnLen elmtLen0 _AND_
581ComponentExtension **v _AND_
582AsnLen *bytesDecoded _AND_
583int mode)
584{
585	int seqDone = FALSE;
586	AsnLen totalElmtsLen1 = 0;
587	AsnLen elmtLen1;
588	AsnTag tagId1;
589	int mandatoryElmtCount1 = 0;
590	int old_mode = mode;
591	int rc;
592	ComponentExtension *k, *t, c_temp;
593
594
595	if ( !(mode & DEC_ALLOC_MODE_1) ) {
596		memset(&c_temp,0,sizeof(c_temp));
597		 k = &c_temp;
598	} else
599		 k = t = *v;
600	mode = DEC_ALLOC_MODE_2;
601    tagId1 = BDecTag (b, &totalElmtsLen1 );
602
603    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE))))
604    {
605    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
606	rc = BDecComponentOid (mem_op, b, tagId1, elmtLen1, (&k->extnID), &totalElmtsLen1, mode);
607		if ( rc != LDAP_SUCCESS ) return rc;
608		(&k->extnID)->identifier.bv_val = (&k->extnID)->id_buf;
609		(&k->extnID)->identifier.bv_len = strlen("extnID");
610		strcpy( (&k->extnID)->identifier.bv_val, "extnID");
611    tagId1 = BDecTag (b, &totalElmtsLen1);
612    }
613    else
614        return -1;
615
616
617
618    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BOOLEAN_TAG_CODE))))
619    {
620    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
621	rc = BDecComponentBool (mem_op, b, tagId1, elmtLen1, (&k->critical), &totalElmtsLen1, DEC_ALLOC_MODE_0 );
622		if ( rc != LDAP_SUCCESS ) return rc;
623		(k->critical)->identifier.bv_val = (k->critical)->id_buf;
624		(k->critical)->identifier.bv_len = strlen("critical");
625		strcpy( (k->critical)->identifier.bv_val, "critical");
626    tagId1 = BDecTag (b, &totalElmtsLen1);
627    }
628
629
630    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE)) ||
631(tagId1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE))))
632    {
633    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
634	rc = BDecComponentOcts (mem_op, b, tagId1, elmtLen1, (&k->extnValue), &totalElmtsLen1, mode);
635		if ( rc != LDAP_SUCCESS ) return rc;
636		(&k->extnValue)->identifier.bv_val = (&k->extnValue)->id_buf;
637		(&k->extnValue)->identifier.bv_len = strlen("extnValue");
638		strcpy( (&k->extnValue)->identifier.bv_val, "extnValue");
639        seqDone = TRUE;
640        if (elmtLen0 == INDEFINITE_LEN)
641            BDecEoc (b, &totalElmtsLen1 );
642        else if (totalElmtsLen1 != elmtLen0)
643        return -1;
644
645    }
646    else
647        return -1;
648
649
650
651    if (!seqDone)
652        return -1;
653
654	if(!COMPONENTNOT_NULL ((k->critical)))
655	{
656(k->critical) = CompAlloc( mem_op, sizeof(ComponentBool));
657		(k->critical)->identifier.bv_val = (k->critical)->id_buf;
658		(k->critical)->identifier.bv_len = strlen("critical");
659		strcpy( (k->critical)->identifier.bv_val, "critical");
660	(k->critical)->value = 0;
661	}
662	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
663	*v = t = (ComponentExtension*) CompAlloc( mem_op, sizeof(ComponentExtension) );
664	if ( !t ) return -1;
665	*t = *k;
666	}
667	t->syntax = (Syntax*)NULL;
668	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
669	if ( !t->comp_desc ) {
670		free ( t );
671		return -1;
672	}
673	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtension ;
674	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtension ;
675	t->comp_desc->cd_free = (comp_free_func*)NULL;
676	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtension;
677	t->comp_desc->cd_type = ASN_COMPOSITE;
678	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
679	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtension;
680    (*bytesDecoded) += totalElmtsLen1;
681	return LDAP_SUCCESS;
682}  /* BDecExtension*/
683
684int
685GDecComponentExtension PARAMS (( mem_op,b, v, bytesDecoded, mode),
686void* mem_op _AND_
687GenBuf * b _AND_
688ComponentExtension **v _AND_
689AsnLen *bytesDecoded _AND_
690int mode)
691{
692	char* peek_head,*peek_head2;
693	int i, strLen,strLen2, rc, old_mode = mode;
694	ComponentExtension *k,*t, c_temp;
695
696
697	if ( !(mode & DEC_ALLOC_MODE_1) ) {
698		memset(&c_temp,0,sizeof(c_temp));
699		 k = &c_temp;
700	} else
701		 k = t = *v;
702	mode = DEC_ALLOC_MODE_2;
703	*bytesDecoded = 0;
704	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
705		Asn1Error("Error during Reading { in encoded data");
706		return LDAP_PROTOCOL_ERROR;
707	}
708	if(*peek_head != '{'){
709		Asn1Error("Missing { in encoded data");
710		return LDAP_PROTOCOL_ERROR;
711	}
712
713	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
714		Asn1Error("Error during Reading identifier");
715		return LDAP_PROTOCOL_ERROR;
716	}
717	if ( strncmp( peek_head, "extnID", strlen("extnID") ) == 0 ) {
718		rc = 	GDecComponentOid (mem_op, b, (&k->extnID), bytesDecoded, mode);
719		if ( rc != LDAP_SUCCESS ) return rc;
720	(&k->extnID)->identifier.bv_val = peek_head;
721	(&k->extnID)->identifier.bv_len = strLen;
722	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
723		Asn1Error("Error during Reading , ");
724		return LDAP_PROTOCOL_ERROR;
725	}
726	if(*peek_head != ','){
727		Asn1Error("Missing , in encoding");
728		return LDAP_PROTOCOL_ERROR;
729	}
730	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
731	  Asn1Error("Error during Reading identifier");
732		return LDAP_PROTOCOL_ERROR;
733	}
734	}
735	if ( strncmp( peek_head, "critical", strlen("critical") ) == 0 ) {
736		rc = 	GDecComponentBool (mem_op, b, (&k->critical), bytesDecoded, DEC_ALLOC_MODE_0 );
737		if ( rc != LDAP_SUCCESS ) return rc;
738	( k->critical)->identifier.bv_val = peek_head;
739	( k->critical)->identifier.bv_len = strLen;
740	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
741		Asn1Error("Error during Reading , ");
742		return LDAP_PROTOCOL_ERROR;
743	}
744	if(*peek_head != ','){
745		Asn1Error("Missing , in encoding");
746		return LDAP_PROTOCOL_ERROR;
747	}
748	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
749	  Asn1Error("Error during Reading identifier");
750		return LDAP_PROTOCOL_ERROR;
751	}
752	}
753	else {
754(k->critical) = CompAlloc( mem_op, sizeof(ComponentBool));
755			(k->critical)->value = 0;
756	}
757	if ( strncmp( peek_head, "extnValue", strlen("extnValue") ) == 0 ) {
758		rc = 	GDecComponentOcts (mem_op, b, (&k->extnValue), bytesDecoded, mode);
759		if ( rc != LDAP_SUCCESS ) return rc;
760	(&k->extnValue)->identifier.bv_val = peek_head;
761	(&k->extnValue)->identifier.bv_len = strLen;
762	}
763	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
764		Asn1Error("Error during Reading } in encoding");
765		return LDAP_PROTOCOL_ERROR;
766	}
767	if(*peek_head != '}'){
768		Asn1Error("Missing } in encoding");
769		return LDAP_PROTOCOL_ERROR;
770	}
771	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
772	*v = t = (ComponentExtension*) CompAlloc( mem_op, sizeof(ComponentExtension) );
773	if ( !t ) return -1;
774	*t = *k;
775	}
776	t->syntax = (Syntax*)NULL;
777	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
778	if ( !t->comp_desc ) {
779		free ( t );
780		return -1;
781	}
782	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtension ;
783	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtension ;
784	t->comp_desc->cd_free = (comp_free_func*)NULL;
785	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtension;
786	t->comp_desc->cd_type = ASN_COMPOSITE;
787	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
788	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtension;
789	return LDAP_SUCCESS;
790}  /* GDecExtension*/
791
792
793int
794MatchingComponentAttributeTypeAndValue ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
795	int rc;
796	MatchingRule* mr;
797
798	if ( oid ) {
799		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
800		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
801	}
802
803	rc = 1;
804	rc =	MatchingComponentAttributeType ( oid, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_attr)->type, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_assert)->type );
805	if ( rc != LDAP_COMPARE_TRUE )
806		return rc;
807	rc =	SetAnyTypeByComponentOid ((ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_attr)->value, (&((ComponentAttributeTypeAndValue*)csi_attr)->type));
808	rc = MatchingComponentAnyDefinedBy ( oid, (ComponentAny*)&((ComponentAttributeTypeAndValue*)csi_attr)->value, (ComponentAny*)&((ComponentAttributeTypeAndValue*)csi_assert)->value);
809	if ( rc != LDAP_COMPARE_TRUE )
810		return rc;
811	return LDAP_COMPARE_TRUE;
812}  /* BMatchingComponentAttributeTypeAndValue */
813
814void*
815ExtractingComponentAttributeTypeAndValue ( void* mem_op, ComponentReference* cr, ComponentAttributeTypeAndValue *comp )
816{
817
818	if ( ( comp->type.identifier.bv_val && strncmp(comp->type.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->type.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
819		if ( cr->cr_curr->ci_next == NULL )
820		return &comp->type;
821		else
822		return NULL;
823	}
824	if ( ( comp->value.identifier.bv_val && strncmp(comp->value.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->value.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
825		if ( cr->cr_curr->ci_next == NULL )
826		return &comp->value;
827		else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_SELECT ) {
828			cr->cr_curr = cr->cr_curr->ci_next;
829			return &comp->value;
830	 } else {
831		return NULL;
832		}
833	}
834	return NULL;
835}  /* ExtractingComponentAttributeTypeAndValue */
836
837int
838BDecComponentAttributeTypeAndValue PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
839void* mem_op _AND_
840GenBuf * b _AND_
841AsnTag tagId0 _AND_
842AsnLen elmtLen0 _AND_
843ComponentAttributeTypeAndValue **v _AND_
844AsnLen *bytesDecoded _AND_
845int mode)
846{
847	int seqDone = FALSE;
848	AsnLen totalElmtsLen1 = 0;
849	AsnLen elmtLen1;
850	AsnTag tagId1;
851	int mandatoryElmtCount1 = 0;
852	int old_mode = mode;
853	int rc;
854	ComponentAttributeTypeAndValue *k, *t, c_temp;
855
856
857	if ( !(mode & DEC_ALLOC_MODE_1) ) {
858		memset(&c_temp,0,sizeof(c_temp));
859		 k = &c_temp;
860	} else
861		 k = t = *v;
862	mode = DEC_ALLOC_MODE_2;
863    tagId1 = BDecTag (b, &totalElmtsLen1 );
864
865    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE))))
866    {
867    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
868	rc = BDecComponentAttributeType (mem_op, b, tagId1, elmtLen1, (&k->type), &totalElmtsLen1, mode);
869		if ( rc != LDAP_SUCCESS ) return rc;
870		(&k->type)->identifier.bv_val = (&k->type)->id_buf;
871		(&k->type)->identifier.bv_len = strlen("type");
872		strcpy( (&k->type)->identifier.bv_val, "type");
873    }
874    else
875        return -1;
876
877
878
879    {
880	rc = SetAnyTypeByComponentOid ((&k->value), (&k->type));
881 	rc = BDecComponentAnyDefinedBy (mem_op,b, (&k->value), &totalElmtsLen1, mode );
882		if ( rc != LDAP_SUCCESS ) return rc;
883		(&k->value)->identifier.bv_val = (&k->value)->id_buf;
884		(&k->value)->identifier.bv_len = strlen("value");
885		strcpy( (&k->value)->identifier.bv_val, "value");
886        seqDone = TRUE;
887        if (elmtLen0 == INDEFINITE_LEN)
888            BDecEoc (b, &totalElmtsLen1 );
889        else if (totalElmtsLen1 != elmtLen0)
890        return -1;
891
892    }
893
894
895    if (!seqDone)
896        return -1;
897
898	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
899	*v = t = (ComponentAttributeTypeAndValue*) CompAlloc( mem_op, sizeof(ComponentAttributeTypeAndValue) );
900	if ( !t ) return -1;
901	*t = *k;
902	}
903	t->syntax = (Syntax*)NULL;
904	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
905	if ( !t->comp_desc ) {
906		free ( t );
907		return -1;
908	}
909	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAttributeTypeAndValue ;
910	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAttributeTypeAndValue ;
911	t->comp_desc->cd_free = (comp_free_func*)NULL;
912	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAttributeTypeAndValue;
913	t->comp_desc->cd_type = ASN_COMPOSITE;
914	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
915	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAttributeTypeAndValue;
916    (*bytesDecoded) += totalElmtsLen1;
917	return LDAP_SUCCESS;
918}  /* BDecAttributeTypeAndValue*/
919
920int
921GDecComponentAttributeTypeAndValue PARAMS (( mem_op,b, v, bytesDecoded, mode),
922void* mem_op _AND_
923GenBuf * b _AND_
924ComponentAttributeTypeAndValue **v _AND_
925AsnLen *bytesDecoded _AND_
926int mode)
927{
928	char* peek_head,*peek_head2;
929	int i, strLen,strLen2, rc, old_mode = mode;
930	ComponentAttributeTypeAndValue *k,*t, c_temp;
931
932
933	if ( !(mode & DEC_ALLOC_MODE_1) ) {
934		memset(&c_temp,0,sizeof(c_temp));
935		 k = &c_temp;
936	} else
937		 k = t = *v;
938	mode = DEC_ALLOC_MODE_2;
939	*bytesDecoded = 0;
940	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
941		Asn1Error("Error during Reading { in encoded data");
942		return LDAP_PROTOCOL_ERROR;
943	}
944	if(*peek_head != '{'){
945		Asn1Error("Missing { in encoded data");
946		return LDAP_PROTOCOL_ERROR;
947	}
948
949	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
950		Asn1Error("Error during Reading identifier");
951		return LDAP_PROTOCOL_ERROR;
952	}
953	if ( strncmp( peek_head, "type", strlen("type") ) == 0 ) {
954		rc = 	GDecComponentAttributeType (mem_op, b, (&k->type), bytesDecoded, mode);
955		if ( rc != LDAP_SUCCESS ) return rc;
956	(&k->type)->identifier.bv_val = peek_head;
957	(&k->type)->identifier.bv_len = strLen;
958	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
959		Asn1Error("Error during Reading , ");
960		return LDAP_PROTOCOL_ERROR;
961	}
962	if(*peek_head != ','){
963		Asn1Error("Missing , in encoding");
964		return LDAP_PROTOCOL_ERROR;
965	}
966	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
967	  Asn1Error("Error during Reading identifier");
968		return LDAP_PROTOCOL_ERROR;
969	}
970	}
971	if ( strncmp( peek_head, "value", strlen("value") ) == 0 ) {
972		rc = 	rc = SetAnyTypeByComponentOid ((&k->value), (&k->type));
973	rc = GDecComponentAnyDefinedBy (mem_op, b, (&k->value), bytesDecoded, mode );
974		if ( rc != LDAP_SUCCESS ) return rc;
975	(&k->value)->identifier.bv_val = peek_head;
976	(&k->value)->identifier.bv_len = strLen;
977	}
978	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
979		Asn1Error("Error during Reading } in encoding");
980		return LDAP_PROTOCOL_ERROR;
981	}
982	if(*peek_head != '}'){
983		Asn1Error("Missing } in encoding");
984		return LDAP_PROTOCOL_ERROR;
985	}
986	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
987	*v = t = (ComponentAttributeTypeAndValue*) CompAlloc( mem_op, sizeof(ComponentAttributeTypeAndValue) );
988	if ( !t ) return -1;
989	*t = *k;
990	}
991	t->syntax = (Syntax*)NULL;
992	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
993	if ( !t->comp_desc ) {
994		free ( t );
995		return -1;
996	}
997	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAttributeTypeAndValue ;
998	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAttributeTypeAndValue ;
999	t->comp_desc->cd_free = (comp_free_func*)NULL;
1000	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAttributeTypeAndValue;
1001	t->comp_desc->cd_type = ASN_COMPOSITE;
1002	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1003	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAttributeTypeAndValue;
1004	return LDAP_SUCCESS;
1005}  /* GDecAttributeTypeAndValue*/
1006
1007
1008int
1009MatchingComponentValidity ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
1010	int rc;
1011	MatchingRule* mr;
1012
1013	if ( oid ) {
1014		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
1015		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
1016	}
1017
1018	rc = 1;
1019	rc =	MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentValidity*)csi_attr)->notBefore, (ComponentSyntaxInfo*)((ComponentValidity*)csi_assert)->notBefore );
1020	if ( rc != LDAP_COMPARE_TRUE )
1021		return rc;
1022	rc =	MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentValidity*)csi_attr)->notAfter, (ComponentSyntaxInfo*)((ComponentValidity*)csi_assert)->notAfter );
1023	if ( rc != LDAP_COMPARE_TRUE )
1024		return rc;
1025	return LDAP_COMPARE_TRUE;
1026}  /* BMatchingComponentValidity */
1027
1028void*
1029ExtractingComponentValidity ( void* mem_op, ComponentReference* cr, ComponentValidity *comp )
1030{
1031
1032	if ( ( comp->notBefore->identifier.bv_val && strncmp(comp->notBefore->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->notBefore->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
1033		if ( cr->cr_curr->ci_next == NULL )
1034			return comp->notBefore;
1035		else {
1036			cr->cr_curr = cr->cr_curr->ci_next;
1037			return 	ExtractingComponentTime ( mem_op, cr, comp->notBefore );
1038		}
1039	}
1040	if ( ( comp->notAfter->identifier.bv_val && strncmp(comp->notAfter->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->notAfter->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
1041		if ( cr->cr_curr->ci_next == NULL )
1042			return comp->notAfter;
1043		else {
1044			cr->cr_curr = cr->cr_curr->ci_next;
1045			return 	ExtractingComponentTime ( mem_op, cr, comp->notAfter );
1046		}
1047	}
1048	return NULL;
1049}  /* ExtractingComponentValidity */
1050
1051int
1052BDecComponentValidity PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
1053void* mem_op _AND_
1054GenBuf * b _AND_
1055AsnTag tagId0 _AND_
1056AsnLen elmtLen0 _AND_
1057ComponentValidity **v _AND_
1058AsnLen *bytesDecoded _AND_
1059int mode)
1060{
1061	int seqDone = FALSE;
1062	AsnLen totalElmtsLen1 = 0;
1063	AsnLen elmtLen1;
1064	AsnTag tagId1;
1065	int mandatoryElmtCount1 = 0;
1066	AsnLen totalElmtsLen2 = 0;
1067	AsnLen elmtLen2;
1068	AsnTag tagId2;
1069	int old_mode = mode;
1070	int rc;
1071	ComponentValidity *k, *t, c_temp;
1072
1073
1074	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1075		memset(&c_temp,0,sizeof(c_temp));
1076		 k = &c_temp;
1077	} else
1078		 k = t = *v;
1079	mode = DEC_ALLOC_MODE_2;
1080    tagId1 = BDecTag (b, &totalElmtsLen1 );
1081
1082    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) ||
1083(tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) ||
1084     (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))||
1085    (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE))))
1086    {
1087        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1088	rc = BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->notBefore), &totalElmtsLen1, mode);
1089		if ( rc != LDAP_SUCCESS ) return rc;
1090		(k->notBefore)->identifier.bv_val = (k->notBefore)->id_buf;
1091		(k->notBefore)->identifier.bv_len = strlen("notBefore");
1092		strcpy( (k->notBefore)->identifier.bv_val, "notBefore");
1093    tagId1 = BDecTag (b, &totalElmtsLen1);
1094    }
1095    else
1096        return -1;
1097
1098
1099
1100    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) ||
1101(tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) ||
1102     (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))||
1103    (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE))))
1104    {
1105        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1106	rc = BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->notAfter), &totalElmtsLen1, mode);
1107		if ( rc != LDAP_SUCCESS ) return rc;
1108		(k->notAfter)->identifier.bv_val = (k->notAfter)->id_buf;
1109		(k->notAfter)->identifier.bv_len = strlen("notAfter");
1110		strcpy( (k->notAfter)->identifier.bv_val, "notAfter");
1111        seqDone = TRUE;
1112        if (elmtLen0 == INDEFINITE_LEN)
1113            BDecEoc (b, &totalElmtsLen1 );
1114        else if (totalElmtsLen1 != elmtLen0)
1115        return -1;
1116
1117    }
1118    else
1119        return -1;
1120
1121
1122
1123    if (!seqDone)
1124        return -1;
1125
1126	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1127	*v = t = (ComponentValidity*) CompAlloc( mem_op, sizeof(ComponentValidity) );
1128	if ( !t ) return -1;
1129	*t = *k;
1130	}
1131	t->syntax = (Syntax*)NULL;
1132	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1133	if ( !t->comp_desc ) {
1134		free ( t );
1135		return -1;
1136	}
1137	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentValidity ;
1138	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentValidity ;
1139	t->comp_desc->cd_free = (comp_free_func*)NULL;
1140	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentValidity;
1141	t->comp_desc->cd_type = ASN_COMPOSITE;
1142	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1143	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentValidity;
1144    (*bytesDecoded) += totalElmtsLen1;
1145	return LDAP_SUCCESS;
1146}  /* BDecValidity*/
1147
1148int
1149GDecComponentValidity PARAMS (( mem_op,b, v, bytesDecoded, mode),
1150void* mem_op _AND_
1151GenBuf * b _AND_
1152ComponentValidity **v _AND_
1153AsnLen *bytesDecoded _AND_
1154int mode)
1155{
1156	char* peek_head,*peek_head2;
1157	int i, strLen,strLen2, rc, old_mode = mode;
1158	ComponentValidity *k,*t, c_temp;
1159
1160
1161	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1162		memset(&c_temp,0,sizeof(c_temp));
1163		 k = &c_temp;
1164	} else
1165		 k = t = *v;
1166	mode = DEC_ALLOC_MODE_2;
1167	*bytesDecoded = 0;
1168	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1169		Asn1Error("Error during Reading { in encoded data");
1170		return LDAP_PROTOCOL_ERROR;
1171	}
1172	if(*peek_head != '{'){
1173		Asn1Error("Missing { in encoded data");
1174		return LDAP_PROTOCOL_ERROR;
1175	}
1176
1177	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1178		Asn1Error("Error during Reading identifier");
1179		return LDAP_PROTOCOL_ERROR;
1180	}
1181	if ( strncmp( peek_head, "notBefore", strlen("notBefore") ) == 0 ) {
1182		rc = 	GDecComponentTime (mem_op, b, (&k->notBefore), bytesDecoded, mode);
1183		if ( rc != LDAP_SUCCESS ) return rc;
1184	( k->notBefore)->identifier.bv_val = peek_head;
1185	( k->notBefore)->identifier.bv_len = strLen;
1186	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1187		Asn1Error("Error during Reading , ");
1188		return LDAP_PROTOCOL_ERROR;
1189	}
1190	if(*peek_head != ','){
1191		Asn1Error("Missing , in encoding");
1192		return LDAP_PROTOCOL_ERROR;
1193	}
1194	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1195	  Asn1Error("Error during Reading identifier");
1196		return LDAP_PROTOCOL_ERROR;
1197	}
1198	}
1199	if ( strncmp( peek_head, "notAfter", strlen("notAfter") ) == 0 ) {
1200		rc = 	GDecComponentTime (mem_op, b, (&k->notAfter), bytesDecoded, mode);
1201		if ( rc != LDAP_SUCCESS ) return rc;
1202	( k->notAfter)->identifier.bv_val = peek_head;
1203	( k->notAfter)->identifier.bv_len = strLen;
1204	}
1205	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
1206		Asn1Error("Error during Reading } in encoding");
1207		return LDAP_PROTOCOL_ERROR;
1208	}
1209	if(*peek_head != '}'){
1210		Asn1Error("Missing } in encoding");
1211		return LDAP_PROTOCOL_ERROR;
1212	}
1213	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1214	*v = t = (ComponentValidity*) CompAlloc( mem_op, sizeof(ComponentValidity) );
1215	if ( !t ) return -1;
1216	*t = *k;
1217	}
1218	t->syntax = (Syntax*)NULL;
1219	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1220	if ( !t->comp_desc ) {
1221		free ( t );
1222		return -1;
1223	}
1224	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentValidity ;
1225	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentValidity ;
1226	t->comp_desc->cd_free = (comp_free_func*)NULL;
1227	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentValidity;
1228	t->comp_desc->cd_type = ASN_COMPOSITE;
1229	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1230	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentValidity;
1231	return LDAP_SUCCESS;
1232}  /* GDecValidity*/
1233
1234
1235int
1236MatchingComponentSubjectPublicKeyInfo ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
1237	int rc;
1238	MatchingRule* mr;
1239
1240	if ( oid ) {
1241		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
1242		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
1243	}
1244
1245	rc = 1;
1246	rc =	MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentSubjectPublicKeyInfo*)csi_attr)->algorithm, (ComponentSyntaxInfo*)((ComponentSubjectPublicKeyInfo*)csi_assert)->algorithm );
1247	if ( rc != LDAP_COMPARE_TRUE )
1248		return rc;
1249	rc =	MatchingComponentBits ( oid, (ComponentSyntaxInfo*)&((ComponentSubjectPublicKeyInfo*)csi_attr)->subjectPublicKey, (ComponentSyntaxInfo*)&((ComponentSubjectPublicKeyInfo*)csi_assert)->subjectPublicKey );
1250	if ( rc != LDAP_COMPARE_TRUE )
1251		return rc;
1252	return LDAP_COMPARE_TRUE;
1253}  /* BMatchingComponentSubjectPublicKeyInfo */
1254
1255void*
1256ExtractingComponentSubjectPublicKeyInfo ( void* mem_op, ComponentReference* cr, ComponentSubjectPublicKeyInfo *comp )
1257{
1258
1259	if ( ( comp->algorithm->identifier.bv_val && strncmp(comp->algorithm->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->algorithm->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
1260		if ( cr->cr_curr->ci_next == NULL )
1261			return comp->algorithm;
1262		else {
1263			cr->cr_curr = cr->cr_curr->ci_next;
1264			return 	ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->algorithm );
1265		}
1266	}
1267	if ( ( comp->subjectPublicKey.identifier.bv_val && strncmp(comp->subjectPublicKey.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectPublicKey.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
1268		if ( cr->cr_curr->ci_next == NULL )
1269		return &comp->subjectPublicKey;
1270	else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
1271			cr->cr_curr = cr->cr_curr->ci_next;
1272		return &comp->subjectPublicKey;
1273	 } else {
1274		return NULL;
1275		}
1276	}
1277	return NULL;
1278}  /* ExtractingComponentSubjectPublicKeyInfo */
1279
1280int
1281BDecComponentSubjectPublicKeyInfo PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
1282void* mem_op _AND_
1283GenBuf * b _AND_
1284AsnTag tagId0 _AND_
1285AsnLen elmtLen0 _AND_
1286ComponentSubjectPublicKeyInfo **v _AND_
1287AsnLen *bytesDecoded _AND_
1288int mode)
1289{
1290	int seqDone = FALSE;
1291	AsnLen totalElmtsLen1 = 0;
1292	AsnLen elmtLen1;
1293	AsnTag tagId1;
1294	int mandatoryElmtCount1 = 0;
1295	int old_mode = mode;
1296	int rc;
1297	ComponentSubjectPublicKeyInfo *k, *t, c_temp;
1298
1299
1300	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1301		memset(&c_temp,0,sizeof(c_temp));
1302		 k = &c_temp;
1303	} else
1304		 k = t = *v;
1305	mode = DEC_ALLOC_MODE_2;
1306    tagId1 = BDecTag (b, &totalElmtsLen1 );
1307
1308    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
1309    {
1310    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1311	rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->algorithm), &totalElmtsLen1, mode);
1312		if ( rc != LDAP_SUCCESS ) return rc;
1313		(k->algorithm)->identifier.bv_val = (k->algorithm)->id_buf;
1314		(k->algorithm)->identifier.bv_len = strlen("algorithm");
1315		strcpy( (k->algorithm)->identifier.bv_val, "algorithm");
1316    tagId1 = BDecTag (b, &totalElmtsLen1);
1317    }
1318    else
1319        return -1;
1320
1321
1322
1323    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE)) ||
1324(tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE))))
1325    {
1326    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1327	rc = BDecComponentBits (mem_op, b, tagId1, elmtLen1, (&k->subjectPublicKey), &totalElmtsLen1, mode);
1328		if ( rc != LDAP_SUCCESS ) return rc;
1329		(&k->subjectPublicKey)->identifier.bv_val = (&k->subjectPublicKey)->id_buf;
1330		(&k->subjectPublicKey)->identifier.bv_len = strlen("subjectPublicKey");
1331		strcpy( (&k->subjectPublicKey)->identifier.bv_val, "subjectPublicKey");
1332        seqDone = TRUE;
1333        if (elmtLen0 == INDEFINITE_LEN)
1334            BDecEoc (b, &totalElmtsLen1 );
1335        else if (totalElmtsLen1 != elmtLen0)
1336        return -1;
1337
1338    }
1339    else
1340        return -1;
1341
1342
1343
1344    if (!seqDone)
1345        return -1;
1346
1347	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1348	*v = t = (ComponentSubjectPublicKeyInfo*) CompAlloc( mem_op, sizeof(ComponentSubjectPublicKeyInfo) );
1349	if ( !t ) return -1;
1350	*t = *k;
1351	}
1352	t->syntax = (Syntax*)NULL;
1353	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1354	if ( !t->comp_desc ) {
1355		free ( t );
1356		return -1;
1357	}
1358	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentSubjectPublicKeyInfo ;
1359	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentSubjectPublicKeyInfo ;
1360	t->comp_desc->cd_free = (comp_free_func*)NULL;
1361	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentSubjectPublicKeyInfo;
1362	t->comp_desc->cd_type = ASN_COMPOSITE;
1363	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1364	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentSubjectPublicKeyInfo;
1365    (*bytesDecoded) += totalElmtsLen1;
1366	return LDAP_SUCCESS;
1367}  /* BDecSubjectPublicKeyInfo*/
1368
1369int
1370GDecComponentSubjectPublicKeyInfo PARAMS (( mem_op,b, v, bytesDecoded, mode),
1371void* mem_op _AND_
1372GenBuf * b _AND_
1373ComponentSubjectPublicKeyInfo **v _AND_
1374AsnLen *bytesDecoded _AND_
1375int mode)
1376{
1377	char* peek_head,*peek_head2;
1378	int i, strLen,strLen2, rc, old_mode = mode;
1379	ComponentSubjectPublicKeyInfo *k,*t, c_temp;
1380
1381
1382	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1383		memset(&c_temp,0,sizeof(c_temp));
1384		 k = &c_temp;
1385	} else
1386		 k = t = *v;
1387	mode = DEC_ALLOC_MODE_2;
1388	*bytesDecoded = 0;
1389	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1390		Asn1Error("Error during Reading { in encoded data");
1391		return LDAP_PROTOCOL_ERROR;
1392	}
1393	if(*peek_head != '{'){
1394		Asn1Error("Missing { in encoded data");
1395		return LDAP_PROTOCOL_ERROR;
1396	}
1397
1398	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1399		Asn1Error("Error during Reading identifier");
1400		return LDAP_PROTOCOL_ERROR;
1401	}
1402	if ( strncmp( peek_head, "algorithm", strlen("algorithm") ) == 0 ) {
1403		rc = 	GDecComponentAlgorithmIdentifier (mem_op, b, (&k->algorithm), bytesDecoded, mode);
1404		if ( rc != LDAP_SUCCESS ) return rc;
1405	( k->algorithm)->identifier.bv_val = peek_head;
1406	( k->algorithm)->identifier.bv_len = strLen;
1407	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1408		Asn1Error("Error during Reading , ");
1409		return LDAP_PROTOCOL_ERROR;
1410	}
1411	if(*peek_head != ','){
1412		Asn1Error("Missing , in encoding");
1413		return LDAP_PROTOCOL_ERROR;
1414	}
1415	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
1416	  Asn1Error("Error during Reading identifier");
1417		return LDAP_PROTOCOL_ERROR;
1418	}
1419	}
1420	if ( strncmp( peek_head, "subjectPublicKey", strlen("subjectPublicKey") ) == 0 ) {
1421		rc = 	GDecComponentBits (mem_op, b, (&k->subjectPublicKey), bytesDecoded, mode);
1422		if ( rc != LDAP_SUCCESS ) return rc;
1423	(&k->subjectPublicKey)->identifier.bv_val = peek_head;
1424	(&k->subjectPublicKey)->identifier.bv_len = strLen;
1425	}
1426	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
1427		Asn1Error("Error during Reading } in encoding");
1428		return LDAP_PROTOCOL_ERROR;
1429	}
1430	if(*peek_head != '}'){
1431		Asn1Error("Missing } in encoding");
1432		return LDAP_PROTOCOL_ERROR;
1433	}
1434	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1435	*v = t = (ComponentSubjectPublicKeyInfo*) CompAlloc( mem_op, sizeof(ComponentSubjectPublicKeyInfo) );
1436	if ( !t ) return -1;
1437	*t = *k;
1438	}
1439	t->syntax = (Syntax*)NULL;
1440	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1441	if ( !t->comp_desc ) {
1442		free ( t );
1443		return -1;
1444	}
1445	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentSubjectPublicKeyInfo ;
1446	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentSubjectPublicKeyInfo ;
1447	t->comp_desc->cd_free = (comp_free_func*)NULL;
1448	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentSubjectPublicKeyInfo;
1449	t->comp_desc->cd_type = ASN_COMPOSITE;
1450	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1451	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentSubjectPublicKeyInfo;
1452	return LDAP_SUCCESS;
1453}  /* GDecSubjectPublicKeyInfo*/
1454
1455
1456int
1457MatchingComponentExtensions ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
1458	int rc;
1459	MatchingRule* mr;
1460	void* component1, *component2;
1461	AsnList *v1, *v2, t_list;
1462
1463
1464	if ( oid ) {
1465		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
1466		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
1467	}
1468
1469	v1 = &((ComponentExtensions*)csi_attr)->comp_list;
1470	v2 = &((ComponentExtensions*)csi_assert)->comp_list;
1471	FOR_EACH_LIST_PAIR_ELMT(component1, component2, v1, v2)
1472	{
1473		if( MatchingComponentExtension(oid, (ComponentSyntaxInfo*)component1, (ComponentSyntaxInfo*)component2) == LDAP_COMPARE_FALSE) {
1474			return LDAP_COMPARE_FALSE;
1475		}
1476	} /* end of for */
1477
1478	AsnListFirst( v1 );
1479	AsnListFirst( v2 );
1480	if( (!component1 && component2) || (component1 && !component2))
1481		return LDAP_COMPARE_FALSE;
1482	else
1483		return LDAP_COMPARE_TRUE;
1484}  /* BMatchingComponentExtensionsContent */
1485
1486void*
1487ExtractingComponentExtensions ( void* mem_op, ComponentReference* cr, ComponentExtensions *comp )
1488{
1489	int count = 0;
1490	int total;
1491	AsnList *v = &comp->comp_list;
1492	ComponentInt *k;
1493	ComponentExtension *component;
1494
1495
1496	switch ( cr->cr_curr->ci_type ) {
1497	case LDAP_COMPREF_FROM_BEGINNING :
1498		count = cr->cr_curr->ci_val.ci_from_beginning;
1499		FOR_EACH_LIST_ELMT( component , v ) {
1500			if( --count == 0 ) {
1501				if( cr->cr_curr->ci_next == NULL )
1502					return component;
1503				else {
1504					cr->cr_curr = cr->cr_curr->ci_next;
1505					return 	ExtractingComponentExtension ( mem_op, cr, component );
1506				}
1507			}
1508		}
1509		break;
1510	case LDAP_COMPREF_FROM_END :
1511		total = AsnListCount ( v );
1512		count = cr->cr_curr->ci_val.ci_from_end;
1513		count = total + count +1;
1514		FOR_EACH_LIST_ELMT ( component, v ) {
1515			if( --count == 0 ) {
1516				if( cr->cr_curr->ci_next == NULL )
1517					return component;
1518				else {
1519					cr->cr_curr = cr->cr_curr->ci_next;
1520					return 	ExtractingComponentExtension ( mem_op, cr, component );
1521				}
1522			}
1523		}
1524		break;
1525	case LDAP_COMPREF_ALL :
1526		return comp;
1527	case LDAP_COMPREF_COUNT :
1528		k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt));
1529		k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1530		k->comp_desc->cd_tag = (-1);
1531		k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
1532		k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
1533		k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL;
1534		k->comp_desc->cd_type = ASN_BASIC;
1535		k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
1536		k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
1537		k->value = AsnListCount(v);
1538		return k;
1539	default :
1540		return NULL;
1541	}
1542}  /* ExtractingComponentExtensions */
1543
1544int
1545BDecComponentExtensions PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
1546void* mem_op _AND_
1547GenBuf * b _AND_
1548AsnTag tagId0 _AND_
1549AsnLen elmtLen0 _AND_
1550ComponentExtensions **v _AND_
1551AsnLen *bytesDecoded _AND_
1552int mode)
1553{
1554	int seqDone = FALSE;
1555	AsnLen totalElmtsLen1 = 0;
1556	AsnLen elmtLen1;
1557	AsnTag tagId1;
1558	int mandatoryElmtCount1 = 0;
1559	int old_mode = mode;
1560	int rc;
1561	ComponentExtensions *k, *t, c_temp;
1562
1563
1564	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1565		memset(&c_temp,0,sizeof(c_temp));
1566		 k = &c_temp;
1567	} else
1568		 k = t = *v;
1569	mode = DEC_ALLOC_MODE_2;
1570	AsnListInit(&k->comp_list,sizeof(ComponentExtension));
1571    for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);)
1572    {
1573        ComponentExtension **tmpVar;
1574    tagId1 = BDecTag (b, &totalElmtsLen1 );
1575
1576    if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
1577    {
1578        BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
1579        break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/
1580    }
1581    if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
1582    {
1583        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1584    tmpVar = (ComponentExtension**) CompAsnListAppend (mem_op,&k->comp_list);
1585	rc = BDecComponentExtension (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode);
1586		if ( rc != LDAP_SUCCESS ) return rc;
1587    }  /* end of tag check if */
1588    else  /* wrong tag */
1589    {
1590         Asn1Error ("Unexpected Tag\n");
1591         return -1;
1592    }
1593    } /* end of for */
1594
1595	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1596	*v = t = (ComponentExtensions*) CompAlloc( mem_op, sizeof(ComponentExtensions) );
1597	if ( !t ) return -1;
1598	*t = *k;
1599	}
1600	t->syntax = (Syntax*)NULL;
1601	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1602	if ( !t->comp_desc ) {
1603		free ( t );
1604		return -1;
1605	}
1606	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtensions ;
1607	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtensions ;
1608	t->comp_desc->cd_free = (comp_free_func*)NULL;
1609	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtensions;
1610	t->comp_desc->cd_type = ASN_COMPOSITE;
1611	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1612	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtensions;
1613    (*bytesDecoded) += totalElmtsLen1;
1614	return LDAP_SUCCESS;
1615}  /* BDecExtensionsContent */
1616
1617int
1618GDecComponentExtensions PARAMS (( mem_op,b, v, bytesDecoded, mode),
1619void* mem_op _AND_
1620GenBuf * b _AND_
1621ComponentExtensions **v _AND_
1622AsnLen *bytesDecoded _AND_
1623int mode)
1624{
1625	char* peek_head,*peek_head2;
1626	int i, strLen,strLen2, rc, old_mode = mode;
1627	ComponentExtensions *k,*t, c_temp;
1628
1629
1630	int ElmtsLen1;
1631	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1632		memset(&c_temp,0,sizeof(c_temp));
1633		 k = &c_temp;
1634	} else
1635		 k = t = *v;
1636	mode = DEC_ALLOC_MODE_2;
1637	AsnListInit( &k->comp_list, sizeof( ComponentExtension ) );
1638	*bytesDecoded = 0;
1639	if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){
1640		Asn1Error("Error during Reading { in encoding");
1641		return LDAP_PROTOCOL_ERROR;
1642	}
1643	if(*peek_head != '{'){
1644		Asn1Error("Missing { in encoded data");
1645		return LDAP_PROTOCOL_ERROR;
1646	}
1647
1648	for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++)
1649	{
1650		ComponentExtension **tmpVar;
1651		if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){
1652			Asn1Error("Error during Reading{ in encoding");
1653			return LDAP_PROTOCOL_ERROR;
1654		}
1655		if(*peek_head == '}') break;
1656		if( !(*peek_head == '{' || *peek_head ==',') ) {
1657			return LDAP_PROTOCOL_ERROR;
1658		}
1659		tmpVar = (ComponentExtension**) CompAsnListAppend (mem_op, &k->comp_list);
1660		if ( tmpVar == NULL ) {
1661			Asn1Error("Error during Reading{ in encoding");
1662			return LDAP_PROTOCOL_ERROR;
1663		}
1664		rc = 	GDecComponentExtension (mem_op, b, tmpVar, bytesDecoded, mode);
1665		if ( rc != LDAP_SUCCESS ) return rc;
1666	} /* end of for */
1667
1668	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1669	*v = t = (ComponentExtensions*) CompAlloc( mem_op, sizeof(ComponentExtensions) );
1670	if ( !t ) return -1;
1671	*t = *k;
1672	}
1673	t->syntax = (Syntax*)NULL;
1674	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1675	if ( !t->comp_desc ) {
1676		free ( t );
1677		return -1;
1678	}
1679	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtensions ;
1680	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtensions ;
1681	t->comp_desc->cd_free = (comp_free_func*)NULL;
1682	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtensions;
1683	t->comp_desc->cd_type = ASN_COMPOSITE;
1684	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
1685	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtensions;
1686	return LDAP_SUCCESS;
1687}  /* GDecExtensionsContent */
1688
1689
1690int
1691MatchingComponentRelativeDistinguishedName ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
1692	int rc;
1693	MatchingRule* mr;
1694	void* component1, *component2;
1695	AsnList *v1, *v2, t_list;
1696
1697
1698	if ( oid ) {
1699		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
1700		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
1701	}
1702
1703	v1 = &((ComponentRelativeDistinguishedName*)csi_attr)->comp_list;
1704	v2 = &((ComponentRelativeDistinguishedName*)csi_assert)->comp_list;
1705	AsnListInit( &t_list, 0 );
1706	if( AsnListCount( v1 ) != AsnListCount( v2 ) )
1707		return LDAP_COMPARE_FALSE;
1708	FOR_EACH_LIST_ELMT (component1, v1)
1709	{
1710		FOR_EACH_LIST_ELMT(component2, v2)
1711		{
1712			if( MatchingComponentAttributeTypeAndValue(oid, (ComponentSyntaxInfo*)component1,(ComponentSyntaxInfo*)component2) == LDAP_COMPARE_TRUE ) {
1713			AsnElmtMove( v2, &t_list );
1714			   break;
1715			}
1716		} /* end of inner for */
1717	} /* end of outer for */
1718
1719	if( AsnListCount( v2 ) == 0 )
1720		 rc = LDAP_COMPARE_TRUE;
1721	else
1722		 rc = LDAP_COMPARE_FALSE;
1723	AsnListMove( &t_list, v2 );
1724	AsnListFirst( v1 );
1725	AsnListFirst( v2 );
1726	return rc;
1727}  /* BMatchingComponentRelativeDistinguishedNameContent */
1728
1729void*
1730ExtractingComponentRelativeDistinguishedName ( void* mem_op, ComponentReference* cr, ComponentRelativeDistinguishedName *comp )
1731{
1732	int count = 0;
1733	int total;
1734	AsnList *v = &comp->comp_list;
1735	ComponentInt *k;
1736	ComponentAttributeTypeAndValue *component;
1737
1738
1739	switch ( cr->cr_curr->ci_type ) {
1740	case LDAP_COMPREF_FROM_BEGINNING :
1741		count = cr->cr_curr->ci_val.ci_from_beginning;
1742		FOR_EACH_LIST_ELMT( component , v ) {
1743			if( --count == 0 ) {
1744				if( cr->cr_curr->ci_next == NULL )
1745					return component;
1746				else {
1747					cr->cr_curr = cr->cr_curr->ci_next;
1748					return 	ExtractingComponentAttributeTypeAndValue ( mem_op, cr, component );
1749				}
1750			}
1751		}
1752		break;
1753	case LDAP_COMPREF_FROM_END :
1754		total = AsnListCount ( v );
1755		count = cr->cr_curr->ci_val.ci_from_end;
1756		count = total + count +1;
1757		FOR_EACH_LIST_ELMT ( component, v ) {
1758			if( --count == 0 ) {
1759				if( cr->cr_curr->ci_next == NULL )
1760					return component;
1761				else {
1762					cr->cr_curr = cr->cr_curr->ci_next;
1763					return 	ExtractingComponentAttributeTypeAndValue ( mem_op, cr, component );
1764				}
1765			}
1766		}
1767		break;
1768	case LDAP_COMPREF_ALL :
1769		return comp;
1770	case LDAP_COMPREF_COUNT :
1771		k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt));
1772		k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1773		k->comp_desc->cd_tag = (-1);
1774		k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
1775		k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
1776		k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL;
1777		k->comp_desc->cd_type = ASN_BASIC;
1778		k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
1779		k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
1780		k->value = AsnListCount(v);
1781		return k;
1782	default :
1783		return NULL;
1784	}
1785}  /* ExtractingComponentRelativeDistinguishedName */
1786
1787int
1788BDecComponentRelativeDistinguishedName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
1789void* mem_op _AND_
1790GenBuf * b _AND_
1791AsnTag tagId0 _AND_
1792AsnLen elmtLen0 _AND_
1793ComponentRelativeDistinguishedName **v _AND_
1794AsnLen *bytesDecoded _AND_
1795int mode)
1796{
1797	int seqDone = FALSE;
1798	AsnLen totalElmtsLen1 = 0;
1799	AsnLen elmtLen1;
1800	AsnTag tagId1;
1801	int mandatoryElmtCount1 = 0;
1802	int old_mode = mode;
1803	int rc;
1804	ComponentRelativeDistinguishedName *k, *t, c_temp;
1805
1806
1807	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1808		memset(&c_temp,0,sizeof(c_temp));
1809		 k = &c_temp;
1810	} else
1811		 k = t = *v;
1812	mode = DEC_ALLOC_MODE_2;
1813	AsnListInit(&k->comp_list,sizeof(ComponentAttributeTypeAndValue));
1814    for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);)
1815    {
1816        ComponentAttributeTypeAndValue **tmpVar;
1817    tagId1 = BDecTag (b, &totalElmtsLen1 );
1818
1819    if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
1820    {
1821        BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
1822        break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/
1823    }
1824    if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
1825    {
1826        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
1827    tmpVar = (ComponentAttributeTypeAndValue**) CompAsnListAppend (mem_op,&k->comp_list);
1828	rc = BDecComponentAttributeTypeAndValue (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode);
1829		if ( rc != LDAP_SUCCESS ) return rc;
1830    }  /* end of tag check if */
1831    else  /* wrong tag */
1832    {
1833         Asn1Error ("Unexpected Tag\n");
1834         return -1;
1835    }
1836    } /* end of for */
1837
1838	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1839	*v = t = (ComponentRelativeDistinguishedName*) CompAlloc( mem_op, sizeof(ComponentRelativeDistinguishedName) );
1840	if ( !t ) return -1;
1841	*t = *k;
1842	}
1843	t->syntax = (Syntax*)NULL;
1844	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1845	if ( !t->comp_desc ) {
1846		free ( t );
1847		return -1;
1848	}
1849
1850	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
1851	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
1852	t->comp_desc->cd_ldap_encoder = (encoder_func*)ConvertRDN2RFC2253;
1853	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeDistinguishedName ;
1854	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeDistinguishedName ;
1855	t->comp_desc->cd_free = (comp_free_func*)NULL;
1856	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName;
1857	t->comp_desc->cd_type = ASN_COMPOSITE;
1858	t->comp_desc->cd_type_id = RelativeDistinguishedName;
1859	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeDistinguishedName;
1860    (*bytesDecoded) += totalElmtsLen1;
1861	return LDAP_SUCCESS;
1862}  /* BDecRelativeDistinguishedNameContent */
1863
1864int
1865GDecComponentRelativeDistinguishedName PARAMS (( mem_op,b, v, bytesDecoded, mode),
1866void* mem_op _AND_
1867GenBuf * b _AND_
1868ComponentRelativeDistinguishedName **v _AND_
1869AsnLen *bytesDecoded _AND_
1870int mode)
1871{
1872	char* peek_head,*peek_head2;
1873	int i, strLen,strLen2, rc, old_mode = mode;
1874	ComponentRelativeDistinguishedName *k,*t, c_temp;
1875
1876
1877	int ElmtsLen1;
1878	if ( !(mode & DEC_ALLOC_MODE_1) ) {
1879		memset(&c_temp,0,sizeof(c_temp));
1880		 k = &c_temp;
1881	} else
1882		 k = t = *v;
1883	mode = DEC_ALLOC_MODE_2;
1884	AsnListInit( &k->comp_list, sizeof( ComponentAttributeTypeAndValue ) );
1885	*bytesDecoded = 0;
1886	if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){
1887		Asn1Error("Error during Reading { in encoding");
1888		return LDAP_PROTOCOL_ERROR;
1889	}
1890	if(*peek_head != '{'){
1891		Asn1Error("Missing { in encoded data");
1892		return LDAP_PROTOCOL_ERROR;
1893	}
1894
1895	for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++)
1896	{
1897		ComponentAttributeTypeAndValue **tmpVar;
1898		if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){
1899			Asn1Error("Error during Reading{ in encoding");
1900			return LDAP_PROTOCOL_ERROR;
1901		}
1902		if(*peek_head == '}') break;
1903		if( !(*peek_head == '{' || *peek_head ==',') ) {
1904			return LDAP_PROTOCOL_ERROR;
1905		}
1906		tmpVar = (ComponentAttributeTypeAndValue**) CompAsnListAppend (mem_op, &k->comp_list);
1907		if ( tmpVar == NULL ) {
1908			Asn1Error("Error during Reading{ in encoding");
1909			return LDAP_PROTOCOL_ERROR;
1910		}
1911		rc = 	GDecComponentAttributeTypeAndValue (mem_op, b, tmpVar, bytesDecoded, mode);
1912		if ( rc != LDAP_SUCCESS ) return rc;
1913	} /* end of for */
1914
1915	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1916	*v = t = (ComponentRelativeDistinguishedName*) CompAlloc( mem_op, sizeof(ComponentRelativeDistinguishedName) );
1917	if ( !t ) return -1;
1918	*t = *k;
1919	}
1920	t->syntax = (Syntax*)NULL;
1921	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1922	if ( !t->comp_desc ) {
1923		free ( t );
1924		return -1;
1925	}
1926	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeDistinguishedName ;
1927	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeDistinguishedName ;
1928	t->comp_desc->cd_free = (comp_free_func*)NULL;
1929	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName;
1930	t->comp_desc->cd_type = ASN_COMPOSITE;
1931	t->comp_desc->cd_type_id = RelativeDistinguishedName;
1932	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeDistinguishedName;
1933	return LDAP_SUCCESS;
1934}  /* GDecRelativeDistinguishedNameContent */
1935
1936
1937int
1938MatchingComponentRDNSequence ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
1939	int rc;
1940	MatchingRule* mr;
1941	void* component1, *component2;
1942	AsnList *v1, *v2, t_list;
1943
1944
1945	if ( oid ) {
1946		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
1947		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
1948	}
1949
1950	v1 = &((ComponentRDNSequence*)csi_attr)->comp_list;
1951	v2 = &((ComponentRDNSequence*)csi_assert)->comp_list;
1952	FOR_EACH_LIST_PAIR_ELMT(component1, component2, v1, v2)
1953	{
1954		if( MatchingComponentRelativeDistinguishedName(oid, (ComponentSyntaxInfo*)component1, (ComponentSyntaxInfo*)component2) == LDAP_COMPARE_FALSE) {
1955			return LDAP_COMPARE_FALSE;
1956		}
1957	} /* end of for */
1958
1959	AsnListFirst( v1 );
1960	AsnListFirst( v2 );
1961	if( (!component1 && component2) || (component1 && !component2))
1962		return LDAP_COMPARE_FALSE;
1963	else
1964		return LDAP_COMPARE_TRUE;
1965}  /* BMatchingComponentRDNSequenceContent */
1966
1967void*
1968ExtractingComponentRDNSequence ( void* mem_op, ComponentReference* cr, ComponentRDNSequence *comp )
1969{
1970	int count = 0;
1971	int total;
1972	AsnList *v = &comp->comp_list;
1973	ComponentInt *k;
1974	ComponentRelativeDistinguishedName *component;
1975
1976
1977	switch ( cr->cr_curr->ci_type ) {
1978	case LDAP_COMPREF_FROM_BEGINNING :
1979		count = cr->cr_curr->ci_val.ci_from_beginning;
1980		FOR_EACH_LIST_ELMT( component , v ) {
1981			if( --count == 0 ) {
1982				if( cr->cr_curr->ci_next == NULL )
1983					return component;
1984				else {
1985					cr->cr_curr = cr->cr_curr->ci_next;
1986					return 	ExtractingComponentRelativeDistinguishedName ( mem_op, cr, component );
1987				}
1988			}
1989		}
1990		break;
1991	case LDAP_COMPREF_FROM_END :
1992		total = AsnListCount ( v );
1993		count = cr->cr_curr->ci_val.ci_from_end;
1994		count = total + count +1;
1995		FOR_EACH_LIST_ELMT ( component, v ) {
1996			if( --count == 0 ) {
1997				if( cr->cr_curr->ci_next == NULL )
1998					return component;
1999				else {
2000					cr->cr_curr = cr->cr_curr->ci_next;
2001					return 	ExtractingComponentRelativeDistinguishedName ( mem_op, cr, component );
2002				}
2003			}
2004		}
2005		break;
2006	case LDAP_COMPREF_ALL :
2007		return comp;
2008	case LDAP_COMPREF_COUNT :
2009		k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt));
2010		k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2011		k->comp_desc->cd_tag = (-1);
2012		k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
2013		k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
2014		k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL;
2015		k->comp_desc->cd_type = ASN_BASIC;
2016		k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
2017		k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
2018		k->value = AsnListCount(v);
2019		return k;
2020	default :
2021		return NULL;
2022	}
2023}  /* ExtractingComponentRDNSequence */
2024
2025int
2026BDecComponentRDNSequence PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
2027void* mem_op _AND_
2028GenBuf * b _AND_
2029AsnTag tagId0 _AND_
2030AsnLen elmtLen0 _AND_
2031ComponentRDNSequence **v _AND_
2032AsnLen *bytesDecoded _AND_
2033int mode)
2034{
2035	int seqDone = FALSE;
2036	AsnLen totalElmtsLen1 = 0;
2037	AsnLen elmtLen1;
2038	AsnTag tagId1;
2039	int mandatoryElmtCount1 = 0;
2040	int old_mode = mode;
2041	int rc;
2042	ComponentRDNSequence *k, *t, c_temp;
2043
2044
2045	if ( !(mode & DEC_ALLOC_MODE_1) ) {
2046		memset(&c_temp,0,sizeof(c_temp));
2047		 k = &c_temp;
2048	} else
2049		 k = t = *v;
2050	mode = DEC_ALLOC_MODE_2;
2051	AsnListInit(&k->comp_list,sizeof(ComponentRelativeDistinguishedName));
2052    for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);)
2053    {
2054        ComponentRelativeDistinguishedName **tmpVar;
2055    tagId1 = BDecTag (b, &totalElmtsLen1 );
2056
2057    if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
2058    {
2059        BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
2060        break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/
2061    }
2062    if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE)))
2063    {
2064        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2065    tmpVar = (ComponentRelativeDistinguishedName**) CompAsnListAppend (mem_op,&k->comp_list);
2066	rc = BDecComponentRelativeDistinguishedName (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode);
2067		if ( rc != LDAP_SUCCESS ) return rc;
2068    }  /* end of tag check if */
2069    else  /* wrong tag */
2070    {
2071         Asn1Error ("Unexpected Tag\n");
2072         return -1;
2073    }
2074    } /* end of for */
2075
2076	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2077	*v = t = (ComponentRDNSequence*) CompAlloc( mem_op, sizeof(ComponentRDNSequence) );
2078	if ( !t ) return -1;
2079	*t = *k;
2080	}
2081	t->syntax = (Syntax*)NULL;
2082	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2083	if ( !t->comp_desc ) {
2084		free ( t );
2085		return -1;
2086	}
2087
2088	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
2089	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
2090	t->comp_desc->cd_ldap_encoder = (encoder_func*) ConvertRDNSequence2RFC2253;
2091	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRDNSequence ;
2092	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRDNSequence ;
2093	t->comp_desc->cd_free = (comp_free_func*)NULL;
2094	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence;
2095	t->comp_desc->cd_type = ASN_COMPOSITE;
2096	t->comp_desc->cd_type_id = RDNSequence;
2097	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRDNSequence;
2098    (*bytesDecoded) += totalElmtsLen1;
2099	return LDAP_SUCCESS;
2100}  /* BDecRDNSequenceContent */
2101
2102int
2103GDecComponentRDNSequence PARAMS (( mem_op,b, v, bytesDecoded, mode),
2104void* mem_op _AND_
2105GenBuf * b _AND_
2106ComponentRDNSequence **v _AND_
2107AsnLen *bytesDecoded _AND_
2108int mode)
2109{
2110	char* peek_head,*peek_head2;
2111	int i, strLen,strLen2, rc, old_mode = mode;
2112	ComponentRDNSequence *k,*t, c_temp;
2113
2114
2115	int ElmtsLen1;
2116	if ( !(mode & DEC_ALLOC_MODE_1) ) {
2117		memset(&c_temp,0,sizeof(c_temp));
2118		 k = &c_temp;
2119	} else
2120		 k = t = *v;
2121	mode = DEC_ALLOC_MODE_2;
2122	AsnListInit( &k->comp_list, sizeof( ComponentRelativeDistinguishedName ) );
2123	*bytesDecoded = 0;
2124	if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){
2125		Asn1Error("Error during Reading { in encoding");
2126		return LDAP_PROTOCOL_ERROR;
2127	}
2128	if(*peek_head != '{'){
2129		Asn1Error("Missing { in encoded data");
2130		return LDAP_PROTOCOL_ERROR;
2131	}
2132
2133	for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++)
2134	{
2135		ComponentRelativeDistinguishedName **tmpVar;
2136		if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){
2137			Asn1Error("Error during Reading{ in encoding");
2138			return LDAP_PROTOCOL_ERROR;
2139		}
2140		if(*peek_head == '}') break;
2141		if( !(*peek_head == '{' || *peek_head ==',') ) {
2142			return LDAP_PROTOCOL_ERROR;
2143		}
2144		tmpVar = (ComponentRelativeDistinguishedName**) CompAsnListAppend (mem_op, &k->comp_list);
2145		if ( tmpVar == NULL ) {
2146			Asn1Error("Error during Reading{ in encoding");
2147			return LDAP_PROTOCOL_ERROR;
2148		}
2149		rc = 	GDecComponentRelativeDistinguishedName (mem_op, b, tmpVar, bytesDecoded, mode);
2150		if ( rc != LDAP_SUCCESS ) return rc;
2151	} /* end of for */
2152
2153	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2154	*v = t = (ComponentRDNSequence*) CompAlloc( mem_op, sizeof(ComponentRDNSequence) );
2155	if ( !t ) return -1;
2156	*t = *k;
2157	}
2158	t->syntax = (Syntax*)NULL;
2159	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2160	if ( !t->comp_desc ) {
2161		free ( t );
2162		return -1;
2163	}
2164	t->comp_desc->cd_gser_encoder = (encoder_func*)NULL;
2165	t->comp_desc->cd_ber_encoder = (encoder_func*)NULL;
2166	t->comp_desc->cd_ldap_encoder = (encoder_func*)ConvertRDNSequence2RFC2253;
2167	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRDNSequence ;
2168	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRDNSequence ;
2169	t->comp_desc->cd_free = (comp_free_func*)NULL;
2170	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence;
2171	t->comp_desc->cd_type = ASN_COMPOSITE;
2172	t->comp_desc->cd_type_id = RDNSequence ;
2173	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRDNSequence;
2174	return LDAP_SUCCESS;
2175}  /* GDecRDNSequenceContent */
2176
2177
2178int
2179MatchingComponentName ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
2180	int rc;
2181	MatchingRule* mr;
2182	ComponentName *v1, *v2;
2183
2184
2185	v1 = (ComponentName*)csi_attr;
2186	v2 = (ComponentName*)csi_assert;
2187	if ( oid ) {
2188		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
2189		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
2190	}
2191
2192	if( (v1->choiceId != v2->choiceId ) )
2193		return LDAP_COMPARE_FALSE;
2194	switch( v1->choiceId )
2195	{
2196	   case NAME_RDNSEQUENCE :
2197		rc = 	MatchingComponentRDNSequence ( oid, (ComponentSyntaxInfo*)(v1->a.rdnSequence), (ComponentSyntaxInfo*)(v2->a.rdnSequence) );
2198		break;
2199	default :
2200		 return LDAP_PROTOCOL_ERROR;
2201	}
2202	return rc;
2203}  /* BMatchingComponentNameContent */
2204
2205void*
2206ExtractingComponentName ( void* mem_op, ComponentReference* cr, ComponentName *comp )
2207{
2208
2209
2210	if( (comp->choiceId) ==  NAME_RDNSEQUENCE &&
2211		 (( comp->a.rdnSequence->identifier.bv_val && strncmp(comp->a.rdnSequence->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) ||
2212		 ( strncmp(comp->a.rdnSequence->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) {
2213		if ( cr->cr_curr->ci_next == NULL )
2214			return (comp->a.rdnSequence);
2215		else {
2216			cr->cr_curr = cr->cr_curr->ci_next;
2217			return 	ExtractingComponentRDNSequence ( mem_op, cr, (comp->a.rdnSequence) );
2218		};
2219	}
2220	return NULL;
2221}  /* ExtractingComponentName */
2222
2223int
2224BDecComponentName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
2225void* mem_op _AND_
2226GenBuf * b _AND_
2227AsnTag tagId0 _AND_
2228AsnLen elmtLen0 _AND_
2229ComponentName **v _AND_
2230AsnLen *bytesDecoded _AND_
2231int mode)
2232{
2233	int seqDone = FALSE;
2234	AsnLen totalElmtsLen1 = 0;
2235	AsnLen elmtLen1;
2236	AsnTag tagId1;
2237	int mandatoryElmtCount1 = 0;
2238	int old_mode = mode;
2239	int rc;
2240	ComponentName *k, *t, c_temp;
2241
2242
2243	if ( !(mode & DEC_ALLOC_MODE_1) ) {
2244		memset(&c_temp,0,sizeof(c_temp));
2245		 k = &c_temp;
2246	} else
2247		 k = t = *v;
2248	mode = DEC_ALLOC_MODE_2;
2249    switch (tagId0)
2250    {
2251       case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
2252        (k->choiceId) = NAME_RDNSEQUENCE;
2253	rc = BDecComponentRDNSequence (mem_op, b, tagId0, elmtLen0, (&k->a.rdnSequence), &totalElmtsLen1, mode);
2254		if ( rc != LDAP_SUCCESS ) return rc;
2255		(k->a.rdnSequence)->identifier.bv_val = (k->a.rdnSequence)->id_buf;
2256		(k->a.rdnSequence)->identifier.bv_len = strlen("rdnSequence");
2257		strcpy( (k->a.rdnSequence)->identifier.bv_val, "rdnSequence");
2258    break;
2259
2260    default:
2261        Asn1Error ("ERROR - unexpected tag in CHOICE\n");
2262        return -1;
2263        break;
2264    } /* end switch */
2265	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2266	*v = t = (ComponentName*) CompAlloc( mem_op, sizeof(ComponentName) );
2267	if ( !t ) return -1;
2268	*t = *k;
2269	}
2270	t->syntax = (Syntax*)NULL;
2271	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2272	if ( !t->comp_desc ) {
2273		free ( t );
2274		return -1;
2275	}
2276	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentName ;
2277	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentName ;
2278	t->comp_desc->cd_free = (comp_free_func*)NULL;
2279	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentName;
2280	t->comp_desc->cd_type = ASN_COMPOSITE;
2281	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
2282	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentName;
2283    (*bytesDecoded) += totalElmtsLen1;
2284	return LDAP_SUCCESS;
2285}  /* BDecNameContent */
2286
2287int
2288GDecComponentName PARAMS (( mem_op,b, v, bytesDecoded, mode),
2289void* mem_op _AND_
2290GenBuf * b _AND_
2291ComponentName **v _AND_
2292AsnLen *bytesDecoded _AND_
2293int mode)
2294{
2295	char* peek_head,*peek_head2;
2296	int i, strLen,strLen2, rc, old_mode = mode;
2297	ComponentName *k,*t, c_temp;
2298
2299
2300	if ( !(mode & DEC_ALLOC_MODE_1) ) {
2301		memset(&c_temp,0,sizeof(c_temp));
2302		 k = &c_temp;
2303	} else
2304		 k = t = *v;
2305	mode = DEC_ALLOC_MODE_2;
2306	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2307		Asn1Error("Error during Reading identifier");
2308		return LDAP_PROTOCOL_ERROR;
2309	}
2310	if( !(strLen2 = LocateNextGSERToken(mem_op,b,&peek_head2,GSER_NO_COPY)) ){
2311		Asn1Error("Error during Reading identifier");
2312		return LDAP_PROTOCOL_ERROR;
2313	}
2314	if(*peek_head2 != ':'){
2315		Asn1Error("Missing : in encoded data");
2316		return LDAP_PROTOCOL_ERROR;
2317	}
2318	if( strncmp("rdnSequence",peek_head, strlen("rdnSequence")) == 0){
2319		(k->choiceId) = NAME_RDNSEQUENCE;
2320		rc = 	GDecComponentRDNSequence (mem_op, b, (&k->a.rdnSequence), bytesDecoded, mode);
2321		if ( rc != LDAP_SUCCESS ) return rc;
2322		(k->a.rdnSequence)->identifier.bv_val = peek_head;
2323		(k->a.rdnSequence)->identifier.bv_len = strLen;
2324	}
2325	else {
2326		Asn1Error("Undefined Identifier");
2327		return LDAP_PROTOCOL_ERROR;
2328	}
2329	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2330	*v = t = (ComponentName*) CompAlloc( mem_op, sizeof(ComponentName) );
2331	if ( !t ) return -1;
2332	*t = *k;
2333	}
2334	t->syntax = (Syntax*)NULL;
2335	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2336	if ( !t->comp_desc ) {
2337		free ( t );
2338		return -1;
2339	}
2340	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentName ;
2341	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentName ;
2342	t->comp_desc->cd_free = (comp_free_func*)NULL;
2343	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentName;
2344	t->comp_desc->cd_type = ASN_COMPOSITE;
2345	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
2346	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentName;
2347	return LDAP_SUCCESS;
2348}  /* GDecNameContent */
2349
2350
2351int
2352MatchingComponentTBSCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
2353	int rc;
2354	MatchingRule* mr;
2355
2356	if ( oid ) {
2357		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
2358		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
2359	}
2360
2361	rc = 1;
2362	rc =	MatchingComponentVersion ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->version, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->version );
2363	if ( rc != LDAP_COMPARE_TRUE )
2364		return rc;
2365	rc =	MatchingComponentCertificateSerialNumber ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->serialNumber, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->serialNumber );
2366	if ( rc != LDAP_COMPARE_TRUE )
2367		return rc;
2368	rc =	MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->signature, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->signature );
2369	if ( rc != LDAP_COMPARE_TRUE )
2370		return rc;
2371	rc =	MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->issuer, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->issuer );
2372	if ( rc != LDAP_COMPARE_TRUE )
2373		return rc;
2374	rc =	MatchingComponentValidity ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->validity, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->validity );
2375	if ( rc != LDAP_COMPARE_TRUE )
2376		return rc;
2377	rc =	MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->subject, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->subject );
2378	if ( rc != LDAP_COMPARE_TRUE )
2379		return rc;
2380	rc =	MatchingComponentSubjectPublicKeyInfo ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->subjectPublicKeyInfo, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->subjectPublicKeyInfo );
2381	if ( rc != LDAP_COMPARE_TRUE )
2382		return rc;
2383	rc =	MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->issuerUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->issuerUniqueIdentifier );
2384	if ( rc != LDAP_COMPARE_TRUE )
2385		return rc;
2386	rc =	MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->subjectUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->subjectUniqueIdentifier );
2387	if ( rc != LDAP_COMPARE_TRUE )
2388		return rc;
2389	if(COMPONENTNOT_NULL( ((ComponentTBSCertificate*)csi_attr)->extensions ) ) {
2390	rc =	MatchingComponentExtensions ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->extensions, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->extensions );
2391	if ( rc != LDAP_COMPARE_TRUE )
2392		return rc;
2393	}
2394	return LDAP_COMPARE_TRUE;
2395}  /* BMatchingComponentTBSCertificate */
2396
2397void*
2398ExtractingComponentTBSCertificate ( void* mem_op, ComponentReference* cr, ComponentTBSCertificate *comp )
2399{
2400
2401	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 ) ) {
2402		if ( cr->cr_curr->ci_next == NULL )
2403			return comp->version;
2404		else {
2405			cr->cr_curr = cr->cr_curr->ci_next;
2406			return 	ExtractingComponentVersion ( mem_op, cr, comp->version );
2407		}
2408	}
2409	if ( ( comp->serialNumber.identifier.bv_val && strncmp(comp->serialNumber.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->serialNumber.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
2410		if ( cr->cr_curr->ci_next == NULL )
2411		return &comp->serialNumber;
2412		else
2413		return NULL;
2414	}
2415	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 ) ) {
2416		if ( cr->cr_curr->ci_next == NULL )
2417			return comp->signature;
2418		else {
2419			cr->cr_curr = cr->cr_curr->ci_next;
2420			return 	ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signature );
2421		}
2422	}
2423	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 ) ) {
2424		if ( cr->cr_curr->ci_next == NULL )
2425			return comp->issuer;
2426		else {
2427			cr->cr_curr = cr->cr_curr->ci_next;
2428			return 	ExtractingComponentName ( mem_op, cr, comp->issuer );
2429		}
2430	}
2431	if ( ( comp->validity->identifier.bv_val && strncmp(comp->validity->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->validity->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
2432		if ( cr->cr_curr->ci_next == NULL )
2433			return comp->validity;
2434		else {
2435			cr->cr_curr = cr->cr_curr->ci_next;
2436			return 	ExtractingComponentValidity ( mem_op, cr, comp->validity );
2437		}
2438	}
2439	if ( ( comp->subject->identifier.bv_val && strncmp(comp->subject->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subject->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
2440		if ( cr->cr_curr->ci_next == NULL )
2441			return comp->subject;
2442		else {
2443			cr->cr_curr = cr->cr_curr->ci_next;
2444			return 	ExtractingComponentName ( mem_op, cr, comp->subject );
2445		}
2446	}
2447	if ( ( comp->subjectPublicKeyInfo->identifier.bv_val && strncmp(comp->subjectPublicKeyInfo->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectPublicKeyInfo->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
2448		if ( cr->cr_curr->ci_next == NULL )
2449			return comp->subjectPublicKeyInfo;
2450		else {
2451			cr->cr_curr = cr->cr_curr->ci_next;
2452			return 	ExtractingComponentSubjectPublicKeyInfo ( mem_op, cr, comp->subjectPublicKeyInfo );
2453		}
2454	}
2455	if ( ( comp->issuerUniqueIdentifier.identifier.bv_val && strncmp(comp->issuerUniqueIdentifier.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->issuerUniqueIdentifier.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
2456		if ( cr->cr_curr->ci_next == NULL )
2457		return &comp->issuerUniqueIdentifier;
2458	else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
2459			cr->cr_curr = cr->cr_curr->ci_next;
2460		return &comp->issuerUniqueIdentifier;
2461	 } else {
2462		return NULL;
2463		}
2464	}
2465	if ( ( comp->subjectUniqueIdentifier.identifier.bv_val && strncmp(comp->subjectUniqueIdentifier.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectUniqueIdentifier.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
2466		if ( cr->cr_curr->ci_next == NULL )
2467		return &comp->subjectUniqueIdentifier;
2468	else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
2469			cr->cr_curr = cr->cr_curr->ci_next;
2470		return &comp->subjectUniqueIdentifier;
2471	 } else {
2472		return NULL;
2473		}
2474	}
2475	if ( ( comp->extensions->identifier.bv_val && strncmp(comp->extensions->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extensions->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
2476		if ( cr->cr_curr->ci_next == NULL )
2477			return comp->extensions;
2478		else {
2479			cr->cr_curr = cr->cr_curr->ci_next;
2480			return 	ExtractingComponentExtensions ( mem_op, cr, comp->extensions );
2481		}
2482	}
2483	return NULL;
2484}  /* ExtractingComponentTBSCertificate */
2485
2486int
2487BDecComponentTBSCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
2488void* mem_op _AND_
2489GenBuf * b _AND_
2490AsnTag tagId0 _AND_
2491AsnLen elmtLen0 _AND_
2492ComponentTBSCertificate **v _AND_
2493AsnLen *bytesDecoded _AND_
2494int mode)
2495{
2496	int seqDone = FALSE;
2497	AsnLen totalElmtsLen1 = 0;
2498	AsnLen elmtLen1;
2499	AsnTag tagId1;
2500	int mandatoryElmtCount1 = 0;
2501	AsnLen totalElmtsLen2 = 0;
2502	AsnLen elmtLen2;
2503	AsnTag tagId2;
2504	int old_mode = mode;
2505	int rc;
2506	ComponentTBSCertificate *k, *t, c_temp;
2507
2508
2509	if ( !(mode & DEC_ALLOC_MODE_1) ) {
2510		memset(&c_temp,0,sizeof(c_temp));
2511		 k = &c_temp;
2512	} else
2513		 k = t = *v;
2514	mode = DEC_ALLOC_MODE_2;
2515    tagId1 = BDecTag (b, &totalElmtsLen1 );
2516
2517    if (((tagId1 == MAKE_TAG_ID (CNTX, CONS, 0))))
2518    {
2519    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2520        tagId2 = BDecTag (b, &totalElmtsLen1 );
2521
2522    if (tagId2 != MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
2523    {
2524         Asn1Error ("Unexpected Tag\n");
2525         return -1;
2526    }
2527
2528    elmtLen2 = BDecLen (b, &totalElmtsLen1 );
2529	rc = BDecComponentVersion (mem_op, b, tagId2, elmtLen2, (&k->version), &totalElmtsLen1, DEC_ALLOC_MODE_0 );
2530		if ( rc != LDAP_SUCCESS ) return rc;
2531		(k->version)->identifier.bv_val = (k->version)->id_buf;
2532		(k->version)->identifier.bv_len = strlen("version");
2533		strcpy( (k->version)->identifier.bv_val, "version");
2534	if (elmtLen1 == INDEFINITE_LEN)
2535        BDecEoc (b, &totalElmtsLen1 );
2536    tagId1 = BDecTag (b, &totalElmtsLen1);
2537    }
2538
2539
2540    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))))
2541    {
2542    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2543	rc = BDecComponentCertificateSerialNumber (mem_op, b, tagId1, elmtLen1, (&k->serialNumber), &totalElmtsLen1, mode);
2544		if ( rc != LDAP_SUCCESS ) return rc;
2545		(&k->serialNumber)->identifier.bv_val = (&k->serialNumber)->id_buf;
2546		(&k->serialNumber)->identifier.bv_len = strlen("serialNumber");
2547		strcpy( (&k->serialNumber)->identifier.bv_val, "serialNumber");
2548    tagId1 = BDecTag (b, &totalElmtsLen1);
2549    }
2550    else
2551        return -1;
2552
2553
2554
2555    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2556    {
2557    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2558	rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode);
2559		if ( rc != LDAP_SUCCESS ) return rc;
2560		(k->signature)->identifier.bv_val = (k->signature)->id_buf;
2561		(k->signature)->identifier.bv_len = strlen("signature");
2562		strcpy( (k->signature)->identifier.bv_val, "signature");
2563    tagId1 = BDecTag (b, &totalElmtsLen1);
2564    }
2565    else
2566        return -1;
2567
2568
2569
2570    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2571    {
2572        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2573	rc = BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->issuer), &totalElmtsLen1, mode);
2574		if ( rc != LDAP_SUCCESS ) return rc;
2575		(k->issuer)->identifier.bv_val = (k->issuer)->id_buf;
2576		(k->issuer)->identifier.bv_len = strlen("issuer");
2577		strcpy( (k->issuer)->identifier.bv_val, "issuer");
2578    tagId1 = BDecTag (b, &totalElmtsLen1);
2579    }
2580    else
2581        return -1;
2582
2583
2584
2585    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2586    {
2587    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2588	rc = BDecComponentValidity (mem_op, b, tagId1, elmtLen1, (&k->validity), &totalElmtsLen1, mode);
2589		if ( rc != LDAP_SUCCESS ) return rc;
2590		(k->validity)->identifier.bv_val = (k->validity)->id_buf;
2591		(k->validity)->identifier.bv_len = strlen("validity");
2592		strcpy( (k->validity)->identifier.bv_val, "validity");
2593    tagId1 = BDecTag (b, &totalElmtsLen1);
2594    }
2595    else
2596        return -1;
2597
2598
2599
2600    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2601    {
2602        elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2603	rc = BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->subject), &totalElmtsLen1, mode);
2604		if ( rc != LDAP_SUCCESS ) return rc;
2605		(k->subject)->identifier.bv_val = (k->subject)->id_buf;
2606		(k->subject)->identifier.bv_len = strlen("subject");
2607		strcpy( (k->subject)->identifier.bv_val, "subject");
2608    tagId1 = BDecTag (b, &totalElmtsLen1);
2609    }
2610    else
2611        return -1;
2612
2613
2614
2615    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2616    {
2617    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2618	rc = BDecComponentSubjectPublicKeyInfo (mem_op, b, tagId1, elmtLen1, (&k->subjectPublicKeyInfo), &totalElmtsLen1, mode);
2619		if ( rc != LDAP_SUCCESS ) return rc;
2620		(k->subjectPublicKeyInfo)->identifier.bv_val = (k->subjectPublicKeyInfo)->id_buf;
2621		(k->subjectPublicKeyInfo)->identifier.bv_len = strlen("subjectPublicKeyInfo");
2622		strcpy( (k->subjectPublicKeyInfo)->identifier.bv_val, "subjectPublicKeyInfo");
2623    if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
2624        seqDone = TRUE;
2625    else
2626    {
2627        tagId1 = BDecTag (b, &totalElmtsLen1 );
2628
2629         if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
2630        {
2631            BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
2632            seqDone = TRUE;
2633        }
2634    }
2635    }
2636    else
2637        return -1;
2638
2639
2640
2641    if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, PRIM, 1)) ||
2642(tagId1 == MAKE_TAG_ID (CNTX, CONS, 1))))
2643    {
2644    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2645	rc = BDecComponentUniqueIdentifier (mem_op, b, tagId1, elmtLen1, (&k->issuerUniqueIdentifier), &totalElmtsLen1, mode);
2646		if ( rc != LDAP_SUCCESS ) return rc;
2647		(&k->issuerUniqueIdentifier)->identifier.bv_val = (&k->issuerUniqueIdentifier)->id_buf;
2648		(&k->issuerUniqueIdentifier)->identifier.bv_len = strlen("issuerUniqueIdentifier");
2649		strcpy( (&k->issuerUniqueIdentifier)->identifier.bv_val, "issuerUniqueIdentifier");
2650    if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
2651        seqDone = TRUE;
2652    else
2653    {
2654        tagId1 = BDecTag (b, &totalElmtsLen1 );
2655
2656         if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
2657        {
2658            BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
2659            seqDone = TRUE;
2660        }
2661    }
2662    }
2663
2664
2665    if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, PRIM, 2)) ||
2666(tagId1 == MAKE_TAG_ID (CNTX, CONS, 2))))
2667    {
2668    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2669	rc = BDecComponentUniqueIdentifier (mem_op, b, tagId1, elmtLen1, (&k->subjectUniqueIdentifier), &totalElmtsLen1, mode);
2670		if ( rc != LDAP_SUCCESS ) return rc;
2671		(&k->subjectUniqueIdentifier)->identifier.bv_val = (&k->subjectUniqueIdentifier)->id_buf;
2672		(&k->subjectUniqueIdentifier)->identifier.bv_len = strlen("subjectUniqueIdentifier");
2673		strcpy( (&k->subjectUniqueIdentifier)->identifier.bv_val, "subjectUniqueIdentifier");
2674    if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
2675        seqDone = TRUE;
2676    else
2677    {
2678        tagId1 = BDecTag (b, &totalElmtsLen1 );
2679
2680         if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
2681        {
2682            BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
2683            seqDone = TRUE;
2684        }
2685    }
2686    }
2687
2688
2689    if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, CONS, 3))))
2690    {
2691    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2692        tagId2 = BDecTag (b, &totalElmtsLen1 );
2693
2694    if (tagId2 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
2695    {
2696         Asn1Error ("Unexpected Tag\n");
2697         return -1;
2698    }
2699
2700    elmtLen2 = BDecLen (b, &totalElmtsLen1 );
2701	rc = BDecComponentExtensions (mem_op, b, tagId2, elmtLen2, (&k->extensions), &totalElmtsLen1, mode);
2702		if ( rc != LDAP_SUCCESS ) return rc;
2703		(k->extensions)->identifier.bv_val = (k->extensions)->id_buf;
2704		(k->extensions)->identifier.bv_len = strlen("extensions");
2705		strcpy( (k->extensions)->identifier.bv_val, "extensions");
2706	if (elmtLen1 == INDEFINITE_LEN)
2707        BDecEoc (b, &totalElmtsLen1 );
2708        seqDone = TRUE;
2709        if (elmtLen0 == INDEFINITE_LEN)
2710            BDecEoc (b, &totalElmtsLen1 );
2711        else if (totalElmtsLen1 != elmtLen0)
2712        return -1;
2713
2714    }
2715
2716
2717    if (!seqDone)
2718        return -1;
2719
2720	if(!COMPONENTNOT_NULL ((k->version)))
2721	{
2722(k->version) = CompAlloc( mem_op, sizeof(ComponentVersion));
2723		(k->version)->identifier.bv_val = (k->version)->id_buf;
2724		(k->version)->identifier.bv_len = strlen("version");
2725		strcpy( (k->version)->identifier.bv_val, "version");
2726	(k->version)->value = 0;
2727	}
2728	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2729	*v = t = (ComponentTBSCertificate*) CompAlloc( mem_op, sizeof(ComponentTBSCertificate) );
2730	if ( !t ) return -1;
2731	*t = *k;
2732	}
2733	t->syntax = (Syntax*)NULL;
2734	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2735	if ( !t->comp_desc ) {
2736		free ( t );
2737		return -1;
2738	}
2739	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertificate ;
2740	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertificate ;
2741	t->comp_desc->cd_free = (comp_free_func*)NULL;
2742	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate;
2743	t->comp_desc->cd_type = ASN_COMPOSITE;
2744	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
2745	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertificate;
2746    (*bytesDecoded) += totalElmtsLen1;
2747	return LDAP_SUCCESS;
2748}  /* BDecTBSCertificate*/
2749
2750int
2751GDecComponentTBSCertificate PARAMS (( mem_op,b, v, bytesDecoded, mode),
2752void* mem_op _AND_
2753GenBuf * b _AND_
2754ComponentTBSCertificate **v _AND_
2755AsnLen *bytesDecoded _AND_
2756int mode)
2757{
2758	char* peek_head,*peek_head2;
2759	int i, strLen,strLen2, rc, old_mode = mode;
2760	ComponentTBSCertificate *k,*t, c_temp;
2761
2762
2763	if ( !(mode & DEC_ALLOC_MODE_1) ) {
2764		memset(&c_temp,0,sizeof(c_temp));
2765		 k = &c_temp;
2766	} else
2767		 k = t = *v;
2768	mode = DEC_ALLOC_MODE_2;
2769	*bytesDecoded = 0;
2770	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2771		Asn1Error("Error during Reading { in encoded data");
2772		return LDAP_PROTOCOL_ERROR;
2773	}
2774	if(*peek_head != '{'){
2775		Asn1Error("Missing { in encoded data");
2776		return LDAP_PROTOCOL_ERROR;
2777	}
2778
2779	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2780		Asn1Error("Error during Reading identifier");
2781		return LDAP_PROTOCOL_ERROR;
2782	}
2783	if ( strncmp( peek_head, "version", strlen("version") ) == 0 ) {
2784		rc = 	GDecComponentVersion (mem_op, b, (&k->version), bytesDecoded, DEC_ALLOC_MODE_0 );
2785		if ( rc != LDAP_SUCCESS ) return rc;
2786	( k->version)->identifier.bv_val = peek_head;
2787	( k->version)->identifier.bv_len = strLen;
2788	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2789		Asn1Error("Error during Reading , ");
2790		return LDAP_PROTOCOL_ERROR;
2791	}
2792	if(*peek_head != ','){
2793		Asn1Error("Missing , in encoding");
2794		return LDAP_PROTOCOL_ERROR;
2795	}
2796	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2797	  Asn1Error("Error during Reading identifier");
2798		return LDAP_PROTOCOL_ERROR;
2799	}
2800	}
2801	else {
2802(k->version) = CompAlloc( mem_op, sizeof(ComponentVersion));
2803			(k->version)->value = 0;
2804	}
2805	if ( strncmp( peek_head, "serialNumber", strlen("serialNumber") ) == 0 ) {
2806		rc = 	GDecComponentCertificateSerialNumber (mem_op, b, (&k->serialNumber), bytesDecoded, mode);
2807		if ( rc != LDAP_SUCCESS ) return rc;
2808	(&k->serialNumber)->identifier.bv_val = peek_head;
2809	(&k->serialNumber)->identifier.bv_len = strLen;
2810	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2811		Asn1Error("Error during Reading , ");
2812		return LDAP_PROTOCOL_ERROR;
2813	}
2814	if(*peek_head != ','){
2815		Asn1Error("Missing , in encoding");
2816		return LDAP_PROTOCOL_ERROR;
2817	}
2818	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2819	  Asn1Error("Error during Reading identifier");
2820		return LDAP_PROTOCOL_ERROR;
2821	}
2822	}
2823	if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) {
2824		rc = 	GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signature), bytesDecoded, mode);
2825		if ( rc != LDAP_SUCCESS ) return rc;
2826	( k->signature)->identifier.bv_val = peek_head;
2827	( k->signature)->identifier.bv_len = strLen;
2828	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2829		Asn1Error("Error during Reading , ");
2830		return LDAP_PROTOCOL_ERROR;
2831	}
2832	if(*peek_head != ','){
2833		Asn1Error("Missing , in encoding");
2834		return LDAP_PROTOCOL_ERROR;
2835	}
2836	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2837	  Asn1Error("Error during Reading identifier");
2838		return LDAP_PROTOCOL_ERROR;
2839	}
2840	}
2841	if ( strncmp( peek_head, "issuer", strlen("issuer") ) == 0 ) {
2842		rc = 	GDecComponentName (mem_op, b, (&k->issuer), bytesDecoded, mode);
2843		if ( rc != LDAP_SUCCESS ) return rc;
2844	( k->issuer)->identifier.bv_val = peek_head;
2845	( k->issuer)->identifier.bv_len = strLen;
2846	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2847		Asn1Error("Error during Reading , ");
2848		return LDAP_PROTOCOL_ERROR;
2849	}
2850	if(*peek_head != ','){
2851		Asn1Error("Missing , in encoding");
2852		return LDAP_PROTOCOL_ERROR;
2853	}
2854	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2855	  Asn1Error("Error during Reading identifier");
2856		return LDAP_PROTOCOL_ERROR;
2857	}
2858	}
2859	if ( strncmp( peek_head, "validity", strlen("validity") ) == 0 ) {
2860		rc = 	GDecComponentValidity (mem_op, b, (&k->validity), bytesDecoded, mode);
2861		if ( rc != LDAP_SUCCESS ) return rc;
2862	( k->validity)->identifier.bv_val = peek_head;
2863	( k->validity)->identifier.bv_len = strLen;
2864	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2865		Asn1Error("Error during Reading , ");
2866		return LDAP_PROTOCOL_ERROR;
2867	}
2868	if(*peek_head != ','){
2869		Asn1Error("Missing , in encoding");
2870		return LDAP_PROTOCOL_ERROR;
2871	}
2872	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2873	  Asn1Error("Error during Reading identifier");
2874		return LDAP_PROTOCOL_ERROR;
2875	}
2876	}
2877	if ( strncmp( peek_head, "subject", strlen("subject") ) == 0 ) {
2878		rc = 	GDecComponentName (mem_op, b, (&k->subject), bytesDecoded, mode);
2879		if ( rc != LDAP_SUCCESS ) return rc;
2880	( k->subject)->identifier.bv_val = peek_head;
2881	( k->subject)->identifier.bv_len = strLen;
2882	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2883		Asn1Error("Error during Reading , ");
2884		return LDAP_PROTOCOL_ERROR;
2885	}
2886	if(*peek_head != ','){
2887		Asn1Error("Missing , in encoding");
2888		return LDAP_PROTOCOL_ERROR;
2889	}
2890	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2891	  Asn1Error("Error during Reading identifier");
2892		return LDAP_PROTOCOL_ERROR;
2893	}
2894	}
2895	if ( strncmp( peek_head, "subjectPublicKeyInfo", strlen("subjectPublicKeyInfo") ) == 0 ) {
2896		rc = 	GDecComponentSubjectPublicKeyInfo (mem_op, b, (&k->subjectPublicKeyInfo), bytesDecoded, mode);
2897		if ( rc != LDAP_SUCCESS ) return rc;
2898	( k->subjectPublicKeyInfo)->identifier.bv_val = peek_head;
2899	( k->subjectPublicKeyInfo)->identifier.bv_len = strLen;
2900	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2901		Asn1Error("Error during Reading , ");
2902		return LDAP_PROTOCOL_ERROR;
2903	}
2904	if(*peek_head != ','){
2905		Asn1Error("Missing , in encoding");
2906		return LDAP_PROTOCOL_ERROR;
2907	}
2908	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2909	  Asn1Error("Error during Reading identifier");
2910		return LDAP_PROTOCOL_ERROR;
2911	}
2912	}
2913	if ( strncmp( peek_head, "issuerUniqueIdentifier", strlen("issuerUniqueIdentifier") ) == 0 ) {
2914		rc = 	GDecComponentUniqueIdentifier (mem_op, b, (&k->issuerUniqueIdentifier), bytesDecoded, mode);
2915		if ( rc != LDAP_SUCCESS ) return rc;
2916	(&k->issuerUniqueIdentifier)->identifier.bv_val = peek_head;
2917	(&k->issuerUniqueIdentifier)->identifier.bv_len = strLen;
2918	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2919		Asn1Error("Error during Reading , ");
2920		return LDAP_PROTOCOL_ERROR;
2921	}
2922	if(*peek_head != ','){
2923		Asn1Error("Missing , in encoding");
2924		return LDAP_PROTOCOL_ERROR;
2925	}
2926	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2927	  Asn1Error("Error during Reading identifier");
2928		return LDAP_PROTOCOL_ERROR;
2929	}
2930	}
2931	if ( strncmp( peek_head, "subjectUniqueIdentifier", strlen("subjectUniqueIdentifier") ) == 0 ) {
2932		rc = 	GDecComponentUniqueIdentifier (mem_op, b, (&k->subjectUniqueIdentifier), bytesDecoded, mode);
2933		if ( rc != LDAP_SUCCESS ) return rc;
2934	(&k->subjectUniqueIdentifier)->identifier.bv_val = peek_head;
2935	(&k->subjectUniqueIdentifier)->identifier.bv_len = strLen;
2936	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2937		Asn1Error("Error during Reading , ");
2938		return LDAP_PROTOCOL_ERROR;
2939	}
2940	if(*peek_head != ','){
2941		Asn1Error("Missing , in encoding");
2942		return LDAP_PROTOCOL_ERROR;
2943	}
2944	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2945	  Asn1Error("Error during Reading identifier");
2946		return LDAP_PROTOCOL_ERROR;
2947	}
2948	}
2949	if ( strncmp( peek_head, "extensions", strlen("extensions") ) == 0 ) {
2950		rc = 	GDecComponentExtensions (mem_op, b, (&k->extensions), bytesDecoded, mode);
2951		if ( rc != LDAP_SUCCESS ) return rc;
2952	( k->extensions)->identifier.bv_val = peek_head;
2953	( k->extensions)->identifier.bv_len = strLen;
2954	}
2955	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
2956		Asn1Error("Error during Reading } in encoding");
2957		return LDAP_PROTOCOL_ERROR;
2958	}
2959	if(*peek_head != '}'){
2960		Asn1Error("Missing } in encoding");
2961		return LDAP_PROTOCOL_ERROR;
2962	}
2963	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2964	*v = t = (ComponentTBSCertificate*) CompAlloc( mem_op, sizeof(ComponentTBSCertificate) );
2965	if ( !t ) return -1;
2966	*t = *k;
2967	}
2968	t->syntax = (Syntax*)NULL;
2969	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2970	if ( !t->comp_desc ) {
2971		free ( t );
2972		return -1;
2973	}
2974	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertificate ;
2975	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertificate ;
2976	t->comp_desc->cd_free = (comp_free_func*)NULL;
2977	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate;
2978	t->comp_desc->cd_type = ASN_COMPOSITE;
2979	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
2980	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertificate;
2981	return LDAP_SUCCESS;
2982}  /* GDecTBSCertificate*/
2983
2984
2985int
2986MatchingComponentCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
2987	int rc;
2988	MatchingRule* mr;
2989
2990	if ( oid ) {
2991		mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
2992		if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
2993	}
2994
2995	rc = 1;
2996	rc =	MatchingComponentTBSCertificate ( oid, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_attr)->toBeSigned, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_assert)->toBeSigned );
2997	if ( rc != LDAP_COMPARE_TRUE )
2998		return rc;
2999	rc =	MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_attr)->signatureAlgorithm, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_assert)->signatureAlgorithm );
3000	if ( rc != LDAP_COMPARE_TRUE )
3001		return rc;
3002	rc =	MatchingComponentBits ( oid, (ComponentSyntaxInfo*)&((ComponentCertificate*)csi_attr)->signature, (ComponentSyntaxInfo*)&((ComponentCertificate*)csi_assert)->signature );
3003	if ( rc != LDAP_COMPARE_TRUE )
3004		return rc;
3005	return LDAP_COMPARE_TRUE;
3006}  /* BMatchingComponentCertificate */
3007
3008void*
3009ExtractingComponentCertificate ( void* mem_op, ComponentReference* cr, ComponentCertificate *comp )
3010{
3011
3012	if ( ( comp->toBeSigned->identifier.bv_val && strncmp(comp->toBeSigned->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->toBeSigned->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
3013		if ( cr->cr_curr->ci_next == NULL )
3014			return comp->toBeSigned;
3015		else {
3016			cr->cr_curr = cr->cr_curr->ci_next;
3017			return 	ExtractingComponentTBSCertificate ( mem_op, cr, comp->toBeSigned );
3018		}
3019	}
3020	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 ) ) {
3021		if ( cr->cr_curr->ci_next == NULL )
3022			return comp->signatureAlgorithm;
3023		else {
3024			cr->cr_curr = cr->cr_curr->ci_next;
3025			return 	ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signatureAlgorithm );
3026		}
3027	}
3028	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 ) ) {
3029		if ( cr->cr_curr->ci_next == NULL )
3030		return &comp->signature;
3031	else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
3032			cr->cr_curr = cr->cr_curr->ci_next;
3033		return &comp->signature;
3034	 } else {
3035		return NULL;
3036		}
3037	}
3038	return NULL;
3039}  /* ExtractingComponentCertificate */
3040
3041int
3042BDecComponentCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
3043void* mem_op _AND_
3044GenBuf * b _AND_
3045AsnTag tagId0 _AND_
3046AsnLen elmtLen0 _AND_
3047ComponentCertificate **v _AND_
3048AsnLen *bytesDecoded _AND_
3049int mode)
3050{
3051	int seqDone = FALSE;
3052	AsnLen totalElmtsLen1 = 0;
3053	AsnLen elmtLen1;
3054	AsnTag tagId1;
3055	int mandatoryElmtCount1 = 0;
3056	int old_mode = mode;
3057	int rc;
3058	ComponentCertificate *k, *t, c_temp;
3059
3060
3061	if ( !(mode & DEC_ALLOC_MODE_1) ) {
3062		memset(&c_temp,0,sizeof(c_temp));
3063		 k = &c_temp;
3064	} else
3065		 k = t = *v;
3066	mode = DEC_ALLOC_MODE_2;
3067    tagId1 = BDecTag (b, &totalElmtsLen1 );
3068
3069    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
3070    {
3071    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
3072	rc = BDecComponentTBSCertificate (mem_op, b, tagId1, elmtLen1, (&k->toBeSigned), &totalElmtsLen1, mode);
3073		if ( rc != LDAP_SUCCESS ) return rc;
3074		(k->toBeSigned)->identifier.bv_val = (k->toBeSigned)->id_buf;
3075		(k->toBeSigned)->identifier.bv_len = strlen("toBeSigned");
3076		strcpy( (k->toBeSigned)->identifier.bv_val, "toBeSigned");
3077    tagId1 = BDecTag (b, &totalElmtsLen1);
3078    }
3079    else
3080        return -1;
3081
3082
3083
3084    if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
3085    {
3086    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
3087	rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signatureAlgorithm), &totalElmtsLen1, mode);
3088		if ( rc != LDAP_SUCCESS ) return rc;
3089		(k->signatureAlgorithm)->identifier.bv_val = (k->signatureAlgorithm)->id_buf;
3090		(k->signatureAlgorithm)->identifier.bv_len = strlen("signatureAlgorithm");
3091		strcpy( (k->signatureAlgorithm)->identifier.bv_val, "signatureAlgorithm");
3092    tagId1 = BDecTag (b, &totalElmtsLen1);
3093    }
3094    else
3095        return -1;
3096
3097
3098
3099    if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE)) ||
3100(tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE))))
3101    {
3102    elmtLen1 = BDecLen (b, &totalElmtsLen1 );
3103	rc = BDecComponentBits (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode);
3104		if ( rc != LDAP_SUCCESS ) return rc;
3105		(&k->signature)->identifier.bv_val = (&k->signature)->id_buf;
3106		(&k->signature)->identifier.bv_len = strlen("signature");
3107		strcpy( (&k->signature)->identifier.bv_val, "signature");
3108        seqDone = TRUE;
3109        if (elmtLen0 == INDEFINITE_LEN)
3110            BDecEoc (b, &totalElmtsLen1 );
3111        else if (totalElmtsLen1 != elmtLen0)
3112        return -1;
3113
3114    }
3115    else
3116        return -1;
3117
3118
3119
3120    if (!seqDone)
3121        return -1;
3122
3123	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
3124	*v = t = (ComponentCertificate*) CompAlloc( mem_op, sizeof(ComponentCertificate) );
3125	if ( !t ) return -1;
3126	*t = *k;
3127	}
3128	t->syntax = (Syntax*)NULL;
3129	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
3130	if ( !t->comp_desc ) {
3131		free ( t );
3132		return -1;
3133	}
3134	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificate ;
3135	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificate ;
3136	t->comp_desc->cd_free = (comp_free_func*)NULL;
3137	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate;
3138	t->comp_desc->cd_type = ASN_COMPOSITE;
3139	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
3140	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificate;
3141    (*bytesDecoded) += totalElmtsLen1;
3142	return LDAP_SUCCESS;
3143}  /* BDecCertificate*/
3144
3145int
3146GDecComponentCertificate PARAMS (( mem_op,b, v, bytesDecoded, mode),
3147void* mem_op _AND_
3148GenBuf * b _AND_
3149ComponentCertificate **v _AND_
3150AsnLen *bytesDecoded _AND_
3151int mode)
3152{
3153	char* peek_head,*peek_head2;
3154	int i, strLen,strLen2, rc, old_mode = mode;
3155	ComponentCertificate *k,*t, c_temp;
3156
3157
3158	if ( !(mode & DEC_ALLOC_MODE_1) ) {
3159		memset(&c_temp,0,sizeof(c_temp));
3160		 k = &c_temp;
3161	} else
3162		 k = t = *v;
3163	mode = DEC_ALLOC_MODE_2;
3164	*bytesDecoded = 0;
3165	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3166		Asn1Error("Error during Reading { in encoded data");
3167		return LDAP_PROTOCOL_ERROR;
3168	}
3169	if(*peek_head != '{'){
3170		Asn1Error("Missing { in encoded data");
3171		return LDAP_PROTOCOL_ERROR;
3172	}
3173
3174	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3175		Asn1Error("Error during Reading identifier");
3176		return LDAP_PROTOCOL_ERROR;
3177	}
3178	if ( strncmp( peek_head, "toBeSigned", strlen("toBeSigned") ) == 0 ) {
3179		rc = 	GDecComponentTBSCertificate (mem_op, b, (&k->toBeSigned), bytesDecoded, mode);
3180		if ( rc != LDAP_SUCCESS ) return rc;
3181	( k->toBeSigned)->identifier.bv_val = peek_head;
3182	( k->toBeSigned)->identifier.bv_len = strLen;
3183	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3184		Asn1Error("Error during Reading , ");
3185		return LDAP_PROTOCOL_ERROR;
3186	}
3187	if(*peek_head != ','){
3188		Asn1Error("Missing , in encoding");
3189		return LDAP_PROTOCOL_ERROR;
3190	}
3191	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3192	  Asn1Error("Error during Reading identifier");
3193		return LDAP_PROTOCOL_ERROR;
3194	}
3195	}
3196	if ( strncmp( peek_head, "signatureAlgorithm", strlen("signatureAlgorithm") ) == 0 ) {
3197		rc = 	GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signatureAlgorithm), bytesDecoded, mode);
3198		if ( rc != LDAP_SUCCESS ) return rc;
3199	( k->signatureAlgorithm)->identifier.bv_val = peek_head;
3200	( k->signatureAlgorithm)->identifier.bv_len = strLen;
3201	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3202		Asn1Error("Error during Reading , ");
3203		return LDAP_PROTOCOL_ERROR;
3204	}
3205	if(*peek_head != ','){
3206		Asn1Error("Missing , in encoding");
3207		return LDAP_PROTOCOL_ERROR;
3208	}
3209	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3210	  Asn1Error("Error during Reading identifier");
3211		return LDAP_PROTOCOL_ERROR;
3212	}
3213	}
3214	if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) {
3215		rc = 	GDecComponentBits (mem_op, b, (&k->signature), bytesDecoded, mode);
3216		if ( rc != LDAP_SUCCESS ) return rc;
3217	(&k->signature)->identifier.bv_val = peek_head;
3218	(&k->signature)->identifier.bv_len = strLen;
3219	}
3220	if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
3221		Asn1Error("Error during Reading } in encoding");
3222		return LDAP_PROTOCOL_ERROR;
3223	}
3224	if(*peek_head != '}'){
3225		Asn1Error("Missing } in encoding");
3226		return LDAP_PROTOCOL_ERROR;
3227	}
3228	if( !(old_mode & DEC_ALLOC_MODE_1) ) {
3229	*v = t = (ComponentCertificate*) CompAlloc( mem_op, sizeof(ComponentCertificate) );
3230	if ( !t ) return -1;
3231	*t = *k;
3232	}
3233	t->syntax = (Syntax*)NULL;
3234	t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
3235	if ( !t->comp_desc ) {
3236		free ( t );
3237		return -1;
3238	}
3239	t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificate ;
3240	t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificate ;
3241	t->comp_desc->cd_free = (comp_free_func*)NULL;
3242	t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate;
3243	t->comp_desc->cd_type = ASN_COMPOSITE;
3244	t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
3245	t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificate;
3246	return LDAP_SUCCESS;
3247}  /* GDecCertificate*/
3248
3249
3250