18 #ifdef USE_CERTIFICATES
39 assert(
isWritePtr( stringTag,
sizeof(
int ) ) );
53 status = readBitStringHole( stream, &bitStringLength, 2,
DEFAULT_TAG );
56 streamPos = stell( stream );
59 status = innerTag = peekTag( stream );
61 status = readGenericHole( stream, &innerLength, 1, innerTag );
63 bitStringLength == sizeofObject( innerLength ) )
71 *stringTag = innerTag;
72 *length = innerLength;
82 sClearError( stream );
83 sseek( stream, streamPos );
85 *length = bitStringLength;
102 assert(
isWritePtr( length,
sizeof(
int ) ) );
103 assert(
isWritePtr( stringTag,
sizeof(
int ) ) );
115 readSequence( stream, NULL );
116 status = readEncodedOID( stream, oid,
MAX_OID_SIZE, &oidLength,
120 dnComponentInfo = findDNInfoByOID( oid, oidLength );
121 if( dnComponentInfo == NULL )
124 status = readUniversal( stream );
127 *type = dnComponentInfo->
type;
133 tag = peekTag( stream );
137 return( readAVABitstring( stream, length, stringTag ) );
139 return( readGenericHole( stream, length, 0, tag ) );
152 const int rdnStart = stell( stream );
163 status = readAVA( stream, &type, &valueLength, &stringTag );
166 if( valueLength <= 0 )
171 status = sMemGetDataBlock( stream, &value, valueLength );
173 status = sSkip( stream, valueLength );
183 if( rdnDataLeft >= ( stell( stream ) - rdnStart ) + 10 )
188 &valueLength, &valueStringType, value,
189 valueLength, stringTag );
197 status = insertDNstring( dnComponentListPtrPtr, type, stringBuffer,
198 valueLength, valueStringType, flags, &dummy );
207 int rdnLength, iterationCount,
status;
210 status = readSet( stream, &rdnLength );
215 for( iterationCount = 0;
219 const int rdnStart = stell( stream );
223 status = readRDNcomponent( stream, dnComponentListPtrPtr,
228 rdnLength -= stell( stream ) - rdnStart;
230 if( rdnLength < 0 || iterationCount >= FAILSAFE_ITERATIONS_MED )
249 *dnComponentListPtrPtr = NULL;
254 status = readSequence( stream, &length );
257 for( iterationCount = 0;
261 const int startPos = stell( stream );
265 status = readDNComponent( stream, &dnComponentListPtr );
268 length -= stell( stream ) -
startPos;
271 length < 0 || iterationCount >= FAILSAFE_ITERATIONS_MED )
274 if( dnComponentListPtr != NULL )
275 deleteDN( (
DN_PTR ** ) &dnComponentListPtr );
280 *dnComponentListPtrPtr = dnComponentListPtr;
299 int size = 0, iterationCount;
302 assert(
isWritePtr( length,
sizeof(
int ) ) );
312 for( iterationCount = 0;
313 dnComponentPtr->prev != NULL && \
315 dnComponentPtr = dnComponentPtr->prev, iterationCount++ );
316 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
318 ENSURES( dnComponentPtr->prev == NULL );
321 for( iterationCount = 0;
323 dnComponentPtr = dnComponentPtr->next, iterationCount++ )
326 int innerIterationCount;
329 for( innerIterationCount = 0;
330 dnComponentPtr != NULL && \
332 dnComponentPtr = dnComponentPtr->next, innerIterationCount++ )
335 int dnStringLength,
status;
337 status = getAsn1StringInfo( dnComponentPtr->value,
338 dnComponentPtr->valueLength,
339 &dnComponentPtr->valueStringType,
340 &dnComponentPtr->asn1EncodedStringType,
344 dnComponentPtr->encodedAVAdataSize = ( int ) \
346 sizeofObject( dnStringLength );
347 dnComponentPtr->encodedRDNdataSize = 0;
349 sizeofObject( dnComponentPtr->encodedAVAdataSize );
353 ENSURES( innerIterationCount < FAILSAFE_ITERATIONS_MED );
361 if( dnComponentPtr == NULL )
364 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
375 assert( dnComponentList == NULL || \
379 if( dnComponentList == NULL )
380 return( sizeofObject( 0 ) );
382 status = preEncodeDN( dnComponentList, &length );
385 return( sizeofObject( length ) );
399 assert( dnComponentList == NULL || \
405 if( dnComponentList == NULL )
406 return( writeConstructed( stream, 0, tag ) );
408 status = preEncodeDN( (
DN_COMPONENT * ) dnComponentList, &size );
413 writeConstructed( stream, size, tag );
414 for( dnComponentPtr = (
DN_COMPONENT * ) dnComponentList, \
416 dnComponentPtr != NULL && \
418 dnComponentPtr = dnComponentPtr->
next, iterationCount++ )
431 status = swrite( stream, dnComponentInfo->
oid,
439 &dnStringLength, dnComponentPtr->value,
445 !dnComponentInfo->
ia5OK )
451 status = writeCharacterString( stream, dnString, dnStringLength,
456 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
478 #ifdef USE_CERT_DNSTRING
480 #if defined( _MSC_VER )
481 #pragma message( " Building with string-form DNs enabled." )
491 assert(
isReadPtr(
string, stringLength ) );
501 if( (
string[ i ] & 0x7F ) <
' ' )
515 int labelLen, textLen;
519 #define MAX_DNSTRING_COMPONENTS 32
523 DN_STRING_INFO *dnStringInfo,
524 OUT_RANGE( 0, MAX_DNSTRING_COMPONENTS ) \
525 int *dnStringInfoIndex,
529 int stringPos, stringInfoIndex;
531 assert(
isWritePtr( dnStringInfo,
sizeof( DN_STRING_INFO ) * \
532 MAX_DNSTRING_COMPONENTS ) );
533 assert(
isReadPtr(
string, stringLength ) );
538 memset( dnStringInfo, 0,
539 sizeof( DN_STRING_INFO ) * MAX_DNSTRING_COMPONENTS );
540 *dnStringInfoIndex = 0;
543 if( !isTextString(
string, stringLength ) )
550 for( stringPos = 0, stringInfoIndex = 0;
551 stringPos < stringLength && \
552 stringInfoIndex < MAX_DNSTRING_COMPONENTS;
555 DN_STRING_INFO *dnStringInfoPtr = &dnStringInfo[ stringInfoIndex ];
563 if( ch ==
'\\' || ch ==
'+' || ch ==
',' )
571 if( i <= stringPos || i >= stringLength - 1 )
577 dnStringInfoPtr->label =
string + stringPos;
578 dnStringInfoPtr->labelLen = i - stringPos;
585 for( i = stringPos; i < stringLength && \
598 if( i >= stringLength - 1 )
611 if( ch !=
',' && ch !=
'+' )
616 if( i >= stringLength - 3 )
621 ENSURES( i < MAX_ATTRIBUTE_SIZE );
623 dnStringInfoPtr->text =
string + stringPos;
624 dnStringInfoPtr->textLen = i - stringPos;
625 if(
string[ i ] ==
',' ||
string[ i ] ==
'+' )
629 if(
string[ i ] ==
'+' )
630 dnStringInfoPtr->isContinued =
TRUE;
636 dnStringInfoPtr->labelLen = \
637 strStripWhitespace( (
const char ** ) &dnStringInfoPtr->label,
638 dnStringInfoPtr->label,
639 dnStringInfoPtr->labelLen );
640 dnStringInfoPtr->textLen = \
641 strStripWhitespace( (
const char ** ) &dnStringInfoPtr->text,
642 dnStringInfoPtr->text,
643 dnStringInfoPtr->textLen );
644 if( dnStringInfoPtr->labelLen < 1 || \
645 dnStringInfoPtr->labelLen > MAX_ATTRIBUTE_SIZE || \
646 dnStringInfoPtr->textLen < 1 || \
647 dnStringInfoPtr->textLen > MAX_ATTRIBUTE_SIZE )
650 if( stringInfoIndex <= 0 || stringInfoIndex >= MAX_DNSTRING_COMPONENTS )
652 *dnStringInfoIndex = stringInfoIndex;
662 DN_STRING_INFO dnStringInfo[ MAX_DNSTRING_COMPONENTS + 8 ];
664 int stringInfoIndex, iterationCount;
667 assert(
isReadPtr(
string, stringLength ) );
669 REQUIRES( stringLength > 0 && stringLength <= MAX_ATTRIBUTE_SIZE );
672 *dnComponentListPtrPtr = NULL;
682 if( !parseDNString( dnStringInfo, &stringInfoIndex,
string,
691 for( iterationCount = 0;
693 stringInfoIndex--, iterationCount++ )
695 const DN_STRING_INFO *dnStringInfoPtr;
697 int innerIterationCount;
700 while( stringInfoIndex > 0 && \
701 dnStringInfo[ stringInfoIndex - 1 ].isContinued )
703 dnStringInfoPtr = &dnStringInfo[ stringInfoIndex ];
705 for( isContinued =
TRUE, innerIterationCount = 0;
707 innerIterationCount++ )
711 BYTE textBuffer[ MAX_ATTRIBUTE_SIZE + 8 ];
716 dnComponentInfo = findDNInfoByLabel( dnStringInfoPtr->label,
717 dnStringInfoPtr->labelLen );
718 if( dnComponentInfo == NULL )
720 if( dnComponentPtr != NULL )
721 deleteDN( (
DN_PTR ** ) &dnComponentPtr );
724 type = dnComponentInfo->
type;
728 for( i = 0; i < dnStringInfoPtr->textLen && \
731 int ch =
byteToInt( dnStringInfoPtr->text[ i ] );
737 if( i >= dnStringInfoPtr->textLen )
739 if( dnComponentPtr != NULL )
740 deleteDN( (
DN_PTR ** ) &dnComponentPtr );
743 ch =
byteToInt( dnStringInfoPtr->text[ i ] );
745 textBuffer[ textIndex++ ] =
intToByte( ch );
747 ENSURES( i < MAX_ATTRIBUTE_SIZE );
753 status = getAsn1StringInfo( textBuffer, textIndex,
754 &valueStringType, &dummy1, &dummy2 );
757 if( dnComponentPtr != NULL )
758 deleteDN( (
DN_PTR ** ) &dnComponentPtr );
768 if( dnComponentPtr != NULL )
769 deleteDN( (
DN_PTR ** ) &dnComponentPtr );
775 status = insertDNstring( &dnComponentPtr, type,
776 textBuffer, textIndex, valueStringType,
777 ( dnStringInfoPtr->isContinued ) ? \
782 if( dnComponentPtr != NULL )
783 deleteDN( (
DN_PTR ** ) &dnComponentPtr );
788 isContinued = dnStringInfoPtr->isContinued;
791 ENSURES( innerIterationCount < FAILSAFE_ITERATIONS_MED );
793 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
796 *dnComponentListPtrPtr = dnComponentPtr;
797 for( iterationCount = 0;
799 dnComponentPtr = dnComponentPtr->
next, iterationCount++ )
801 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
819 swrite( stream, componentInfoPtr->name, componentInfoPtr->
nameLen );
820 status = sputc( stream,
'=' );
825 const int ch =
byteToInt( ( (
BYTE * ) dnComponentPtr->value )[ i ] );
827 if( ch ==
',' || ch ==
'=' || ch ==
'+' || ch ==
';' || \
828 ch ==
'\\' || ch ==
'"' )
829 sputc( stream,
'\\' );
830 status = sputc( stream, ch );
843 int iterationCount,
status;
846 assert( dnComponentList == NULL || \
850 if( dnComponentPtr == NULL )
866 for( iterationCount = 0;
867 dnComponentPtr->
next != NULL && \
869 dnComponentPtr = dnComponentPtr->
next, iterationCount++ )
881 if( !isTextString( dnComponentPtr->value,
885 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
887 for( iterationCount = 0;
892 int innerIterationCount;
895 for( innerIterationCount = 0;
896 dnComponentPtr->
prev != NULL && \
898 innerIterationCount < FAILSAFE_ITERATIONS_MED;
899 dnComponentPtr = dnComponentPtr->
prev, innerIterationCount++ );
900 ENSURES( innerIterationCount < FAILSAFE_ITERATIONS_MED );
901 dnComponentCursor = dnComponentPtr;
902 dnComponentPtr = dnComponentPtr->
prev;
905 for( status =
CRYPT_OK, innerIterationCount = 0;
908 innerIterationCount++ )
910 status = writeAVAString( stream, dnComponentCursor );
920 status = swrite( stream,
" + ", 3 );
923 dnComponentCursor = dnComponentCursor->
next;
925 ENSURES( innerIterationCount < FAILSAFE_ITERATIONS_MED );
928 if( dnComponentPtr != NULL )
930 status = swrite( stream,
", ", 2 );
935 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );