20 #ifdef USE_CERTIFICATES
41 assert(
isWritePtr( attributeDataSize,
sizeof(
int ) ) );
44 *attributeInfoPtrPtr = NULL;
49 if( attributeListPtr->
fifoEnd > 0 )
52 attributeListPtr->encodingFifo[ attributeListPtr->
fifoEnd - 1 ];
57 ENSURES( attributeInfoPtr != NULL );
62 *attributeDataSize = ( int ) sizeofObject( \
63 attributeListPtr->sizeFifo[ attributeListPtr->
fifoEnd - 1 ] );
86 #define ATTR_ENCODED_SIZE ( 16 + MAX_OID_SIZE )
91 BYTE *prevEncodedForm,
93 const int prevEncodedFormLength )
97 BYTE currentEncodedForm[ ATTR_ENCODED_SIZE + 8 ];
99 int iterationCount,
status;
102 assert(
isWritePtr( prevEncodedForm, prevEncodedFormLength ) );
104 REQUIRES_N( prevEncodedFormLength == ATTR_ENCODED_SIZE );
107 memset( buffer, 0, ATTR_ENCODED_SIZE );
108 memset( currentEncodedForm, 0xFF, ATTR_ENCODED_SIZE );
110 sMemOpen( &stream, buffer, ATTR_ENCODED_SIZE );
114 for( iterationCount = 0;
115 attributeListPtr != NULL && \
116 !checkAttributeProperty( attributeListPtr,
123 int attributeDataSize;
126 status = getAttributeEncodingInfo( attributeListPtr,
128 &attributeDataSize );
134 writeSequence( &stream,
sizeofOID( attributeInfoPtr->
oid ) + \
135 (
int ) sizeofObject( attributeDataSize ) );
136 status = swrite( &stream, attributeInfoPtr->
oid,
145 if( memcmp( prevEncodedForm, buffer, ATTR_ENCODED_SIZE ) < 0 && \
146 memcmp( buffer, currentEncodedForm, ATTR_ENCODED_SIZE ) < 0 )
148 memcpy( currentEncodedForm, buffer, ATTR_ENCODED_SIZE );
154 attributeListPtr != NULL && \
157 attributeListPtr = attributeListPtr->
next, iterationCount++ );
159 ENSURES_N( iterationCount < FAILSAFE_ITERATIONS_LARGE );
163 attributeListPtr != NULL && \
165 attributeListPtr = attributeListPtr->
next, iterationCount++ )
167 ENSURES_N( checkAttributeProperty( attributeListPtr,
172 writeSequence( &stream,
sizeofOID( attributeListPtr->
oid ) + \
173 (
int ) sizeofObject( attributeListPtr->
valueLength ) );
174 status = swrite( &stream, attributeListPtr->
oid,
181 if( memcmp( prevEncodedForm, buffer, ATTR_ENCODED_SIZE ) < 0 && \
182 memcmp( buffer, currentEncodedForm, ATTR_ENCODED_SIZE ) < 0 )
184 memcpy( currentEncodedForm, buffer, ATTR_ENCODED_SIZE );
188 ENSURES_N( iterationCount < FAILSAFE_ITERATIONS_LARGE );
190 sMemDisconnect( &stream );
194 memcpy( prevEncodedForm, currentEncodedForm, ATTR_ENCODED_SIZE );
208 assert( attributePtr == NULL || \
212 if( attributeListPtr == NULL )
216 for( iterationCount = 0;
217 attributeListPtr != NULL && \
218 !checkAttributeProperty( attributeListPtr,
225 int attributeDataSize;
228 status = getAttributeEncodingInfo( attributeListPtr,
230 &attributeDataSize );
233 attributeDataSize = ( int ) sizeofObject( attributeDataSize );
236 attributeDataSize +=
sizeofOID( attributeInfoPtr->
oid );
240 attributeSize += ( int ) sizeofObject( attributeDataSize );
244 attributeListPtr != NULL && \
247 attributeListPtr = attributeListPtr->
next, iterationCount++ );
249 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
255 if( !signUnrecognised )
256 return( attributeSize );
259 for( ; attributeListPtr != NULL && \
261 attributeListPtr = attributeListPtr->
next, iterationCount++ )
263 ENSURES( checkAttributeProperty( attributeListPtr,
266 attributeSize += ( int ) \
272 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
274 return( attributeSize );
286 static
int calculateSpecialFieldSize(
const ATTRIBUTE_LIST *attributeListPtr,
289 const int fieldType )
293 assert(
isWritePtr( payloadSize,
sizeof(
int ) ) );
297 ( fieldType > 0 && fieldType <
MAX_TAG ) );
300 *payloadSize = attributeListPtr->sizeFifo[ attributeListPtr->
fifoPos ];
323 return( (
int ) sizeofObject( *payloadSize ) );
330 static
int calculateFieldSize(
const ATTRIBUTE_LIST *attributeListPtr,
332 const int fieldType )
350 return(
sizeofDN( attributeListPtr->value ) );
373 return( (
int ) sizeofObject( attributeListPtr->
valueLength ) );
382 return( (
int ) sizeofObject( attributeListPtr->
valueLength ) );
390 IN_RANGE( 0, 4 )
const int complianceLevel )
394 attributeListPtr->encodingFifo[ --attributeListPtr->fifoPos ] : \
395 attributeListPtr->attributeInfoPtr;
396 const void *dataPtr = attributeListPtr->value;
397 const int fieldType = attributeInfoPtr->
fieldType;
414 size = calculateSpecialFieldSize( attributeListPtr, attributeInfoPtr,
415 &payloadSize, fieldType );
419 size = calculateFieldSize( attributeListPtr, attributeInfoPtr,
429 (
int ) sizeofObject(
size ) :
size );
460 return( swrite( stream, attributeInfoPtr->
extraData,
size ) );
463 return( swrite( stream, attributeInfoPtr->
oid,
size ) );
467 return( writeShortInteger( stream, attributeInfoPtr->
defaultValue,
474 return( writeConstructed( stream, payloadSize, tag ) );
475 return( ( fieldType ==
BER_SET ) ? \
476 writeSet( stream, payloadSize ) : \
477 writeSequence( stream, payloadSize ) );
494 sputc( stream, getFieldEncodedTag( attributeInfoPtr ) );
495 return( swrite( stream, ( (
BYTE * ) dataPtr ) + 1,
496 attributeListPtr->valueLength - 1 ) );
498 return( swrite( stream, dataPtr, attributeListPtr->valueLength ) );
501 return( writeDN( stream, attributeListPtr->value, tag ) );
505 return( swrite( stream, attributeInfoPtr->
oid,
size ) );
513 return( writeCharacterString( stream, dataPtr,
514 attributeListPtr->valueLength,
518 return( writeBitString( stream, (
int ) \
519 attributeListPtr->intValue, tag ) );
522 return( writeBoolean( stream, (
BOOLEAN ) \
523 attributeListPtr->intValue, tag ) );
526 return( writeEnumerated( stream, (
int ) \
527 attributeListPtr->intValue, tag ) );
530 return( writeShortInteger( stream, attributeListPtr->intValue,
534 return( writeNull( stream, tag ) );
542 sputc( stream, getFieldEncodedTag( attributeInfoPtr ) );
543 return( swrite( stream, ( (
BYTE * ) dataPtr ) + 1,
544 attributeListPtr->valueLength - 1 ) );
546 return( swrite( stream, dataPtr,
547 attributeListPtr->valueLength ) );
550 return( writeOctetString( stream, dataPtr,
551 attributeListPtr->valueLength,
560 return( writeCharacterString( stream, dataPtr,
561 attributeListPtr->valueLength,
567 return( writeGeneralizedTime( stream, *( time_t * ) dataPtr,
571 return( writeUTCTime( stream, *( time_t * ) dataPtr, tag ) );
583 IN_RANGE( 0, 4 )
const int complianceLevel )
589 int attributeDataSize, iterationCount,
status;
599 status = getAttributeEncodingInfo( attributeListPtr,
601 &attributeDataSize );
610 writeSequence( stream,
613 (
int ) sizeofObject( attributeDataSize ) );
614 swrite( stream, attributeInfoPtr->
oid,
619 status = writeSet( stream, attributeDataSize );
621 status = writeOctetStringHole( stream, attributeDataSize,
627 for( iterationCount = 0;
628 attributeListPtr != NULL && \
631 attributeListPtr = attributeListPtr->
next, iterationCount++ )
633 int innerIterationCount;
641 innerIterationCount = 0;
643 attributeListPtr->
fifoPos > 0 && \
645 innerIterationCount++ )
647 status = writeAttributeField( stream,
655 status = writeAttributeField( stream,
662 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
669 static
int writeBlobAttribute(
INOUT STREAM *stream,
672 IN_RANGE( 0, 4 )
const int complianceLevel )
681 writeSequence( stream,
684 (
int ) sizeofObject( attributeListPtr->
valueLength ) );
685 swrite( stream, attributeListPtr->
oid,
693 writeOctetStringHole( stream, attributeListPtr->
valueLength,
696 status = swrite( stream, attributeListPtr->value,
699 *attributeListPtrPtr = attributeListPtr->
next;
710 IN_RANGE( 0, 4 )
const int complianceLevel )
713 BYTE currentEncodedForm[ ATTR_ENCODED_SIZE + 8 ];
714 int iterationCount,
status;
728 status = writeSet( stream, attributeSize );
731 status = writeConstructed( stream, attributeSize,
740 memset( currentEncodedForm, 0, ATTR_ENCODED_SIZE );
741 for( currentAttributePtr = getNextEncodedAttribute( attributeListPtr, \
747 currentAttributePtr = getNextEncodedAttribute( attributeListPtr,
752 if( checkAttributeProperty( currentAttributePtr,
755 status = writeBlobAttribute( stream, ¤tAttributePtr,
TRUE,
760 status = writeAttribute( stream, ¤tAttributePtr,
TRUE,
766 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
787 int signUnrecognised =
DUMMY_INIT, complianceLevel, iterationCount;
826 return( writeCmsAttributes( stream, attributeListPtr, type,
827 attributeSize, complianceLevel ) );
840 writeConstructed( stream, (
int ) sizeofObject( attributeSize ),
843 status = writeSequence( stream, attributeSize );
848 (
int ) sizeofObject( sizeofObject( attributeSize ) ) );
850 writeSet( stream, (
int ) sizeofObject( attributeSize ) );
851 status = writeSequence( stream, attributeSize );
862 status = writeSequence( stream, attributeSize );
866 writeConstructed( stream, (
int ) sizeofObject( attributeSize ),
868 status = writeSequence( stream, attributeSize );
872 writeConstructed( stream, (
int ) sizeofObject( attributeSize ),
874 status = writeSequence( stream, attributeSize );
885 for( iterationCount = 0;
887 !checkAttributeProperty( attributeListPtr,
892 status = writeAttribute( stream, &attributeListPtr,
FALSE,
895 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
900 for( iterationCount = 0;
905 status = writeBlobAttribute( stream, &attributeListPtr,
FALSE,
908 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );