22 #define MAX_NESTING_LEVEL 50
29 #define LENGTH_MAGIC 500000000L
125 const long offset = stell( stream );
139 status = item->tag = sPeek( stream );
145 status = checkEOC( stream );
150 item->headerSize = 2;
157 if( item->tag <= 0 || item->tag >=
MAX_TAG )
161 status = readLongGenericHole( stream, &length, item->tag );
164 item->headerSize = stell( stream ) -
offset;
166 item->indefinite =
TRUE;
197 const long streamPos = stell( stream );
198 const int tag = peekTag( stream );
210 sClearError( stream );
211 sseek( stream, streamPos );
223 status = readGenericHole( stream, &innerLength, 1,
DEFAULT_TAG );
225 ( stell( stream ) - streamPos ) + innerLength != length )
227 sClearError( stream );
228 sseek( stream, streamPos );
240 innerLength > length - 4 )
241 isEncapsulated =
FALSE;
243 sClearError( stream );
244 sseek( stream, streamPos );
245 return( isEncapsulated );
276 if( innerLength < 0 || innerLength > 2 )
277 isEncapsulated =
FALSE;
280 int ch = sgetc( stream );
282 if( ch < 0 || ch > 7 )
283 isEncapsulated =
FALSE;
288 if( innerLength < 10 || innerLength > 20 )
289 isEncapsulated =
FALSE;
293 if( innerLength < 0 || innerLength > 2 )
294 isEncapsulated =
FALSE;
299 if( innerLength < 2 || innerLength > 256 )
300 isEncapsulated =
FALSE;
306 isEncapsulated =
FALSE;
313 isEncapsulated =
FALSE;
315 sClearError( stream );
316 sseek( stream, streamPos );
317 return( isEncapsulated );
335 int length = ( int ) item->length,
ch, i;
375 ch = sgetc( stream );
406 if( ( ( isBitstring && state == STATE_CHECK_HOLE_BITSTRING ) || \
409 checkEncapsulation( stream, length, isBitstring, state ) )
413 checkEncapsulation( stream, length, isBitstring, state ) )
418 encapsState = checkASN1( stream, length, item->indefinite,
469 for( i = 0; i < length - 1; i++ )
471 ch = sgetc( stream );
475 if( sgetc( stream ) !=
'Z' )
477 return( STATE_NONE );
533 if( !checkDataElements && item->length > 0 )
543 if( item->length <= 0 && !item->indefinite )
546 return( checkASN1( stream, item->length, item->indefinite,
549 checkDataElements ) );
555 newState = checkPrimitive( stream, item, level + 1, state );
556 if( newState < STATE_NONE || newState >=
STATE_ERROR )
564 return( STATE_CHECK_HOLE_BITSTRING );
577 if( item->length <= 0 && !item->indefinite )
584 ENSURES( item->length > 0 || item->indefinite );
589 newState = checkASN1( stream, item->length, item->indefinite,
591 return( ( newState < STATE_NONE || newState >=
STATE_ERROR ) ? \
622 const long maxIterationCount = ( level == 6 && length > 30000 ) ? \
624 long localLength =
length, lastPos = stell( stream );
632 REQUIRES( ( isIndefinite && length == 0 ) || \
633 ( !isIndefinite && length >= 0 && length <
MAX_INTLENGTH ) );
640 for( iterationCount = 0;
641 ( newState = getItem( stream, &item ) ) ==
STATE_NONE && \
642 iterationCount < maxIterationCount;
657 if( !checkDataElements && item.
length > 0 )
668 newState = checkASN1Object( stream, &item, level + 1, state,
670 if( newState < STATE_NONE || newState >=
STATE_ERROR )
689 localLength -= stell( stream ) - lastPos;
690 lastPos = stell( stream );
693 if( localLength == 0 )
703 ENSURES_S( iterationCount < maxIterationCount );
719 assert(
isReadPtr( objectPtr, objectLength ) );
723 sMemConnect( &stream, objectPtr, objectLength );
726 length = stell( &stream );
727 sMemDisconnect( &stream );
740 const long startPos = stell( stream );
745 assert(
isWritePtr( length,
sizeof(
long ) ) );
753 status = readGenericObjectHeader( stream, &localLength, isLongObject );
771 sseek( stream, startPos );
782 localLength = stell( stream ) -
startPos;
787 localLength += stell( stream ) -
startPos;
794 if( !isLongObject && localLength > 32767L )
796 *length = localLength;
797 return( sseek( stream, startPos ) );
807 assert(
isWritePtr( length,
sizeof(
int ) ) );
812 status = findObjectLength( stream, &localLength,
FALSE );
814 *length = localLength;
819 int getLongStreamObjectLength(
INOUT STREAM *stream,
826 assert(
isWritePtr( length,
sizeof(
long ) ) );
831 status = findObjectLength( stream, &localLength,
TRUE );
833 *length = localLength;
838 int getObjectLength(
IN_BUFFER( objectLength )
const void *objectPtr,
846 assert(
isReadPtr( objectPtr, objectLength ) );
847 assert(
isWritePtr( length,
sizeof(
int ) ) );
854 sMemConnect( &stream, objectPtr, objectLength );
855 status = findObjectLength( &stream, &localLength,
FALSE );
856 sMemDisconnect( &stream );
860 *length = localLength;
865 int getLongObjectLength(
IN_BUFFER( objectLength )
const void *objectPtr,
873 assert(
isReadPtr( objectPtr, objectLength ) );
874 assert(
isWritePtr( length,
sizeof(
long ) ) );
881 sMemConnect( &stream, objectPtr, objectLength );
882 status = findObjectLength( &stream, &localLength,
TRUE );
883 sMemDisconnect( &stream );
885 *length = localLength;