mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-06 06:04:41 +02:00
Rework to remove early function returns
This commit is contained in:
@@ -2594,35 +2594,47 @@ int wc_IndexSequenceOf(const byte * seqOf, word32 seqOfSz, size_t seqIndex,
|
|||||||
byte tagFound;
|
byte tagFound;
|
||||||
size_t i;
|
size_t i;
|
||||||
word32 elementIdx = 0U;
|
word32 elementIdx = 0U;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
/* Validate the SEQUENCE OF header. */
|
/* Validate the SEQUENCE OF header. */
|
||||||
if (GetSequence(seqOf, &seqOfIdx, &length, seqOfSz) < 0)
|
if (GetSequence(seqOf, &seqOfIdx, &length, seqOfSz) < 0) {
|
||||||
return ASN_PARSE_E;
|
ret = ASN_PARSE_E;
|
||||||
|
}
|
||||||
|
else {
|
||||||
seqOfSz = seqOfIdx + (word32)length;
|
seqOfSz = seqOfIdx + (word32)length;
|
||||||
|
|
||||||
for (i = 0U; i <= seqIndex; i++) {
|
for (i = 0U; i <= seqIndex; i++) {
|
||||||
if (seqOfIdx >= seqOfSz)
|
if (seqOfIdx >= seqOfSz) {
|
||||||
return BAD_INDEX_E;
|
ret = BAD_INDEX_E;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
elementIdx = seqOfIdx;
|
elementIdx = seqOfIdx;
|
||||||
|
|
||||||
/* Validate the element tag. */
|
/* Validate the element tag. */
|
||||||
if (GetASNTag(seqOf, &seqOfIdx, &tagFound, seqOfSz) != 0)
|
if (GetASNTag(seqOf, &seqOfIdx, &tagFound, seqOfSz) != 0) {
|
||||||
return ASN_PARSE_E;
|
ret = ASN_PARSE_E;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Validate and get the element's encoded length. */
|
/* Validate and get the element's encoded length. */
|
||||||
if (GetLength(seqOf, &seqOfIdx, &length, seqOfSz) < 0)
|
if (GetLength(seqOf, &seqOfIdx, &length, seqOfSz) < 0) {
|
||||||
return ASN_PARSE_E;
|
ret = ASN_PARSE_E;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
seqOfIdx += (word32)length;
|
seqOfIdx += (word32)length;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* If the tag and length checks above passed then we've found the requested
|
/* If the tag and length checks above passed then we've found the requested
|
||||||
* element and validated it fits within seqOfSz. */
|
* element and validated it fits within seqOfSz. */
|
||||||
|
if (ret == 0) {
|
||||||
*out = &seqOf[elementIdx];
|
*out = &seqOf[elementIdx];
|
||||||
*outSz = (seqOfIdx - elementIdx);
|
*outSz = (seqOfIdx - elementIdx);
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decode the header of a BER/DER encoded SET.
|
/* Decode the header of a BER/DER encoded SET.
|
||||||
|
Reference in New Issue
Block a user