in source/sigv4.c [2077:2123]
static SigV4Status_t generateCanonicalQuery( const char * pQuery,
size_t queryLen,
const bool doubleEncodeEqualsInParmsValues,
CanonicalContext_t * pCanonicalContext )
{
SigV4Status_t returnStatus = SigV4Success;
size_t numberOfParameters = 0U;
assert( pCanonicalContext != NULL );
if( pQuery != NULL )
{
returnStatus = parseQueryString( pQuery, queryLen, &numberOfParameters, pCanonicalContext );
}
if( ( returnStatus == SigV4Success ) && ( numberOfParameters > 0U ) )
{
/* Sort the parameter names by character code point in ascending order.
* Parameters with duplicate names should be sorted by value. */
quickSort( pCanonicalContext->pQueryLoc, numberOfParameters, sizeof( SigV4KeyValuePair_t ), cmpQueryFieldValue );
/* URI-encode each parameter name and value according to the following rules specified for SigV4:
* - Do not URI-encode any of the unreserved characters that RFC 3986 defines:
* A-Z, a-z, 0-9, hyphen ( - ), underscore ( _ ), period ( . ), and tilde ( ~ ).
* - Percent-encode all other characters with %XY, where X and Y are hexadecimal characters (0-9 and uppercase A-F).
*/
returnStatus = writeCanonicalQueryParameters( pCanonicalContext, numberOfParameters, doubleEncodeEqualsInParmsValues );
}
if( returnStatus == SigV4Success )
{
if( pCanonicalContext->bufRemaining > 0U )
{
/* Append a linefeed at the end. */
( ( char * ) ( pCanonicalContext->pBufProcessing ) )[ pCanonicalContext->uxCursorIndex ] = LINEFEED_CHAR;
pCanonicalContext->uxCursorIndex++;
pCanonicalContext->bufRemaining -= 1U;
}
else
{
returnStatus = SigV4InsufficientMemory;
LOG_INSUFFICIENT_MEMORY_ERROR( "write newline character after canonical query", 1U );
}
}
return returnStatus;
}