23 #if !defined( NDEBUG ) && 0
24 #define TRACE_FIELDTYPE( attributeInfoPtr ) \
26 if( ( attributeInfoPtr ) != NULL && \
27 ( attributeInfoPtr )->description != NULL ) \
28 DEBUG_PRINT(( ( attributeInfoPtr )->description )); \
30 DEBUG_PRINT(( "<Unrecognised attribute>" )); \
31 DEBUG_PRINT(( "\n" )); \
33 #define TRACE_DEBUG( message ) \
34 DEBUG_PRINT( message )
36 #define TRACE_FIELDTYPE( attributeInfoPtr )
37 #define TRACE_DEBUG( message )
40 #ifdef USE_CERTIFICATES
137 #define ATTRIBUTE_STACKSIZE 10
155 static
int updateStackedInfo(
INOUT_ARRAY_C( ATTRIBUTE_STACKSIZE ) \
156 ATTRIBUTE_STACK *stack,
157 IN_RANGE( 0, ATTRIBUTE_STACKSIZE - 1 ) \
159 OUT_RANGE( 0, ATTRIBUTE_STACKSIZE - 1 ) \
161 IN_RANGE( 0, ATTRIBUTE_STACKSIZE - 1 )
int count,
164 int currentStackPos = stackPos, iterationCount;
166 assert(
isWritePtr( stack,
sizeof( ATTRIBUTE_STACK ) * \
167 ATTRIBUTE_STACKSIZE ) );
168 assert(
isWritePtr( newStackPosPtr,
sizeof(
int ) ) );
173 REQUIRES( stackPos >= 0 && stackPos < ATTRIBUTE_STACKSIZE );
174 REQUIRES( count >= 0 && count <= stackPos );
176 for( iterationCount = 0; \
177 count > 0 && iterationCount < ATTRIBUTE_STACKSIZE; \
178 count--, iterationCount++ )
184 ENSURES( count > 0 && count <= currentStackPos );
188 ENSURES( currentStackPos >= 0 && \
189 currentStackPos < ATTRIBUTE_STACKSIZE );
190 attributeFifoPtr = stack[ currentStackPos ].attributeListPtr;
191 attributeInfoPtr = stack[ currentStackPos ].attributeInfoPtr;
192 size = stack[ currentStackPos ].size;
213 if( attributeFifoPtr == NULL )
225 attributeFifoPtr->sizeFifo[ attributeFifoPtr->
fifoEnd ] =
size;
226 attributeFifoPtr->encodingFifo[ attributeFifoPtr->
fifoEnd++ ] = \
233 if( currentStackPos <= 0 )
236 ENSURES( currentStackPos > 0 && \
237 currentStackPos < ATTRIBUTE_STACKSIZE );
263 stack[ currentStackPos - 1 ].size += size + newLength;
271 stack[ currentStackPos - 1 ].size += ( int ) sizeofObject( size );
274 ENSURES( iterationCount < ATTRIBUTE_STACKSIZE );
276 *newStackPosPtr = currentStackPos;
294 int nestLevel = 0, iterationCount;
301 ( fieldID == CRYPT_IATTRIBUTE_LAST ) );
324 if( attributeInfoPtr->
fieldID == fieldID )
330 if( nestLevel <= 0 || \
336 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
354 typedef enum { CHOICE_NONE, CHOICE_START, CHOICE_DONE } CHOICE_STATE;
371 CHOICE_STATE choiceState;
377 ARRAY( ATTRIBUTE_STACKSIZE, stackPos ) \
378 ATTRIBUTE_STACK stack[ ATTRIBUTE_STACKSIZE + 8 ];
385 } ATTRIBUTE_CHECK_INFO;
388 static
int stackInfo(
INOUT ATTRIBUTE_CHECK_INFO *attributeCheckInfo,
392 ATTRIBUTE_STACK *stack = attributeCheckInfo->stack;
395 sizeof( ATTRIBUTE_CHECK_INFO ) ) );
396 assert( attributeListPtr == NULL || \
400 REQUIRES( attributeCheckInfo->stackPos >= 0 && \
401 attributeCheckInfo->stackPos < ATTRIBUTE_STACKSIZE - 1 );
403 stack[ attributeCheckInfo->stackPos ].size = 0;
405 stack[ attributeCheckInfo->stackPos++ ].
attributeInfoPtr = attributeInfoPtr;
411 static
int checkAttribute(
INOUT ATTRIBUTE_CHECK_INFO *attributeCheckInfo );
415 static
int checkAttributeEntry(
INOUT ATTRIBUTE_CHECK_INFO *attributeCheckInfo )
417 ATTRIBUTE_LIST *attributeListPtr = attributeCheckInfo->attributeListPtr;
418 const ATTRIBUTE_INFO *attributeInfoPtr = attributeCheckInfo->attributeInfoPtr;
419 ATTRIBUTE_STACK *stack = attributeCheckInfo->stack;
423 sizeof( ATTRIBUTE_CHECK_INFO ) ) );
424 assert( attributeListPtr == NULL || \
428 sizeof( ATTRIBUTE_STACK ) * ATTRIBUTE_STACKSIZE ) );
435 if( attributeListPtr == NULL || \
440 fieldID = CRYPT_IATTRIBUTE_LAST;
446 if( attributeCheckInfo->subtypeParent == attributeListPtr->
fieldID )
451 fieldID = attributeListPtr->
fieldID;
457 if( attributeListPtr != NULL && attributeInfoPtr->
fieldID == fieldID )
473 status = stackInfo( attributeCheckInfo, attributeListPtr,
477 attributeCheckInfo->choiceState = CHOICE_START;
479 attributeCheckInfo->attributeInfoPtr = \
481 attributeCheckInfo->subtypeParent = attributeListPtr->
fieldID;
482 attributeCheckInfo->stackTop = attributeCheckInfo->stackPos;
483 status = checkAttribute( attributeCheckInfo );
484 attributeCheckInfo->attributeInfoPtr = attributeInfoPtr;
486 attributeCheckInfo->stackTop = 0;
505 if( attributeInfoPtr->
extraData != NULL )
507 VALIDATION_FUNCTION validationFunction = \
508 ( VALIDATION_FUNCTION ) attributeInfoPtr->
extraData;
510 attributeCheckInfo->errorType = \
511 validationFunction( attributeListPtr );
522 attributeCheckInfo->attributeListPtr = attributeListPtr->
next;
534 writeAttributeField( NULL, attributeListPtr,
536 if( attributeCheckInfo->stackPos > 0 )
538 stack[ attributeCheckInfo->stackPos - 1 ].size += \
539 attributeListPtr->encodedSize;
543 if( attributeCheckInfo->choiceState != CHOICE_NONE )
545 if( attributeCheckInfo->choiceState == CHOICE_DONE )
552 if( attributeCheckInfo->choiceState == CHOICE_START )
555 attributeCheckInfo->choiceState = CHOICE_DONE;
560 attributeCheckInfo->attributeListPtr = attributeListPtr->
next;
578 status = checkComponentPresent( fieldID,
585 attributeCheckInfo->attributeInfoPtr = attributeInfoPtr;
592 status = stackInfo( attributeCheckInfo, attributeListPtr,
593 attributeInfoPtr++ );
595 status = stackInfo( attributeCheckInfo, attributeListPtr,
603 endOfAttributeField =
TRUE;
611 status = stackInfo( attributeCheckInfo, attributeListPtr,
618 endOfAttributeField =
TRUE;
621 attributeCheckInfo->attributeInfoPtr = attributeInfoPtr;
622 if( endOfAttributeField )
626 if( attributeListPtr == NULL )
627 attributeCheckInfo->attributeListPtr = NULL;
629 attributeCheckInfo->attributeListPtr = attributeListPtr->
next;
642 return( stackInfo( attributeCheckInfo, attributeListPtr,
643 attributeInfoPtr ) );
663 static
int checkAttribute(
INOUT ATTRIBUTE_CHECK_INFO *attributeCheckInfo )
667 int restartStackPos = 0, iterationCount;
670 sizeof( ATTRIBUTE_CHECK_INFO ) ) );
671 assert(
isReadPtr( attributeCheckInfo->attributeInfoPtr,
683 int typeInfoFlags,
status;
693 if( restartEntry == NULL && \
694 attributeCheckInfo->attributeListPtr != NULL && \
695 attributeCheckInfo->attributeListPtr->
next != NULL && \
696 ( attributeCheckInfo->attributeListPtr->fieldID == \
697 attributeCheckInfo->attributeListPtr->next->fieldID ) && \
698 ( attributeCheckInfo->attributeListPtr->subFieldID == \
699 attributeCheckInfo->attributeListPtr->next->subFieldID ) )
701 restartEntry = attributeCheckInfo->attributeListPtr;
702 restartPoint = attributeCheckInfo->attributeInfoPtr + 1;
703 restartStackPos = attributeCheckInfo->stackPos + 1;
707 status = checkAttributeEntry( attributeCheckInfo );
712 attributeCheckInfo->errorLocus = \
713 attributeCheckInfo->attributeInfoPtr->fieldID;
721 status = updateStackedInfo( attributeCheckInfo->stack,
722 attributeCheckInfo->stackPos,
723 &attributeCheckInfo->stackPos,
732 if( restartEntry != NULL && \
733 restartEntry != attributeCheckInfo->attributeListPtr )
737 attributeCheckInfo->attributeInfoPtr = restartPoint;
738 if( attributeCheckInfo->stackPos > restartStackPos )
740 status = updateStackedInfo( attributeCheckInfo->stack,
741 attributeCheckInfo->stackPos,
742 &attributeCheckInfo->stackPos,
743 attributeCheckInfo->stackPos - \
744 restartStackPos,
TRUE );
758 typeInfoFlags = attributeCheckInfo->attributeInfoPtr->
typeInfoFlags;
759 attributeCheckInfo->attributeInfoPtr++;
763 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
764 attributeCheckInfo->choiceState = CHOICE_NONE;
770 return( updateStackedInfo( attributeCheckInfo->stack,
771 attributeCheckInfo->stackPos,
772 &attributeCheckInfo->stackPos,
773 attributeCheckInfo->stackPos - \
774 attributeCheckInfo->stackTop,
FALSE ) );
787 ATTRIBUTE_CHECK_INFO attributeCheckInfo;
803 status = getAttributeInfo( attributeType, &attributeInfoStartPtr,
813 attributeListPtr != NULL && \
814 isValidAttributeField( attributeListPtr ) && \
816 attributeListPtr = attributeListPtr->
next, iterationCount++ )
818 if( attributeListPtr->
next != NULL && \
820 attributeListPtr->attributeID > \
821 attributeListPtr->next->attributeID )
828 attributeListPtr->fifoEnd = 0;
831 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
834 memset( &attributeCheckInfo, 0,
sizeof( ATTRIBUTE_CHECK_INFO ) );
835 attributeCheckInfo.attributeListPtr = (
ATTRIBUTE_LIST * ) listHeadPtr;
836 attributeCheckInfo.attributeInfoPtr = attributeInfoStartPtr;
840 for( iterationCount = 0;
841 attributeCheckInfo.attributeListPtr != NULL && \
846 int innerIterationCount;
857 for( innerIterationCount = 0;
858 attributeCheckInfo.attributeInfoPtr->fieldID !=
CRYPT_ERROR && \
860 attributeCheckInfo.attributeInfoPtr++, innerIterationCount++ )
864 if( attributeCheckInfo.attributeInfoPtr[ 1 ].fieldID == \
865 attributeCheckInfo.attributeListPtr->attributeID )
870 if( attributeCheckInfo.attributeInfoPtr->fieldID == \
871 attributeCheckInfo.attributeListPtr->attributeID )
875 ENSURES( innerIterationCount < FAILSAFE_ITERATIONS_LARGE );
879 status = checkAttribute( &attributeCheckInfo );
882 *errorLocus = attributeCheckInfo.errorLocus;
883 *errorType = attributeCheckInfo.errorType;
887 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );