]> git.sur5r.net Git - openldap/blob - contrib/slapd-modules/comp_match/certificate.c
1) <select> and <content> type component reference support
[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, (ComponentSyntaxInfo*)v,(int*)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, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_attr)->parameters, (ComponentSyntaxInfo*)&((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, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_attr)->value, (ComponentSyntaxInfo*)&((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 = NULL;
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 = NULL;
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         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeDistinguishedName ;
1837         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeDistinguishedName ;
1838         t->comp_desc->cd_free = (comp_free_func*)NULL;
1839         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName;
1840         t->comp_desc->cd_type = ASN_COMPOSITE;
1841         t->comp_desc->cd_type_id = RelativeDistinguishedName;
1842         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeDistinguishedName;
1843     (*bytesDecoded) += totalElmtsLen1;
1844         return LDAP_SUCCESS;
1845 }  /* BDecRelativeDistinguishedNameContent */
1846
1847 int
1848 GDecComponentRelativeDistinguishedName PARAMS (( mem_op,b, v, bytesDecoded, mode),
1849 void* mem_op _AND_
1850 GenBuf * b _AND_
1851 ComponentRelativeDistinguishedName **v _AND_
1852 AsnLen *bytesDecoded _AND_
1853 int mode)
1854 {
1855         char* peek_head,*peek_head2;
1856         int i, strLen,strLen2, rc, old_mode = mode;
1857         ComponentRelativeDistinguishedName *k,*t, c_temp;
1858
1859
1860         int ElmtsLen1;
1861         if ( !(mode & DEC_ALLOC_MODE_1) ) {
1862                 memset(&c_temp,0,sizeof(c_temp));
1863                  k = &c_temp;
1864         } else
1865                  k = t = *v;
1866         mode = DEC_ALLOC_MODE_2;
1867         AsnListInit( &k->comp_list, sizeof( ComponentAttributeTypeAndValue ) );
1868         *bytesDecoded = 0;
1869         if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){
1870                 Asn1Error("Error during Reading { in encoding");
1871                 return LDAP_PROTOCOL_ERROR;
1872         }
1873         if(*peek_head != '{'){
1874                 Asn1Error("Missing { in encoded data");
1875                 return LDAP_PROTOCOL_ERROR;
1876         }
1877
1878         for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++)
1879         {
1880                 ComponentAttributeTypeAndValue **tmpVar;
1881                 if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){
1882                         Asn1Error("Error during Reading{ in encoding");
1883                         return LDAP_PROTOCOL_ERROR;
1884                 }
1885                 if(*peek_head == '}') break;
1886                 if( !(*peek_head == '{' || *peek_head ==',') ) {
1887                         return LDAP_PROTOCOL_ERROR;
1888                 }
1889                 tmpVar = (ComponentAttributeTypeAndValue**) CompAsnListAppend (mem_op, &k->comp_list);
1890                 if ( tmpVar == NULL ) {
1891                         Asn1Error("Error during Reading{ in encoding");
1892                         return LDAP_PROTOCOL_ERROR;
1893                 }
1894                 rc =    GDecComponentAttributeTypeAndValue (mem_op, b, tmpVar, bytesDecoded, mode);
1895                 if ( rc != LDAP_SUCCESS ) return rc;
1896         } /* end of for */
1897
1898         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
1899         *v = t = (ComponentRelativeDistinguishedName*) CompAlloc( mem_op, sizeof(ComponentRelativeDistinguishedName) );
1900         if ( !t ) return -1;
1901         *t = *k;
1902         }
1903         t->syntax = (Syntax*)NULL;
1904         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1905         if ( !t->comp_desc ) {
1906                 free ( t );
1907                 return -1;
1908         }
1909         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeDistinguishedName ;
1910         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeDistinguishedName ;
1911         t->comp_desc->cd_free = (comp_free_func*)NULL;
1912         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName;
1913         t->comp_desc->cd_type = ASN_COMPOSITE;
1914         t->comp_desc->cd_type_id = RelativeDistinguishedName;
1915         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeDistinguishedName;
1916         return LDAP_SUCCESS;
1917 }  /* GDecRelativeDistinguishedNameContent */
1918
1919
1920 int
1921 MatchingComponentRDNSequence ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
1922         int rc;
1923         MatchingRule* mr;
1924         void* component1, *component2;
1925         AsnList *v1, *v2, t_list;
1926
1927
1928         if ( oid ) {
1929                 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
1930                 if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
1931         }
1932
1933         v1 = &((ComponentRDNSequence*)csi_attr)->comp_list;
1934         v2 = &((ComponentRDNSequence*)csi_assert)->comp_list;
1935         FOR_EACH_LIST_PAIR_ELMT(component1, component2, v1, v2)
1936         {
1937                 if( MatchingComponentRelativeDistinguishedName(oid, (ComponentSyntaxInfo*)component1, (ComponentSyntaxInfo*)component2) == LDAP_COMPARE_FALSE) {
1938                         return LDAP_COMPARE_FALSE;
1939                 }
1940         } /* end of for */
1941
1942         AsnListFirst( v1 );
1943         AsnListFirst( v2 );
1944         if( (!component1 && component2) || (component1 && !component2))
1945                 return LDAP_COMPARE_FALSE;
1946         else
1947                 return LDAP_COMPARE_TRUE;
1948 }  /* BMatchingComponentRDNSequenceContent */
1949
1950 void*
1951 ExtractingComponentRDNSequence ( void* mem_op, ComponentReference* cr, ComponentRDNSequence *comp )
1952 {
1953         int count = 0;
1954         int total;
1955         AsnList *v = &comp->comp_list;
1956         ComponentInt *k;
1957         ComponentRelativeDistinguishedName *component;
1958
1959
1960         switch ( cr->cr_curr->ci_type ) {
1961         case LDAP_COMPREF_FROM_BEGINNING :
1962                 count = cr->cr_curr->ci_val.ci_from_beginning;
1963                 FOR_EACH_LIST_ELMT( component , v ) {
1964                         if( --count == 0 ) {
1965                                 if( cr->cr_curr->ci_next == NULL )
1966                                         return component;
1967                                 else {
1968                                         cr->cr_curr = cr->cr_curr->ci_next;
1969                                         return  ExtractingComponentRelativeDistinguishedName ( mem_op, cr, component );
1970                                 }
1971                         }
1972                 }
1973                 break;
1974         case LDAP_COMPREF_FROM_END :
1975                 total = AsnListCount ( v );
1976                 count = cr->cr_curr->ci_val.ci_from_end;
1977                 count = total + count +1;
1978                 FOR_EACH_LIST_ELMT ( component, v ) {
1979                         if( --count == 0 ) {
1980                                 if( cr->cr_curr->ci_next == NULL ) 
1981                                         return component;
1982                                 else {
1983                                         cr->cr_curr = cr->cr_curr->ci_next;
1984                                         return  ExtractingComponentRelativeDistinguishedName ( mem_op, cr, component );
1985                                 }
1986                         }
1987                 }
1988                 break;
1989         case LDAP_COMPREF_ALL :
1990                 return comp;
1991         case LDAP_COMPREF_COUNT :
1992                 k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt));
1993                 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1994                 k->comp_desc->cd_tag = NULL;
1995                 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
1996                 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
1997                 k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL;
1998                 k->comp_desc->cd_type = ASN_BASIC;
1999                 k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
2000                 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
2001                 k->value = AsnListCount(v);
2002                 return k;
2003         default :
2004                 return NULL;
2005         }
2006 }  /* ExtractingComponentRDNSequence */
2007
2008 int
2009 BDecComponentRDNSequence PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
2010 void* mem_op _AND_
2011 GenBuf * b _AND_
2012 AsnTag tagId0 _AND_
2013 AsnLen elmtLen0 _AND_
2014 ComponentRDNSequence **v _AND_
2015 AsnLen *bytesDecoded _AND_
2016 int mode)
2017 {
2018         int seqDone = FALSE;
2019         AsnLen totalElmtsLen1 = 0;
2020         AsnLen elmtLen1;
2021         AsnTag tagId1;
2022         int mandatoryElmtCount1 = 0;
2023         int old_mode = mode;
2024         int rc;
2025         ComponentRDNSequence *k, *t, c_temp;
2026
2027
2028         if ( !(mode & DEC_ALLOC_MODE_1) ) {
2029                 memset(&c_temp,0,sizeof(c_temp));
2030                  k = &c_temp;
2031         } else
2032                  k = t = *v;
2033         mode = DEC_ALLOC_MODE_2;
2034         AsnListInit(&k->comp_list,sizeof(ComponentRelativeDistinguishedName));
2035     for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);)
2036     {
2037         ComponentRelativeDistinguishedName **tmpVar;
2038     tagId1 = BDecTag (b, &totalElmtsLen1 );
2039
2040     if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
2041     {
2042         BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
2043         break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/
2044     }
2045     if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE)))
2046     {
2047         elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2048     tmpVar = (ComponentRelativeDistinguishedName**) CompAsnListAppend (mem_op,&k->comp_list);
2049         rc = BDecComponentRelativeDistinguishedName (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode);
2050                 if ( rc != LDAP_SUCCESS ) return rc;
2051     }  /* end of tag check if */
2052     else  /* wrong tag */
2053     {
2054          Asn1Error ("Unexpected Tag\n");
2055          return -1;
2056     }
2057     } /* end of for */
2058
2059         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2060         *v = t = (ComponentRDNSequence*) CompAlloc( mem_op, sizeof(ComponentRDNSequence) );
2061         if ( !t ) return -1;
2062         *t = *k;
2063         }
2064         t->syntax = (Syntax*)NULL;
2065         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2066         if ( !t->comp_desc ) {
2067                 free ( t );
2068                 return -1;
2069         }
2070         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRDNSequence ;
2071         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRDNSequence ;
2072         t->comp_desc->cd_free = (comp_free_func*)NULL;
2073         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence;
2074         t->comp_desc->cd_type = ASN_COMPOSITE;
2075         t->comp_desc->cd_type_id = RDNSequence;
2076         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRDNSequence;
2077     (*bytesDecoded) += totalElmtsLen1;
2078         return LDAP_SUCCESS;
2079 }  /* BDecRDNSequenceContent */
2080
2081 int
2082 GDecComponentRDNSequence PARAMS (( mem_op,b, v, bytesDecoded, mode),
2083 void* mem_op _AND_
2084 GenBuf * b _AND_
2085 ComponentRDNSequence **v _AND_
2086 AsnLen *bytesDecoded _AND_
2087 int mode)
2088 {
2089         char* peek_head,*peek_head2;
2090         int i, strLen,strLen2, rc, old_mode = mode;
2091         ComponentRDNSequence *k,*t, c_temp;
2092
2093
2094         int ElmtsLen1;
2095         if ( !(mode & DEC_ALLOC_MODE_1) ) {
2096                 memset(&c_temp,0,sizeof(c_temp));
2097                  k = &c_temp;
2098         } else
2099                  k = t = *v;
2100         mode = DEC_ALLOC_MODE_2;
2101         AsnListInit( &k->comp_list, sizeof( ComponentRelativeDistinguishedName ) );
2102         *bytesDecoded = 0;
2103         if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){
2104                 Asn1Error("Error during Reading { in encoding");
2105                 return LDAP_PROTOCOL_ERROR;
2106         }
2107         if(*peek_head != '{'){
2108                 Asn1Error("Missing { in encoded data");
2109                 return LDAP_PROTOCOL_ERROR;
2110         }
2111
2112         for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++)
2113         {
2114                 ComponentRelativeDistinguishedName **tmpVar;
2115                 if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){
2116                         Asn1Error("Error during Reading{ in encoding");
2117                         return LDAP_PROTOCOL_ERROR;
2118                 }
2119                 if(*peek_head == '}') break;
2120                 if( !(*peek_head == '{' || *peek_head ==',') ) {
2121                         return LDAP_PROTOCOL_ERROR;
2122                 }
2123                 tmpVar = (ComponentRelativeDistinguishedName**) CompAsnListAppend (mem_op, &k->comp_list);
2124                 if ( tmpVar == NULL ) {
2125                         Asn1Error("Error during Reading{ in encoding");
2126                         return LDAP_PROTOCOL_ERROR;
2127                 }
2128                 rc =    GDecComponentRelativeDistinguishedName (mem_op, b, tmpVar, bytesDecoded, mode);
2129                 if ( rc != LDAP_SUCCESS ) return rc;
2130         } /* end of for */
2131
2132         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2133         *v = t = (ComponentRDNSequence*) CompAlloc( mem_op, sizeof(ComponentRDNSequence) );
2134         if ( !t ) return -1;
2135         *t = *k;
2136         }
2137         t->syntax = (Syntax*)NULL;
2138         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2139         if ( !t->comp_desc ) {
2140                 free ( t );
2141                 return -1;
2142         }
2143         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRDNSequence ;
2144         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRDNSequence ;
2145         t->comp_desc->cd_free = (comp_free_func*)NULL;
2146         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence;
2147         t->comp_desc->cd_type = ASN_COMPOSITE;
2148         t->comp_desc->cd_type_id = RDNSequence ;
2149         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRDNSequence;
2150         return LDAP_SUCCESS;
2151 }  /* GDecRDNSequenceContent */
2152
2153
2154 int
2155 MatchingComponentName ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
2156         int rc;
2157         MatchingRule* mr;
2158         ComponentName *v1, *v2;
2159
2160
2161         v1 = (ComponentName*)csi_attr;
2162         v2 = (ComponentName*)csi_assert;
2163         if ( oid ) {
2164                 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
2165                 if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
2166         }
2167
2168         if( (v1->choiceId != v2->choiceId ) )
2169                 return LDAP_COMPARE_FALSE;
2170         switch( v1->choiceId )
2171         {
2172            case NAME_RDNSEQUENCE :
2173                 rc =    MatchingComponentRDNSequence ( oid, (ComponentSyntaxInfo*)(v1->a.rdnSequence), (ComponentSyntaxInfo*)(v2->a.rdnSequence) );
2174                 break;
2175         default : 
2176                  return LDAP_PROTOCOL_ERROR;
2177         }
2178         return rc;
2179 }  /* BMatchingComponentNameContent */
2180
2181 void*
2182 ExtractingComponentName ( void* mem_op, ComponentReference* cr, ComponentName *comp )
2183 {
2184
2185
2186         if( (comp->choiceId) ==  NAME_RDNSEQUENCE &&
2187                  (( 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) ||
2188                  ( 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))) {
2189                 if ( cr->cr_curr->ci_next == NULL )
2190                         return (comp->a.rdnSequence);
2191                 else {
2192                         cr->cr_curr = cr->cr_curr->ci_next;
2193                         return  ExtractingComponentRDNSequence ( mem_op, cr, (comp->a.rdnSequence) );
2194                 };
2195         }
2196         return NULL;
2197 }  /* ExtractingComponentName */
2198
2199 int
2200 BDecComponentName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
2201 void* mem_op _AND_
2202 GenBuf * b _AND_
2203 AsnTag tagId0 _AND_
2204 AsnLen elmtLen0 _AND_
2205 ComponentName **v _AND_
2206 AsnLen *bytesDecoded _AND_
2207 int mode)
2208 {
2209         int seqDone = FALSE;
2210         AsnLen totalElmtsLen1 = 0;
2211         AsnLen elmtLen1;
2212         AsnTag tagId1;
2213         int mandatoryElmtCount1 = 0;
2214         int old_mode = mode;
2215         int rc;
2216         ComponentName *k, *t, c_temp;
2217
2218
2219         if ( !(mode & DEC_ALLOC_MODE_1) ) {
2220                 memset(&c_temp,0,sizeof(c_temp));
2221                  k = &c_temp;
2222         } else
2223                  k = t = *v;
2224         mode = DEC_ALLOC_MODE_2;
2225     switch (tagId0)
2226     {
2227        case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
2228         (k->choiceId) = NAME_RDNSEQUENCE;
2229         rc = BDecComponentRDNSequence (mem_op, b, tagId0, elmtLen0, (&k->a.rdnSequence), &totalElmtsLen1, mode);
2230                 if ( rc != LDAP_SUCCESS ) return rc;
2231                 (k->a.rdnSequence)->identifier.bv_val = (k->a.rdnSequence)->id_buf;
2232                 (k->a.rdnSequence)->identifier.bv_len = strlen("rdnSequence");
2233                 strcpy( (k->a.rdnSequence)->identifier.bv_val, "rdnSequence");
2234     break;
2235
2236     default:
2237         Asn1Error ("ERROR - unexpected tag in CHOICE\n");
2238         return -1;
2239         break;
2240     } /* end switch */
2241         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2242         *v = t = (ComponentName*) CompAlloc( mem_op, sizeof(ComponentName) );
2243         if ( !t ) return -1;
2244         *t = *k;
2245         }
2246         t->syntax = (Syntax*)NULL;
2247         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2248         if ( !t->comp_desc ) {
2249                 free ( t );
2250                 return -1;
2251         }
2252         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentName ;
2253         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentName ;
2254         t->comp_desc->cd_free = (comp_free_func*)NULL;
2255         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentName;
2256         t->comp_desc->cd_type = ASN_COMPOSITE;
2257         t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
2258         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentName;
2259     (*bytesDecoded) += totalElmtsLen1;
2260         return LDAP_SUCCESS;
2261 }  /* BDecNameContent */
2262
2263 int
2264 GDecComponentName PARAMS (( mem_op,b, v, bytesDecoded, mode),
2265 void* mem_op _AND_
2266 GenBuf * b _AND_
2267 ComponentName **v _AND_
2268 AsnLen *bytesDecoded _AND_
2269 int mode)
2270 {
2271         char* peek_head,*peek_head2;
2272         int i, strLen,strLen2, rc, old_mode = mode;
2273         ComponentName *k,*t, c_temp;
2274
2275
2276         if ( !(mode & DEC_ALLOC_MODE_1) ) {
2277                 memset(&c_temp,0,sizeof(c_temp));
2278                  k = &c_temp;
2279         } else
2280                  k = t = *v;
2281         mode = DEC_ALLOC_MODE_2;
2282         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2283                 Asn1Error("Error during Reading identifier");
2284                 return LDAP_PROTOCOL_ERROR;
2285         }
2286         if( !(strLen2 = LocateNextGSERToken(mem_op,b,&peek_head2,GSER_NO_COPY)) ){
2287                 Asn1Error("Error during Reading identifier");
2288                 return LDAP_PROTOCOL_ERROR;
2289         }
2290         if(*peek_head2 != ':'){
2291                 Asn1Error("Missing : in encoded data");
2292                 return LDAP_PROTOCOL_ERROR;
2293         }
2294         if( strncmp("rdnSequence",peek_head, strlen("rdnSequence")) == 0){
2295                 (k->choiceId) = NAME_RDNSEQUENCE;
2296                 rc =    GDecComponentRDNSequence (mem_op, b, (&k->a.rdnSequence), bytesDecoded, mode);
2297                 if ( rc != LDAP_SUCCESS ) return rc;
2298                 (k->a.rdnSequence)->identifier.bv_val = peek_head;
2299                 (k->a.rdnSequence)->identifier.bv_len = strLen;
2300         }
2301         else {
2302                 Asn1Error("Undefined Identifier");
2303                 return LDAP_PROTOCOL_ERROR;
2304         }
2305         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2306         *v = t = (ComponentName*) CompAlloc( mem_op, sizeof(ComponentName) );
2307         if ( !t ) return -1;
2308         *t = *k;
2309         }
2310         t->syntax = (Syntax*)NULL;
2311         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2312         if ( !t->comp_desc ) {
2313                 free ( t );
2314                 return -1;
2315         }
2316         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentName ;
2317         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentName ;
2318         t->comp_desc->cd_free = (comp_free_func*)NULL;
2319         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentName;
2320         t->comp_desc->cd_type = ASN_COMPOSITE;
2321         t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
2322         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentName;
2323         return LDAP_SUCCESS;
2324 }  /* GDecNameContent */
2325
2326
2327 int
2328 MatchingComponentTBSCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
2329         int rc;
2330         MatchingRule* mr;
2331
2332         if ( oid ) {
2333                 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
2334                 if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
2335         }
2336
2337         rc = 1;
2338         rc =    MatchingComponentVersion ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->version, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->version );
2339         if ( rc != LDAP_COMPARE_TRUE )
2340                 return rc;
2341         rc =    MatchingComponentCertificateSerialNumber ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->serialNumber, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->serialNumber );
2342         if ( rc != LDAP_COMPARE_TRUE )
2343                 return rc;
2344         rc =    MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->signature, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->signature );
2345         if ( rc != LDAP_COMPARE_TRUE )
2346                 return rc;
2347         rc =    MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->issuer, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->issuer );
2348         if ( rc != LDAP_COMPARE_TRUE )
2349                 return rc;
2350         rc =    MatchingComponentValidity ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->validity, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->validity );
2351         if ( rc != LDAP_COMPARE_TRUE )
2352                 return rc;
2353         rc =    MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->subject, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->subject );
2354         if ( rc != LDAP_COMPARE_TRUE )
2355                 return rc;
2356         rc =    MatchingComponentSubjectPublicKeyInfo ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->subjectPublicKeyInfo, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->subjectPublicKeyInfo );
2357         if ( rc != LDAP_COMPARE_TRUE )
2358                 return rc;
2359         rc =    MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->issuerUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->issuerUniqueIdentifier );
2360         if ( rc != LDAP_COMPARE_TRUE )
2361                 return rc;
2362         rc =    MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->subjectUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->subjectUniqueIdentifier );
2363         if ( rc != LDAP_COMPARE_TRUE )
2364                 return rc;
2365         if(COMPONENTNOT_NULL( ((ComponentTBSCertificate*)csi_attr)->extensions ) ) {
2366         rc =    MatchingComponentExtensions ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->extensions, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->extensions );
2367         if ( rc != LDAP_COMPARE_TRUE )
2368                 return rc;
2369         }
2370         return LDAP_COMPARE_TRUE;
2371 }  /* BMatchingComponentTBSCertificate */
2372
2373 void*
2374 ExtractingComponentTBSCertificate ( void* mem_op, ComponentReference* cr, ComponentTBSCertificate *comp )
2375 {
2376
2377         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 ) ) {
2378                 if ( cr->cr_curr->ci_next == NULL )
2379                         return comp->version;
2380                 else {
2381                         cr->cr_curr = cr->cr_curr->ci_next;
2382                         return  ExtractingComponentVersion ( mem_op, cr, comp->version );
2383                 }
2384         }
2385         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 ) ) {
2386                 if ( cr->cr_curr->ci_next == NULL )
2387                 return &comp->serialNumber;
2388                 else
2389                 return NULL;
2390         }
2391         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 ) ) {
2392                 if ( cr->cr_curr->ci_next == NULL )
2393                         return comp->signature;
2394                 else {
2395                         cr->cr_curr = cr->cr_curr->ci_next;
2396                         return  ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signature );
2397                 }
2398         }
2399         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 ) ) {
2400                 if ( cr->cr_curr->ci_next == NULL )
2401                         return comp->issuer;
2402                 else {
2403                         cr->cr_curr = cr->cr_curr->ci_next;
2404                         return  ExtractingComponentName ( mem_op, cr, comp->issuer );
2405                 }
2406         }
2407         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 ) ) {
2408                 if ( cr->cr_curr->ci_next == NULL )
2409                         return comp->validity;
2410                 else {
2411                         cr->cr_curr = cr->cr_curr->ci_next;
2412                         return  ExtractingComponentValidity ( mem_op, cr, comp->validity );
2413                 }
2414         }
2415         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 ) ) {
2416                 if ( cr->cr_curr->ci_next == NULL )
2417                         return comp->subject;
2418                 else {
2419                         cr->cr_curr = cr->cr_curr->ci_next;
2420                         return  ExtractingComponentName ( mem_op, cr, comp->subject );
2421                 }
2422         }
2423         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 ) ) {
2424                 if ( cr->cr_curr->ci_next == NULL )
2425                         return comp->subjectPublicKeyInfo;
2426                 else {
2427                         cr->cr_curr = cr->cr_curr->ci_next;
2428                         return  ExtractingComponentSubjectPublicKeyInfo ( mem_op, cr, comp->subjectPublicKeyInfo );
2429                 }
2430         }
2431         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 ) ) {
2432                 if ( cr->cr_curr->ci_next == NULL )
2433                 return &comp->issuerUniqueIdentifier;
2434         else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
2435                         cr->cr_curr = cr->cr_curr->ci_next;
2436                 return &comp->issuerUniqueIdentifier;
2437          } else {
2438                 return NULL;
2439                 }
2440         }
2441         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 ) ) {
2442                 if ( cr->cr_curr->ci_next == NULL )
2443                 return &comp->subjectUniqueIdentifier;
2444         else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
2445                         cr->cr_curr = cr->cr_curr->ci_next;
2446                 return &comp->subjectUniqueIdentifier;
2447          } else {
2448                 return NULL;
2449                 }
2450         }
2451         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 ) ) {
2452                 if ( cr->cr_curr->ci_next == NULL )
2453                         return comp->extensions;
2454                 else {
2455                         cr->cr_curr = cr->cr_curr->ci_next;
2456                         return  ExtractingComponentExtensions ( mem_op, cr, comp->extensions );
2457                 }
2458         }
2459         return NULL;
2460 }  /* ExtractingComponentTBSCertificate */
2461
2462 int
2463 BDecComponentTBSCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
2464 void* mem_op _AND_
2465 GenBuf * b _AND_
2466 AsnTag tagId0 _AND_
2467 AsnLen elmtLen0 _AND_
2468 ComponentTBSCertificate **v _AND_
2469 AsnLen *bytesDecoded _AND_
2470 int mode)
2471 {
2472         int seqDone = FALSE;
2473         AsnLen totalElmtsLen1 = 0;
2474         AsnLen elmtLen1;
2475         AsnTag tagId1;
2476         int mandatoryElmtCount1 = 0;
2477         AsnLen totalElmtsLen2 = 0;
2478         AsnLen elmtLen2;
2479         AsnTag tagId2;
2480         int old_mode = mode;
2481         int rc;
2482         ComponentTBSCertificate *k, *t, c_temp;
2483
2484
2485         if ( !(mode & DEC_ALLOC_MODE_1) ) {
2486                 memset(&c_temp,0,sizeof(c_temp));
2487                  k = &c_temp;
2488         } else
2489                  k = t = *v;
2490         mode = DEC_ALLOC_MODE_2;
2491     tagId1 = BDecTag (b, &totalElmtsLen1 );
2492
2493     if (((tagId1 == MAKE_TAG_ID (CNTX, CONS, 0))))
2494     {
2495     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2496         tagId2 = BDecTag (b, &totalElmtsLen1 );
2497
2498     if (tagId2 != MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
2499     {
2500          Asn1Error ("Unexpected Tag\n");
2501          return -1;
2502     }
2503
2504     elmtLen2 = BDecLen (b, &totalElmtsLen1 );
2505         rc = BDecComponentVersion (mem_op, b, tagId2, elmtLen2, (&k->version), &totalElmtsLen1, DEC_ALLOC_MODE_0 );
2506                 if ( rc != LDAP_SUCCESS ) return rc;
2507                 (k->version)->identifier.bv_val = (k->version)->id_buf;
2508                 (k->version)->identifier.bv_len = strlen("version");
2509                 strcpy( (k->version)->identifier.bv_val, "version");
2510         if (elmtLen1 == INDEFINITE_LEN)
2511         BDecEoc (b, &totalElmtsLen1 );
2512     tagId1 = BDecTag (b, &totalElmtsLen1);
2513     }
2514
2515
2516     if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))))
2517     {
2518     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2519         rc = BDecComponentCertificateSerialNumber (mem_op, b, tagId1, elmtLen1, (&k->serialNumber), &totalElmtsLen1, mode);
2520                 if ( rc != LDAP_SUCCESS ) return rc;
2521                 (&k->serialNumber)->identifier.bv_val = (&k->serialNumber)->id_buf;
2522                 (&k->serialNumber)->identifier.bv_len = strlen("serialNumber");
2523                 strcpy( (&k->serialNumber)->identifier.bv_val, "serialNumber");
2524     tagId1 = BDecTag (b, &totalElmtsLen1);
2525     }
2526     else
2527         return -1;
2528
2529
2530
2531     if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2532     {
2533     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2534         rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode);
2535                 if ( rc != LDAP_SUCCESS ) return rc;
2536                 (k->signature)->identifier.bv_val = (k->signature)->id_buf;
2537                 (k->signature)->identifier.bv_len = strlen("signature");
2538                 strcpy( (k->signature)->identifier.bv_val, "signature");
2539     tagId1 = BDecTag (b, &totalElmtsLen1);
2540     }
2541     else
2542         return -1;
2543
2544
2545
2546     if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2547     {
2548         elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2549         rc = BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->issuer), &totalElmtsLen1, mode);
2550                 if ( rc != LDAP_SUCCESS ) return rc;
2551                 (k->issuer)->identifier.bv_val = (k->issuer)->id_buf;
2552                 (k->issuer)->identifier.bv_len = strlen("issuer");
2553                 strcpy( (k->issuer)->identifier.bv_val, "issuer");
2554     tagId1 = BDecTag (b, &totalElmtsLen1);
2555     }
2556     else
2557         return -1;
2558
2559
2560
2561     if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2562     {
2563     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2564         rc = BDecComponentValidity (mem_op, b, tagId1, elmtLen1, (&k->validity), &totalElmtsLen1, mode);
2565                 if ( rc != LDAP_SUCCESS ) return rc;
2566                 (k->validity)->identifier.bv_val = (k->validity)->id_buf;
2567                 (k->validity)->identifier.bv_len = strlen("validity");
2568                 strcpy( (k->validity)->identifier.bv_val, "validity");
2569     tagId1 = BDecTag (b, &totalElmtsLen1);
2570     }
2571     else
2572         return -1;
2573
2574
2575
2576     if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2577     {
2578         elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2579         rc = BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->subject), &totalElmtsLen1, mode);
2580                 if ( rc != LDAP_SUCCESS ) return rc;
2581                 (k->subject)->identifier.bv_val = (k->subject)->id_buf;
2582                 (k->subject)->identifier.bv_len = strlen("subject");
2583                 strcpy( (k->subject)->identifier.bv_val, "subject");
2584     tagId1 = BDecTag (b, &totalElmtsLen1);
2585     }
2586     else
2587         return -1;
2588
2589
2590
2591     if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
2592     {
2593     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2594         rc = BDecComponentSubjectPublicKeyInfo (mem_op, b, tagId1, elmtLen1, (&k->subjectPublicKeyInfo), &totalElmtsLen1, mode);
2595                 if ( rc != LDAP_SUCCESS ) return rc;
2596                 (k->subjectPublicKeyInfo)->identifier.bv_val = (k->subjectPublicKeyInfo)->id_buf;
2597                 (k->subjectPublicKeyInfo)->identifier.bv_len = strlen("subjectPublicKeyInfo");
2598                 strcpy( (k->subjectPublicKeyInfo)->identifier.bv_val, "subjectPublicKeyInfo");
2599     if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
2600         seqDone = TRUE;
2601     else
2602     {
2603         tagId1 = BDecTag (b, &totalElmtsLen1 );
2604
2605          if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
2606         {
2607             BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
2608             seqDone = TRUE;
2609         }
2610     }
2611     }
2612     else
2613         return -1;
2614
2615
2616
2617     if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, PRIM, 1)) ||
2618 (tagId1 == MAKE_TAG_ID (CNTX, CONS, 1))))
2619     {
2620     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2621         rc = BDecComponentUniqueIdentifier (mem_op, b, tagId1, elmtLen1, (&k->issuerUniqueIdentifier), &totalElmtsLen1, mode);
2622                 if ( rc != LDAP_SUCCESS ) return rc;
2623                 (&k->issuerUniqueIdentifier)->identifier.bv_val = (&k->issuerUniqueIdentifier)->id_buf;
2624                 (&k->issuerUniqueIdentifier)->identifier.bv_len = strlen("issuerUniqueIdentifier");
2625                 strcpy( (&k->issuerUniqueIdentifier)->identifier.bv_val, "issuerUniqueIdentifier");
2626     if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
2627         seqDone = TRUE;
2628     else
2629     {
2630         tagId1 = BDecTag (b, &totalElmtsLen1 );
2631
2632          if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
2633         {
2634             BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
2635             seqDone = TRUE;
2636         }
2637     }
2638     }
2639
2640
2641     if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, PRIM, 2)) ||
2642 (tagId1 == MAKE_TAG_ID (CNTX, CONS, 2))))
2643     {
2644     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2645         rc = BDecComponentUniqueIdentifier (mem_op, b, tagId1, elmtLen1, (&k->subjectUniqueIdentifier), &totalElmtsLen1, mode);
2646                 if ( rc != LDAP_SUCCESS ) return rc;
2647                 (&k->subjectUniqueIdentifier)->identifier.bv_val = (&k->subjectUniqueIdentifier)->id_buf;
2648                 (&k->subjectUniqueIdentifier)->identifier.bv_len = strlen("subjectUniqueIdentifier");
2649                 strcpy( (&k->subjectUniqueIdentifier)->identifier.bv_val, "subjectUniqueIdentifier");
2650     if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0))
2651         seqDone = TRUE;
2652     else
2653     {
2654         tagId1 = BDecTag (b, &totalElmtsLen1 );
2655
2656          if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID))
2657         {
2658             BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 )
2659             seqDone = TRUE;
2660         }
2661     }
2662     }
2663
2664
2665     if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, CONS, 3))))
2666     {
2667     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
2668         tagId2 = BDecTag (b, &totalElmtsLen1 );
2669
2670     if (tagId2 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
2671     {
2672          Asn1Error ("Unexpected Tag\n");
2673          return -1;
2674     }
2675
2676     elmtLen2 = BDecLen (b, &totalElmtsLen1 );
2677         rc = BDecComponentExtensions (mem_op, b, tagId2, elmtLen2, (&k->extensions), &totalElmtsLen1, mode);
2678                 if ( rc != LDAP_SUCCESS ) return rc;
2679                 (k->extensions)->identifier.bv_val = (k->extensions)->id_buf;
2680                 (k->extensions)->identifier.bv_len = strlen("extensions");
2681                 strcpy( (k->extensions)->identifier.bv_val, "extensions");
2682         if (elmtLen1 == INDEFINITE_LEN)
2683         BDecEoc (b, &totalElmtsLen1 );
2684         seqDone = TRUE;
2685         if (elmtLen0 == INDEFINITE_LEN)
2686             BDecEoc (b, &totalElmtsLen1 );
2687         else if (totalElmtsLen1 != elmtLen0)
2688         return -1;
2689
2690     }
2691
2692
2693     if (!seqDone)
2694         return -1;
2695
2696         if(!COMPONENTNOT_NULL ((k->version)))
2697         {
2698 (k->version) = CompAlloc( mem_op, sizeof(ComponentVersion));
2699                 (k->version)->identifier.bv_val = (k->version)->id_buf;
2700                 (k->version)->identifier.bv_len = strlen("version");
2701                 strcpy( (k->version)->identifier.bv_val, "version");
2702         (k->version)->value = 0;
2703         }
2704         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2705         *v = t = (ComponentTBSCertificate*) CompAlloc( mem_op, sizeof(ComponentTBSCertificate) );
2706         if ( !t ) return -1;
2707         *t = *k;
2708         }
2709         t->syntax = (Syntax*)NULL;
2710         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2711         if ( !t->comp_desc ) {
2712                 free ( t );
2713                 return -1;
2714         }
2715         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertificate ;
2716         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertificate ;
2717         t->comp_desc->cd_free = (comp_free_func*)NULL;
2718         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate;
2719         t->comp_desc->cd_type = ASN_COMPOSITE;
2720         t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
2721         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertificate;
2722     (*bytesDecoded) += totalElmtsLen1;
2723         return LDAP_SUCCESS;
2724 }  /* BDecTBSCertificate*/
2725
2726 int
2727 GDecComponentTBSCertificate PARAMS (( mem_op,b, v, bytesDecoded, mode),
2728 void* mem_op _AND_
2729 GenBuf * b _AND_
2730 ComponentTBSCertificate **v _AND_
2731 AsnLen *bytesDecoded _AND_
2732 int mode)
2733 {
2734         char* peek_head,*peek_head2;
2735         int i, strLen,strLen2, rc, old_mode = mode;
2736         ComponentTBSCertificate *k,*t, c_temp;
2737
2738
2739         if ( !(mode & DEC_ALLOC_MODE_1) ) {
2740                 memset(&c_temp,0,sizeof(c_temp));
2741                  k = &c_temp;
2742         } else
2743                  k = t = *v;
2744         mode = DEC_ALLOC_MODE_2;
2745         *bytesDecoded = 0;
2746         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2747                 Asn1Error("Error during Reading { in encoded data");
2748                 return LDAP_PROTOCOL_ERROR;
2749         }
2750         if(*peek_head != '{'){
2751                 Asn1Error("Missing { in encoded data");
2752                 return LDAP_PROTOCOL_ERROR;
2753         }
2754
2755         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2756                 Asn1Error("Error during Reading identifier");
2757                 return LDAP_PROTOCOL_ERROR;
2758         }
2759         if ( strncmp( peek_head, "version", strlen("version") ) == 0 ) {
2760                 rc =    GDecComponentVersion (mem_op, b, (&k->version), bytesDecoded, DEC_ALLOC_MODE_0 );
2761                 if ( rc != LDAP_SUCCESS ) return rc;
2762         ( k->version)->identifier.bv_val = peek_head;
2763         ( k->version)->identifier.bv_len = strLen;
2764         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2765                 Asn1Error("Error during Reading , ");
2766                 return LDAP_PROTOCOL_ERROR;
2767         }
2768         if(*peek_head != ','){
2769                 Asn1Error("Missing , in encoding");
2770                 return LDAP_PROTOCOL_ERROR;
2771         }
2772         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2773           Asn1Error("Error during Reading identifier");
2774                 return LDAP_PROTOCOL_ERROR;
2775         }
2776         }
2777         else {
2778 (k->version) = CompAlloc( mem_op, sizeof(ComponentVersion));
2779                         (k->version)->value = 0;
2780         }
2781         if ( strncmp( peek_head, "serialNumber", strlen("serialNumber") ) == 0 ) {
2782                 rc =    GDecComponentCertificateSerialNumber (mem_op, b, (&k->serialNumber), bytesDecoded, mode);
2783                 if ( rc != LDAP_SUCCESS ) return rc;
2784         (&k->serialNumber)->identifier.bv_val = peek_head;
2785         (&k->serialNumber)->identifier.bv_len = strLen;
2786         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2787                 Asn1Error("Error during Reading , ");
2788                 return LDAP_PROTOCOL_ERROR;
2789         }
2790         if(*peek_head != ','){
2791                 Asn1Error("Missing , in encoding");
2792                 return LDAP_PROTOCOL_ERROR;
2793         }
2794         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2795           Asn1Error("Error during Reading identifier");
2796                 return LDAP_PROTOCOL_ERROR;
2797         }
2798         }
2799         if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) {
2800                 rc =    GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signature), bytesDecoded, mode);
2801                 if ( rc != LDAP_SUCCESS ) return rc;
2802         ( k->signature)->identifier.bv_val = peek_head;
2803         ( k->signature)->identifier.bv_len = strLen;
2804         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2805                 Asn1Error("Error during Reading , ");
2806                 return LDAP_PROTOCOL_ERROR;
2807         }
2808         if(*peek_head != ','){
2809                 Asn1Error("Missing , in encoding");
2810                 return LDAP_PROTOCOL_ERROR;
2811         }
2812         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2813           Asn1Error("Error during Reading identifier");
2814                 return LDAP_PROTOCOL_ERROR;
2815         }
2816         }
2817         if ( strncmp( peek_head, "issuer", strlen("issuer") ) == 0 ) {
2818                 rc =    GDecComponentName (mem_op, b, (&k->issuer), bytesDecoded, mode);
2819                 if ( rc != LDAP_SUCCESS ) return rc;
2820         ( k->issuer)->identifier.bv_val = peek_head;
2821         ( k->issuer)->identifier.bv_len = strLen;
2822         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2823                 Asn1Error("Error during Reading , ");
2824                 return LDAP_PROTOCOL_ERROR;
2825         }
2826         if(*peek_head != ','){
2827                 Asn1Error("Missing , in encoding");
2828                 return LDAP_PROTOCOL_ERROR;
2829         }
2830         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2831           Asn1Error("Error during Reading identifier");
2832                 return LDAP_PROTOCOL_ERROR;
2833         }
2834         }
2835         if ( strncmp( peek_head, "validity", strlen("validity") ) == 0 ) {
2836                 rc =    GDecComponentValidity (mem_op, b, (&k->validity), bytesDecoded, mode);
2837                 if ( rc != LDAP_SUCCESS ) return rc;
2838         ( k->validity)->identifier.bv_val = peek_head;
2839         ( k->validity)->identifier.bv_len = strLen;
2840         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2841                 Asn1Error("Error during Reading , ");
2842                 return LDAP_PROTOCOL_ERROR;
2843         }
2844         if(*peek_head != ','){
2845                 Asn1Error("Missing , in encoding");
2846                 return LDAP_PROTOCOL_ERROR;
2847         }
2848         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2849           Asn1Error("Error during Reading identifier");
2850                 return LDAP_PROTOCOL_ERROR;
2851         }
2852         }
2853         if ( strncmp( peek_head, "subject", strlen("subject") ) == 0 ) {
2854                 rc =    GDecComponentName (mem_op, b, (&k->subject), bytesDecoded, mode);
2855                 if ( rc != LDAP_SUCCESS ) return rc;
2856         ( k->subject)->identifier.bv_val = peek_head;
2857         ( k->subject)->identifier.bv_len = strLen;
2858         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2859                 Asn1Error("Error during Reading , ");
2860                 return LDAP_PROTOCOL_ERROR;
2861         }
2862         if(*peek_head != ','){
2863                 Asn1Error("Missing , in encoding");
2864                 return LDAP_PROTOCOL_ERROR;
2865         }
2866         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2867           Asn1Error("Error during Reading identifier");
2868                 return LDAP_PROTOCOL_ERROR;
2869         }
2870         }
2871         if ( strncmp( peek_head, "subjectPublicKeyInfo", strlen("subjectPublicKeyInfo") ) == 0 ) {
2872                 rc =    GDecComponentSubjectPublicKeyInfo (mem_op, b, (&k->subjectPublicKeyInfo), bytesDecoded, mode);
2873                 if ( rc != LDAP_SUCCESS ) return rc;
2874         ( k->subjectPublicKeyInfo)->identifier.bv_val = peek_head;
2875         ( k->subjectPublicKeyInfo)->identifier.bv_len = strLen;
2876         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2877                 Asn1Error("Error during Reading , ");
2878                 return LDAP_PROTOCOL_ERROR;
2879         }
2880         if(*peek_head != ','){
2881                 Asn1Error("Missing , in encoding");
2882                 return LDAP_PROTOCOL_ERROR;
2883         }
2884         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2885           Asn1Error("Error during Reading identifier");
2886                 return LDAP_PROTOCOL_ERROR;
2887         }
2888         }
2889         if ( strncmp( peek_head, "issuerUniqueIdentifier", strlen("issuerUniqueIdentifier") ) == 0 ) {
2890                 rc =    GDecComponentUniqueIdentifier (mem_op, b, (&k->issuerUniqueIdentifier), bytesDecoded, mode);
2891                 if ( rc != LDAP_SUCCESS ) return rc;
2892         (&k->issuerUniqueIdentifier)->identifier.bv_val = peek_head;
2893         (&k->issuerUniqueIdentifier)->identifier.bv_len = strLen;
2894         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2895                 Asn1Error("Error during Reading , ");
2896                 return LDAP_PROTOCOL_ERROR;
2897         }
2898         if(*peek_head != ','){
2899                 Asn1Error("Missing , in encoding");
2900                 return LDAP_PROTOCOL_ERROR;
2901         }
2902         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2903           Asn1Error("Error during Reading identifier");
2904                 return LDAP_PROTOCOL_ERROR;
2905         }
2906         }
2907         if ( strncmp( peek_head, "subjectUniqueIdentifier", strlen("subjectUniqueIdentifier") ) == 0 ) {
2908                 rc =    GDecComponentUniqueIdentifier (mem_op, b, (&k->subjectUniqueIdentifier), bytesDecoded, mode);
2909                 if ( rc != LDAP_SUCCESS ) return rc;
2910         (&k->subjectUniqueIdentifier)->identifier.bv_val = peek_head;
2911         (&k->subjectUniqueIdentifier)->identifier.bv_len = strLen;
2912         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2913                 Asn1Error("Error during Reading , ");
2914                 return LDAP_PROTOCOL_ERROR;
2915         }
2916         if(*peek_head != ','){
2917                 Asn1Error("Missing , in encoding");
2918                 return LDAP_PROTOCOL_ERROR;
2919         }
2920         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
2921           Asn1Error("Error during Reading identifier");
2922                 return LDAP_PROTOCOL_ERROR;
2923         }
2924         }
2925         if ( strncmp( peek_head, "extensions", strlen("extensions") ) == 0 ) {
2926                 rc =    GDecComponentExtensions (mem_op, b, (&k->extensions), bytesDecoded, mode);
2927                 if ( rc != LDAP_SUCCESS ) return rc;
2928         ( k->extensions)->identifier.bv_val = peek_head;
2929         ( k->extensions)->identifier.bv_len = strLen;
2930         }
2931         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
2932                 Asn1Error("Error during Reading } in encoding");
2933                 return LDAP_PROTOCOL_ERROR;
2934         }
2935         if(*peek_head != '}'){
2936                 Asn1Error("Missing } in encoding");
2937                 return LDAP_PROTOCOL_ERROR;
2938         }
2939         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
2940         *v = t = (ComponentTBSCertificate*) CompAlloc( mem_op, sizeof(ComponentTBSCertificate) );
2941         if ( !t ) return -1;
2942         *t = *k;
2943         }
2944         t->syntax = (Syntax*)NULL;
2945         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2946         if ( !t->comp_desc ) {
2947                 free ( t );
2948                 return -1;
2949         }
2950         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertificate ;
2951         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertificate ;
2952         t->comp_desc->cd_free = (comp_free_func*)NULL;
2953         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate;
2954         t->comp_desc->cd_type = ASN_COMPOSITE;
2955         t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
2956         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertificate;
2957         return LDAP_SUCCESS;
2958 }  /* GDecTBSCertificate*/
2959
2960
2961 int
2962 MatchingComponentCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) {
2963         int rc;
2964         MatchingRule* mr;
2965
2966         if ( oid ) {
2967                 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id);
2968                 if ( mr ) return component_value_match( mr, csi_attr, csi_assert );
2969         }
2970
2971         rc = 1;
2972         rc =    MatchingComponentTBSCertificate ( oid, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_attr)->tbsCertificate, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_assert)->tbsCertificate );
2973         if ( rc != LDAP_COMPARE_TRUE )
2974                 return rc;
2975         rc =    MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_attr)->signatureAlgorithm, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_assert)->signatureAlgorithm );
2976         if ( rc != LDAP_COMPARE_TRUE )
2977                 return rc;
2978         rc =    MatchingComponentBits ( oid, (ComponentSyntaxInfo*)&((ComponentCertificate*)csi_attr)->signature, (ComponentSyntaxInfo*)&((ComponentCertificate*)csi_assert)->signature );
2979         if ( rc != LDAP_COMPARE_TRUE )
2980                 return rc;
2981         return LDAP_COMPARE_TRUE;
2982 }  /* BMatchingComponentCertificate */
2983
2984 void*
2985 ExtractingComponentCertificate ( void* mem_op, ComponentReference* cr, ComponentCertificate *comp )
2986 {
2987
2988         if ( ( comp->tbsCertificate->identifier.bv_val && strncmp(comp->tbsCertificate->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->tbsCertificate->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) {
2989                 if ( cr->cr_curr->ci_next == NULL )
2990                         return comp->tbsCertificate;
2991                 else {
2992                         cr->cr_curr = cr->cr_curr->ci_next;
2993                         return  ExtractingComponentTBSCertificate ( mem_op, cr, comp->tbsCertificate );
2994                 }
2995         }
2996         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 ) ) {
2997                 if ( cr->cr_curr->ci_next == NULL )
2998                         return comp->signatureAlgorithm;
2999                 else {
3000                         cr->cr_curr = cr->cr_curr->ci_next;
3001                         return  ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signatureAlgorithm );
3002                 }
3003         }
3004         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 ) ) {
3005                 if ( cr->cr_curr->ci_next == NULL )
3006                 return &comp->signature;
3007         else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) {
3008                         cr->cr_curr = cr->cr_curr->ci_next;
3009                 return &comp->signature;
3010          } else {
3011                 return NULL;
3012                 }
3013         }
3014         return NULL;
3015 }  /* ExtractingComponentCertificate */
3016
3017 int
3018 BDecComponentCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode),
3019 void* mem_op _AND_
3020 GenBuf * b _AND_
3021 AsnTag tagId0 _AND_
3022 AsnLen elmtLen0 _AND_
3023 ComponentCertificate **v _AND_
3024 AsnLen *bytesDecoded _AND_
3025 int mode)
3026 {
3027         int seqDone = FALSE;
3028         AsnLen totalElmtsLen1 = 0;
3029         AsnLen elmtLen1;
3030         AsnTag tagId1;
3031         int mandatoryElmtCount1 = 0;
3032         int old_mode = mode;
3033         int rc;
3034         ComponentCertificate *k, *t, c_temp;
3035
3036
3037         if ( !(mode & DEC_ALLOC_MODE_1) ) {
3038                 memset(&c_temp,0,sizeof(c_temp));
3039                  k = &c_temp;
3040         } else
3041                  k = t = *v;
3042         mode = DEC_ALLOC_MODE_2;
3043     tagId1 = BDecTag (b, &totalElmtsLen1 );
3044
3045     if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
3046     {
3047     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
3048         rc = BDecComponentTBSCertificate (mem_op, b, tagId1, elmtLen1, (&k->tbsCertificate), &totalElmtsLen1, mode);
3049                 if ( rc != LDAP_SUCCESS ) return rc;
3050                 (k->tbsCertificate)->identifier.bv_val = (k->tbsCertificate)->id_buf;
3051                 (k->tbsCertificate)->identifier.bv_len = strlen("tbsCertificate");
3052                 strcpy( (k->tbsCertificate)->identifier.bv_val, "tbsCertificate");
3053     tagId1 = BDecTag (b, &totalElmtsLen1);
3054     }
3055     else
3056         return -1;
3057
3058
3059
3060     if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))))
3061     {
3062     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
3063         rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signatureAlgorithm), &totalElmtsLen1, mode);
3064                 if ( rc != LDAP_SUCCESS ) return rc;
3065                 (k->signatureAlgorithm)->identifier.bv_val = (k->signatureAlgorithm)->id_buf;
3066                 (k->signatureAlgorithm)->identifier.bv_len = strlen("signatureAlgorithm");
3067                 strcpy( (k->signatureAlgorithm)->identifier.bv_val, "signatureAlgorithm");
3068     tagId1 = BDecTag (b, &totalElmtsLen1);
3069     }
3070     else
3071         return -1;
3072
3073
3074
3075     if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE)) ||
3076 (tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE))))
3077     {
3078     elmtLen1 = BDecLen (b, &totalElmtsLen1 );
3079         rc = BDecComponentBits (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode);
3080                 if ( rc != LDAP_SUCCESS ) return rc;
3081                 (&k->signature)->identifier.bv_val = (&k->signature)->id_buf;
3082                 (&k->signature)->identifier.bv_len = strlen("signature");
3083                 strcpy( (&k->signature)->identifier.bv_val, "signature");
3084         seqDone = TRUE;
3085         if (elmtLen0 == INDEFINITE_LEN)
3086             BDecEoc (b, &totalElmtsLen1 );
3087         else if (totalElmtsLen1 != elmtLen0)
3088         return -1;
3089
3090     }
3091     else
3092         return -1;
3093
3094
3095
3096     if (!seqDone)
3097         return -1;
3098
3099         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
3100         *v = t = (ComponentCertificate*) CompAlloc( mem_op, sizeof(ComponentCertificate) );
3101         if ( !t ) return -1;
3102         *t = *k;
3103         }
3104         t->syntax = (Syntax*)NULL;
3105         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
3106         if ( !t->comp_desc ) {
3107                 free ( t );
3108                 return -1;
3109         }
3110         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificate ;
3111         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificate ;
3112         t->comp_desc->cd_free = (comp_free_func*)NULL;
3113         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate;
3114         t->comp_desc->cd_type = ASN_COMPOSITE;
3115         t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
3116         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificate;
3117     (*bytesDecoded) += totalElmtsLen1;
3118         return LDAP_SUCCESS;
3119 }  /* BDecCertificate*/
3120
3121 int
3122 GDecComponentCertificate PARAMS (( mem_op,b, v, bytesDecoded, mode),
3123 void* mem_op _AND_
3124 GenBuf * b _AND_
3125 ComponentCertificate **v _AND_
3126 AsnLen *bytesDecoded _AND_
3127 int mode)
3128 {
3129         char* peek_head,*peek_head2;
3130         int i, strLen,strLen2, rc, old_mode = mode;
3131         ComponentCertificate *k,*t, c_temp;
3132
3133
3134         if ( !(mode & DEC_ALLOC_MODE_1) ) {
3135                 memset(&c_temp,0,sizeof(c_temp));
3136                  k = &c_temp;
3137         } else
3138                  k = t = *v;
3139         mode = DEC_ALLOC_MODE_2;
3140         *bytesDecoded = 0;
3141         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3142                 Asn1Error("Error during Reading { in encoded data");
3143                 return LDAP_PROTOCOL_ERROR;
3144         }
3145         if(*peek_head != '{'){
3146                 Asn1Error("Missing { in encoded data");
3147                 return LDAP_PROTOCOL_ERROR;
3148         }
3149
3150         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3151                 Asn1Error("Error during Reading identifier");
3152                 return LDAP_PROTOCOL_ERROR;
3153         }
3154         if ( strncmp( peek_head, "tbsCertificate", strlen("tbsCertificate") ) == 0 ) {
3155                 rc =    GDecComponentTBSCertificate (mem_op, b, (&k->tbsCertificate), bytesDecoded, mode);
3156                 if ( rc != LDAP_SUCCESS ) return rc;
3157         ( k->tbsCertificate)->identifier.bv_val = peek_head;
3158         ( k->tbsCertificate)->identifier.bv_len = strLen;
3159         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3160                 Asn1Error("Error during Reading , ");
3161                 return LDAP_PROTOCOL_ERROR;
3162         }
3163         if(*peek_head != ','){
3164                 Asn1Error("Missing , in encoding");
3165                 return LDAP_PROTOCOL_ERROR;
3166         }
3167         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3168           Asn1Error("Error during Reading identifier");
3169                 return LDAP_PROTOCOL_ERROR;
3170         }
3171         }
3172         if ( strncmp( peek_head, "signatureAlgorithm", strlen("signatureAlgorithm") ) == 0 ) {
3173                 rc =    GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signatureAlgorithm), bytesDecoded, mode);
3174                 if ( rc != LDAP_SUCCESS ) return rc;
3175         ( k->signatureAlgorithm)->identifier.bv_val = peek_head;
3176         ( k->signatureAlgorithm)->identifier.bv_len = strLen;
3177         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3178                 Asn1Error("Error during Reading , ");
3179                 return LDAP_PROTOCOL_ERROR;
3180         }
3181         if(*peek_head != ','){
3182                 Asn1Error("Missing , in encoding");
3183                 return LDAP_PROTOCOL_ERROR;
3184         }
3185         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){
3186           Asn1Error("Error during Reading identifier");
3187                 return LDAP_PROTOCOL_ERROR;
3188         }
3189         }
3190         if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) {
3191                 rc =    GDecComponentBits (mem_op, b, (&k->signature), bytesDecoded, mode);
3192                 if ( rc != LDAP_SUCCESS ) return rc;
3193         (&k->signature)->identifier.bv_val = peek_head;
3194         (&k->signature)->identifier.bv_len = strLen;
3195         }
3196         if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) {
3197                 Asn1Error("Error during Reading } in encoding");
3198                 return LDAP_PROTOCOL_ERROR;
3199         }
3200         if(*peek_head != '}'){
3201                 Asn1Error("Missing } in encoding");
3202                 return LDAP_PROTOCOL_ERROR;
3203         }
3204         if( !(old_mode & DEC_ALLOC_MODE_1) ) {
3205         *v = t = (ComponentCertificate*) CompAlloc( mem_op, sizeof(ComponentCertificate) );
3206         if ( !t ) return -1;
3207         *t = *k;
3208         }
3209         t->syntax = (Syntax*)NULL;
3210         t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
3211         if ( !t->comp_desc ) {
3212                 free ( t );
3213                 return -1;
3214         }
3215         t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificate ;
3216         t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificate ;
3217         t->comp_desc->cd_free = (comp_free_func*)NULL;
3218         t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate;
3219         t->comp_desc->cd_type = ASN_COMPOSITE;
3220         t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE;
3221         t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificate;
3222         return LDAP_SUCCESS;
3223 }  /* GDecCertificate*/
3224
3225