static int readAVABitstring( INOUT STREAM *stream, OUT_LENGTH_SHORT_Z int *length, OUT_TAG_ENCODED_Z int *stringTag ) { long streamPos; int bitStringLength, innerTag, innerLength = DUMMY_INIT, status; assert( isWritePtr( stream, sizeof( STREAM ) ) ); assert( isWritePtr( length, sizeof( int ) ) ); assert( isWritePtr( stringTag, sizeof( int ) ) ); /* Bitstrings are used for uniqueIdentifiers, however these usually encapsulate something else: BIT STRING { IA5String 'xxxxx' } so we try and dig one level deeper to find the encapsulated string if there is one. This gets a bit complicated because we have to speculatively try and decode the inner content and if that fails assume that it's raw bitstring data. First we read the bitstring wrapper and remember where the bitstring data starts */ status = readBitStringHole( stream, &bitStringLength, 2, DEFAULT_TAG ); if( cryptStatusError( status ) ) return( status ); streamPos = stell( stream ); /* Then we try and read any inner content */ status = innerTag = peekTag( stream ); if( !cryptStatusError( status ) ) status = readGenericHole( stream, &innerLength, 1, innerTag ); if( !cryptStatusError( status ) && \ bitStringLength == sizeofObject( innerLength ) ) { /* There was inner content present, treat it as the actual type and value of the bitstring. This assumes that the inner content is a string data type, which always seems to be the case (in any event it's not certain what we should be returning to the user if we find, for example, a SEQUENCE with further encapsulated content at this point) */ *stringTag = innerTag; *length = innerLength; return( CRYPT_OK ); } /* We couldn't identify any (obvious) inner content, it must be raw bitstring data. Unfortunately we have no idea what format this is in, it could in fact really be raw binary data but never actually seems to be this, it's usually ASCII text so we mark it as such and let the string-read routines sort it out */ sClearError( stream ); sseek( stream, streamPos ); *stringTag = BER_STRING_IA5; *length = bitStringLength; return( CRYPT_OK ); }
static int readRawSignature( INOUT STREAM *stream, OUT QUERY_INFO *queryInfo ) { const int startPos = stell( stream ); int status; assert( isWritePtr( stream, sizeof( STREAM ) ) ); assert( isWritePtr( queryInfo, sizeof( QUERY_INFO ) ) ); REQUIRES( startPos >= 0 && startPos < MAX_BUFFER_SIZE ); /* Clear return value */ memset( queryInfo, 0, sizeof( QUERY_INFO ) ); /* Read the start of the signature */ status = readBitStringHole( stream, &queryInfo->dataLength, 18 + 18, DEFAULT_TAG ); if( cryptStatusError( status ) ) return( status ); queryInfo->dataStart = stell( stream ) - startPos; /* Make sure that the remaining signature data is present */ return( sSkip( stream, queryInfo->dataLength, MAX_INTLENGTH_SHORT ) ); }
void *dataPtr; int length, status; assert( isWritePtr( stream, sizeof( STREAM ) ) ); assert( isWritePtr( encDataPtrPtr, sizeof( void * ) ) ); assert( isWritePtr( encDataLength, sizeof( int ) ) ); REQUIRES( minLength >= 32 && minLength < maxLength && \ minLength < MAX_INTLENGTH_SHORT ); /* Clear return values */ *encDataPtrPtr = NULL; *encDataLength = 0; /* Read and remember the encrypted data */ status = readBitStringHole( stream, &length, minLength, CTAG_EV_ENCCEK ); if( cryptStatusError( status ) ) return( status ); if( length < MIN_PKCSIZE || length > CRYPT_MAX_PKCSIZE ) return( CRYPT_ERROR_BADDATA ); status = sMemGetDataBlock( stream, &dataPtr, length ); if( cryptStatusOK( status ) ) status = sSkip( stream, length ); if( cryptStatusError( status ) ) return( status ); *encDataPtrPtr = dataPtr; *encDataLength = length; return( CRYPT_OK ); }