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